casaroli opened a new pull request, #20818:
URL: https://github.com/apache/nuttx/pull/20818

   ## Summary
   
   In a kernel build (`CONFIG_BUILD_KERNEL`), `umask()` had no effect on the 
files that a process creates. libc kept the mask in a static variable, and each 
process and the kernel have their own copy of libc. So `open()`, `mkdir()`, 
`mq_open()` and `sem_open()` in the kernel always used the mask 0, and a 
program that `posix_spawn()` or `exec()` started got the mask 0. In the flat 
and protected builds, the mask was in the `task_info_s` of the task group, and 
a task that `task_create()` or `posix_spawn()` started got the mask 0. POSIX 
says that a new process gets the mask of its parent.
   
   This PR keeps the mask in `struct task_group_s` (`tg_umask`) and makes 
`umask()` and `getumask()` system calls, as #20784 did for the resource limits. 
A new task group gets the mask of the parent group. Kernel threads keep the 
mask 0. `umask()` keeps only the permission bits of the mask. 
`libs/libc/misc/lib_umask.c` and `ta_umask` in `task_info_s` are removed.
   
   ## Impact
   
   Kernel builds: the kernel applies the mask of the calling process, and 
`posix_spawn()` and `exec()` children get the mask of the parent (`fork()` 
children already did). Flat and protected builds: `task_create()` and 
`posix_spawn()` children get the mask of the parent. Two new system calls: 
`umask` and `getumask`.
   
   Size (text + data, `nuttx`): `lm3s6965-ek:qemu-flat` +24 B, `mps2-an500:nsh` 
+36 B, `mps2-an500:knsh` (protected) +128 B kernel and +0 B user, 
`qemu-armv8a:knsh` +208 B. No Kconfig option, because this is a bug fix.
   
   Documentation: a new paragraph "File Mode Creation Mask" in 
`Documentation/reference/user/01_task_control.rst`.
   
   ## Testing
   
   A test program calls `umask(077)`, creates a file (`open(O_CREAT, 0666)`), a 
directory (`mkdir(0777)`) and a node (`mknod(S_IFREG | 0666)`) on tmpfs and on 
v9fs, and checks the modes with `stat()`. Then it checks that a thread that 
changes the mask changes it for the process, and that a child gets the mask 
077. The child returns `umask()` as its exit status.
   
   `qemu-armv8a:knsh` (QEMU 11 with HVF on an Apple M4, `/system` over virtio 
9p, with `FS_TMPFS`, `FS_PERMISSION`, `PSEUDOFS_ATTRIBUTES`, 
`SCHED_USER_IDENTITY`, `PIPES`):
   
   | Check | master | this PR |
   |---|---|---|
   | tmpfs `open()` / `mkdir()` / `mknod()` | 0666 / 0777 / 0666 (FAIL) | 0600 
/ 0700 / 0600 |
   | v9fs `open()` / `mkdir()` / `mknod()` | 0666 / 0777 / 0666 (FAIL) | 0600 / 
0700 / 0600 |
   | mask after a thread sets 027 | 027 | 027 |
   | child of `posix_spawn()` | 000 (FAIL) | 077 |
   | child of `fork()` | 077 | 077 |
   | child of `fork()` + `exec()` | 000 (FAIL) | 077 |
   | `umask(07077)`, then `umask()` returns | 07077 | 077 |
   
   Flat `qemu-armv8a:nsh` (HVF) and protected `mps2-an500:knsh` (QEMU 11, TCG), 
the test as an NSH application:
   
   | Check | master | this PR |
   |---|---|---|
   | tmpfs `open()` / `mkdir()` / `mknod()` | 0600 / 0700 / 0600 | 0600 / 0700 
/ 0600 |
   | mask after a thread sets 027 | 027 | 027 |
   | child of `task_create()` | 000 (FAIL) | 077 |
   
   `ostest` on `qemu-armv8a:knsh` and `qemu-armv8a:nsh` ends with `ostest_main: 
Exiting with status 0`. CMake builds of `qemu-armv8a:nsh` and 
`qemu-armv8a:knsh` pass. `tools/checkpatch.sh -c -u -m -g` passes.
   


-- 
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]

Reply via email to