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

   ## Summary
   
   `read_pseudodir()` reads `pdir->next` and its name, operations and
   child pointers without the inode lock, and takes the lock only to
   advance to the next peer. If another thread unregisters a driver in
   between, the peer can be unlinked and freed, and `readdir()` then
   dereferences freed memory.
   
   Take the inode lock at the start of `read_pseudodir()`, as
   `seek_pseudodir()` already does, and release it on both return paths.
   `inode_release()` of the previous entry still runs after the unlock.
   
   ## Impact
   
   No functional change for a single reader. `readdir()` of a pseudo
   directory is now serialized with driver registration and removal.
   
   ## Testing
   
   Host: Ubuntu x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0, master 
03aea78639 (rebased onto 6f47a1c3d6; the one new commit does not touch fs/).
   
   - `sim:smp` (4 CPUs) with `CONFIG_MM_FILL_ALLOCATIONS=y`: one thread
     registers and unregisters drivers under `/dev` in a loop while
     another thread runs `opendir()`/`readdir()`/`closedir()` on `/dev`
     200 times. Both master and this PR finish without a crash; sim threads
     are host threads, so the race window is hard to hit and this run only
     shows the change does not deadlock or break the listing.
   - `sim:nsh`: the same test runs 2000 rounds with identical entry counts
     on master and this PR.
   - `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
   - Make and CMake builds pass; `ostest` exits with status 0.
   


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