You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/12/21 03:18:09 UTC

[GitHub] [incubator-nuttx] MTres19 commented on issue #2663: kthread_create hangs waiting on semaphore while trying to copy file descriptors

MTres19 commented on issue #2663:
URL: https://github.com/apache/incubator-nuttx/issues/2663#issuecomment-998437230


   So taking a fresh look at this and not being _quite_ so pressed for time, I would like to discuss what the correct fix for this bug would be. Restated, the problem is:
   
   App calls `open()` → `can_open()` → `tivacan_open()`, which calls `kthread_create()`. `kthread_create` calls `nxthread_create()` which allocates the thread control block, sets the thread type to kernel and calls `nxtask_init()`. `nxtask_init()` does the following:
   
   1. Allocates a new task group with `group_allocate()`. `group_allocate` allocates memory on the heap but it also copies the UID, GID, and environment of the current task to the new task. That doesn't make sense for kernel threads.
   2. Copies file descriptors for the task group with `group_setuptaskfiles()`. Again this tries to copy userspace file descriptors to the kernel thread which is wrong.
   3. Does some other initialization stuff
   4. Calls `group_initialize()` to finish the setup.
   
   To me it seems kernel threads should have a different task group struct that excludes at least `tg_filelist`, `tg_streamlist`, `tg_envsize`, and `tg_envp`. Or at least these should not be initialized for kernel threads. The latter option would be easy, like the band-aid patch I already posted.
   
   It also seems that kernel threads should have their UID and GID set to 0 instead of inheriting it.
   
   Are these accurate conclusions? Given a recommendation I could submit a PR.


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org