Skip to content

system/nxinit: Add an option to set the umask at start. - #4077

Open
casaroli wants to merge 1 commit into
apache:masterfrom
casaroli:fb-nxinit-umask-up
Open

casaroli wants to merge 1 commit into
apache:masterfrom
casaroli:fb-nxinit-umask-up

Conversation

@casaroli

@casaroli casaroli commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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 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. Kconfig has no octal type, so a string keeps the usual form 022.

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 (with SCHED_USER_IDENTITY and PSEUDOFS_ATTRIBUTES), so that tmpfs keeps the file modes. Commands in nsh: mkdir /tmp/d, echo x > /tmp/f, ls -l /tmp.

apps CONFIG_SYSTEM_NXINIT_UMASK /tmp/d /tmp/f
master - drwxrwxrwx -rw-rw-rw-
this PR empty (default) drwxrwxrwx -rw-rw-rw-
this PR 022 drwxr-xr-x -rw-r--r--
this PR 9x drwxrwxrwx -rw-rw-rw-, and init prints Error Bad umask 9x

With 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 022 and FS_PERMISSION builds. 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 and 022).

tools/checkpatch.sh passes. The docs PR builds with Sphinx, and the changed page gives no warning.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant