Repository navigation
binfmt: Check the execute permission in every binary format. - #20764
Merged
Merged
Conversation
casaroli
requested review from
Donny9,
jerpelea,
pussuw and
xiaoxiang781216
as code owners
October 17, 2026 22:35
|
casaroli
force-pushed
the
binfmt-checkexec
branch
from
October 18, 2026 17:05
15fbdf2 to
af9dc05
Compare
The ELF, NXFLAT and builtin loaders checked the execute permission only with CONFIG_SCHED_USER_IDENTITY, and the script loader did not check it at all. Without user identities, NuttX started any file that a loader recognized, whatever its mode. Add CONFIG_BINFMT_CHECKEXEC, which is the default with CONFIG_SCHED_USER_IDENTITY. Each loader then checks the mode of the file that it already opened, so no extra lookup is needed: the ELF and NXFLAT loaders, the builtin loader with the mode of the builtin table, and the script loader, which now checks the script too; its interpreter is checked by its own loader. A file without execute permission gives EACCES. Without user identities, any execute bit is enough, as for root. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
The file permission page did not say when NuttX checks the execute permission of a program. Describe CONFIG_BINFMT_CHECKEXEC, its rule, and where the mode comes from. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
casaroli
force-pushed
the
binfmt-checkexec
branch
from
October 18, 2026 19:41
af9dc05 to
60faf9e
Compare
xiaoxiang781216
approved these changes
Oct 18, 2026
acassis
approved these changes
Oct 19, 2026
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
The ELF, NXFLAT and builtin loaders checked the execute permission only with
CONFIG_SCHED_USER_IDENTITY, and the script loader did not check it at all. Without user identities, NuttX started any file that a loader recognized, whatever its mode.This PR adds
CONFIG_BINFMT_CHECKEXEC, which is the default withCONFIG_SCHED_USER_IDENTITY. Each loader then checks the mode of the file that it already opened, so no extra lookup is needed:EACCES. WithCONFIG_SCHED_USER_IDENTITY, the owner, group or other bit is checked for the effective IDs, and root needs any execute bit. Without it, any execute bit is enough.The second commit adds an "Execute permission" section to
Documentation/os/filesystem/file_permission.rst.Impact
Without
CONFIG_BINFMT_CHECKEXEC(the default withoutCONFIG_SCHED_USER_IDENTITY), nothing changes. WithCONFIG_SCHED_USER_IDENTITY, scripts are now checked too. File systems without a stored mode report execute permission for all files (#20754, #20755, #20756), so their programs still run.Testing
A test program on
qemu-armv8a:knsh(QEMU 11 with HVF on an Apple M4) starts files withposix_spawn(). The files are on v9fs, with the host mode, and on tmpfs mounts with and withoutMS_NOEXEC(#20762):BINFMT_CHECKEXECSCHED_USER_IDENTITY+FS_PERMISSIONEACCESEACCESEACCESEACCESnoexecmountEACCESEACCESIn the last configuration, a program copied to tmpfs with a mode without execute bits fails with "Permission denied" and runs after
chmod 755.binfmt/nxflat.cbuilds forlm3s6965-ek:qemu-nxflatwithCONFIG_BINFMT_CHECKEXEC(no user identities).ostestonqemu-armv8a:knshandqemu-armv8a:nshends withostest_main: Exiting with status 0.tools/checkpatch.sh -c -u -m -gpasses.