casaroli opened a new pull request, #4077: URL: https://github.com/apache/nuttx-apps/pull/4077
## 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#NNNNN (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. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
