Skip to content

binfmt: Check the execute permission in every binary format. - #20764

Merged
acassis merged 2 commits into
apache:masterfrom
casaroli:binfmt-checkexec
Oct 19, 2026
Merged

acassis merged 2 commits into
apache:masterfrom
casaroli:binfmt-checkexec

Conversation

@casaroli

@casaroli casaroli commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

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 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 use the mode of the program file, the builtin loader the mode of the builtin table.
  • The script loader now checks the script too. Its interpreter is checked by its own loader.
  • A file without execute permission gives EACCES. With CONFIG_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 without CONFIG_SCHED_USER_IDENTITY), nothing changes. With CONFIG_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 with posix_spawn(). The files are on v9fs, with the host mode, and on tmpfs mounts with and without MS_NOEXEC (#20762):

Check default BINFMT_CHECKEXEC SCHED_USER_IDENTITY + FS_PERMISSION
program with execute bits runs runs runs
program without execute bits runs EACCES EACCES
script with / without execute bits runs / runs runs / EACCES runs / EACCES
directory fails fails fails
program on a noexec mount runs EACCES EACCES

In 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.c builds for lm3s6965-ek:qemu-nxflat with CONFIG_BINFMT_CHECKEXEC (no user identities). ostest on qemu-armv8a:knsh and qemu-armv8a:nsh ends with ostest_main: Exiting with status 0. tools/checkpatch.sh -c -u -m -g passes.

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

Comment thread binfmt/builtin.c Resolved
Comment thread binfmt/binfmt_loadmodule.c Resolved
@casaroli casaroli changed the title binfmt: Check the execute permission once for every binary format. binfmt: Check the execute permission in every binary format. Oct 18, 2026
Comment thread binfmt/builtin.c Resolved
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]>
Comment thread binfmt/script.c Resolved
@acassis
acassis merged commit 621122e into apache:master Oct 19, 2026
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: BINFMT Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants