Repository navigation
sched, binfmt: Fail with E2BIG for arguments that are too large. - #20957
Merged
Merged
Conversation
nxtask_setup_scheduler() gives the TCB a PID and puts it on the inactive task list. When a later step of nxtask_init() failed (tls_init_info() or nxtask_setup_stackargs()), the error path left both in place, and the caller then freed the TCB with kmm_free(). The PID hash table and the inactive task list kept a pointer to freed memory, and the next task creation could crash the kernel. The kernel stack of the new task also leaked. On failure, take the TCB off the inactive task list, release its PID and free its kernel stack before the group is released. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
nxtask_setup_stackargs() copies the arguments to the stack of the new task. When they did not fit, a DEBUGASSERT stopped the system, which a program can cause with a long argument. Without assertions the loop set -ENAMETOOLONG but did not advance, so it never ended. The check of CONFIG_TASK_MAX_ARGS did not end the loop either. Strings that fit but leave no room for the argv[] array made up_stack_frame() fail, and a DEBUGASSERT stopped the system there too. Now both checks end the loop with E2BIG, the error that POSIX gives exec for an argument list that is too large, and a failed up_stack_frame() gives E2BIG too. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
CONFIG_TASK_ARG_MAX sets ARG_MAX, but nothing checked it. POSIX: exec fails with E2BIG when the arguments and the environment of the new image are larger than ARG_MAX bytes. exec_internal() now counts the bytes of the argument and environment strings, with their terminators and the pointers to them, before it loads the program, and fails with E2BIG above ARG_MAX. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
posix_spawn() and exec() fail with E2BIG for arguments and environment larger than ARG_MAX, and for arguments that do not fit the stack of the new task. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
casaroli
requested review from
Donny9,
GUIDINGLI,
anchao,
masayuki2009,
pussuw and
xiaoxiang781216
as code owners
October 24, 2026 09:39
xiaoxiang781216
approved these changes
Oct 24, 2026
|
acassis
approved these changes
Oct 25, 2026
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
POSIX:
execandposix_spawn()fail withE2BIGwhen the arguments and the environment of the new image are larger thanARG_MAXbytes.CONFIG_TASK_ARG_MAXsetsARG_MAXandsysconf(_SC_ARG_MAX), but nothing checked it. An argument list that did not fit the stack of the new task reached aDEBUGASSERTinnxtask_setup_stackargs(), so a program could stop the system with one long argument. Without assertions the loop set-ENAMETOOLONGbut did not advance, so it never ended.nxtask_init()undoes the scheduler setup when a later step fails.nxtask_setup_scheduler()gives the TCB a PID and puts it on the inactive task list; whentls_init_info()ornxtask_setup_stackargs()then failed, both stayed in place and the caller freed the TCB withkmm_free(). The next task creation could then crash the kernel. The kernel stack of the new task also leaked. This path was reachable without assertions before; theE2BIGbelow makes it reachable with them, so it comes first.nxtask_setup_stackargs()ends withE2BIGwhen the arguments do not fit the stack, when theargv[]array does not fit with them (up_stack_frame()fails), or when there are more thanCONFIG_TASK_MAX_ARGS.exec_internal()counts the bytes of the argument and environment strings, with their terminators and pointers, before it loads the program, and fails withE2BIGaboveARG_MAX.posix_spawn()and theTASK_ARG_MAXhelp.Impact
exec()andposix_spawn()of a program with more thanARG_MAXbytes of arguments and environment fail withE2BIG(the defaultARG_MAXis 4096). A configuration that passes more must raiseCONFIG_TASK_ARG_MAX. All build modes and architectures.Testing
Test program
e2big.conqemu-armv8a:knsh(QEMU with HVF,CONFIG_TASK_ARG_MAX=65536): a small argument, an argument and an environment larger thanARG_MAX,execv()with a too large argument, an argument withinARG_MAXthat does not fit an 8 KiB stack (twice), then 8 small spawns. ostest runs after it in the same boot.e2bigARG_MAXstops the system with an assertion in the kernel (task/task_setup.c:557)e2bigarm64_fatal.c:696, fault address0x74736574736fin one run,0x10in another): a freed TCB in the task listsostest also exits with status 0 on
qemu-armv8a:nshwith this PR, and on master withCONFIG_TASK_ARG_MAX=65536(knsh and nsh), so the option alone changes nothing.The
stackcase depends on the configuration: with a larger stack the argument fits, and the case gives 0, notE2BIG.Build, each OK:
qemu-armv8a:nsh(flat, arm64),qemu-armv8a:knsh(kernel, arm64),lm3s6965-ek:qemu-protected(protected, armv7-m),qemu-armv7a:knsh(kernel, armv7-a),rv-virt:nsh64(flat, rv64),rv-virt:knsh64(kernel, rv64). No new warnings.tools/checkpatch.sh -c -u -m -gpasses.