casaroli commented on code in PR #20818:
URL: https://github.com/apache/nuttx/pull/20818#discussion_r4319067213


##########
include/nuttx/tls.h:
##########
@@ -144,7 +144,6 @@ struct task_info_s
 #endif
 #ifndef CONFIG_BUILD_KERNEL
   struct getopt_s ta_getopt; /* Globals used by getopt() */
-  mode_t          ta_umask;  /* File mode creation mask */

Review Comment:
   In a kernel build `task_info_s` is in the user heap of the process, so the 
kernel can read `ta_umask` only while the address environment of that process 
is active. Two paths need the mask of the parent while the address environment 
of the child is active: `exec_module()` selects the new address environment 
before `nxtask_init()` -> `group_allocate()` -> `task_init_info()`, and the 
`open` file actions of `posix_spawn()` run in `nxtask_init()` too 
(`spawn_file_actions()` -> `fdlist_open()` -> `getumask()`).
   
   I tried it: with `ta_umask` out of the `#ifndef` and `task_init_info()` 
copying `this_task()->group->tg_info->ta_umask`, `qemu-armv8a:knsh` does not 
boot. The first exec from `/system/bin/init` stops with a data abort (level 3 
translation fault, FAR 0xc00166d4) in `task_init_info()`, at the read of the 
task_info_s of the parent.
   
   It can be made to work: read the mask before `addrenv_select()` in 
`exec_module()`, and give the file actions the mask of the child. But each 
kernel path that runs in another address environment then needs this care, and 
the kernel reads user memory for every `open()`, `mkdir()`, `mq_open()` and 
`sem_open()`. `tg_umask` is kernel memory: it is readable in every context, 
`group_allocate()` copies it, and the child of `posix_spawn()`, `exec()`, 
`fork()` and `task_create()` gets it. This is the reason why #20784 also keeps 
the resource limits in `task_group_s`.
   



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