Repository navigation
Conversation
NuttX starts the first task with the umask 0, and init keeps it, so every command and service inherits it. Files and directories that programs create with mode 0666 or 0777 can then be written by all users, where the file system keeps file modes. Some programs refuse to run in this case: sshd stops with "/run/sshd must be owned by root and not group or world-writable". Add CONFIG_SYSTEM_NXINIT_UMASK, an octal string. init calls umask() with it at the start of main(), before it starts anything. A bad value gives an error message, and init keeps the umask. The default is empty: init keeps the umask that it got, so no board changes. A system with file permissions can set "022", as sysvinit and systemd do. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
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
NuttX starts the first task with the umask 0, and nxinit keeps it. So every command and service of nxinit has the umask 0. Where the file system keeps file modes (for example tmpfs with
CONFIG_FS_PERMISSION), the files and directories that programs create with mode 0666 or 0777 are writable by all users. Some programs refuse to run in this case: sshd stops with "/run/sshd must be owned by root and not group or world-writable".This PR adds
CONFIG_SYSTEM_NXINIT_UMASK, an octal string. If it is not empty, init callsumask()with it at the start ofmain(), before it starts anything. A bad value gives an error message, and init keeps the umask. Kconfig has no octal type, so a string keeps the usual form022.The default is empty: init keeps the umask that it got. A system with file permissions can set
022, as sysvinit and systemd do.The documentation is in apache/nuttx#21956 (Documentation/applications/system/nxinit/index.rst).
Impact
No change for existing configurations: the default is empty, and init then does not call
umask(). Many board configurations use nxinit (qemu-armv8a:nsh, rv-virt:nsh64, sim:nsh and others); their umask stays 0. The code is in the init program only, the same in flat, protected and kernel builds.Testing
Board qemu-armv8a:nsh (flat build, arm64, GCC 14.2, QEMU), where nxinit is the init and nsh is its service. I added
CONFIG_FS_PERMISSION(withSCHED_USER_IDENTITYandPSEUDOFS_ATTRIBUTES), so that tmpfs keeps the file modes. Commands in nsh:mkdir /tmp/d,echo x > /tmp/f,ls -l /tmp.CONFIG_SYSTEM_NXINIT_UMASK/tmp/d/tmp/fdrwxrwxrwx-rw-rw-rw-drwxrwxrwx-rw-rw-rw-022drwxr-xr-x-rw-r--r--9xdrwxrwxrwx-rw-rw-rw-, and init printsError Bad umask 9xWith the default, the image of this PR has the same size as the image of master (text 368924 bytes with
FS_PERMISSION, 360316 bytes with the stock configuration). ostest passes (exit status 0) on the stock qemu-armv8a:nsh with this PR.rv-virt:pnsh64 (protected build, RV64) with
022andFS_PERMISSIONbuilds. In QEMU it printed no shell prompt, so the test did not run there. The arm64 build uses-Wshadow -Werror, and the new code builds with them (empty and022).tools/checkpatch.sh passes. The docs PR builds with Sphinx, and the changed page gives no warning.