casaroli opened a new pull request, #22065: URL: https://github.com/apache/nuttx/pull/22065
## Summary `v9fs_client_unlink()` clunks the fid of the directory after `Tunlinkat`, and its callers `v9fs_vfs_unlink()` and `v9fs_vfs_rmdir()` then release the same fid again with `v9fs_fid_put()`. After the clunk the fid number is free, and another thread of the mount can get it at once for a new walk. The second release then finds the fid of that thread: it drops its reference, clunks it and frees it while the thread still uses it. `v9fs_client_open()` and `v9fs_client_create()` then write the iounit into the freed memory. That breaks the free list of the kernel heap, and the next `malloc()` or `free()` faults at address 0x10018 (the iounit is 0x10000). Later requests of that thread use a fid that the server does not know any more. With only one thread, the second release finds no fid and does nothing, so this happens only when threads use the mount at the same time; on SMP it happens within seconds. `Tunlinkat` does not change the directory fid. This PR makes `v9fs_client_unlink()` only send the request. Its callers release the fid, as they do after the other requests. ## Impact `fs/v9fs` only, one function. No API, ABI or Kconfig change. The same in flat, protected and kernel builds, on every architecture and transport. ## Testing qemu-armv8a:knsh under HVF (Apple M-series), `CONFIG_MM_FILL_ALLOCATIONS=y`, the root file system on virtio-9p. A test program starts 3 threads that each open (`O_CREAT`), write, close and unlink files in one directory of the 9p mount, for 30 s; then the same for 30 s in rounds where a child process does it for up to 100 ms and joins its threads. | Tree | Result | |---|---| | master, 4 CPUs (`CONFIG_SMP`) | kernel fault in the first seconds: data abort at address 0x10018 in `mm_malloc()` from `v9fs_vfs_open()` | | master, 4 CPUs, with checks for the test only | the fid that `v9fs_client_create()` uses is freed during its request, by `v9fs_vfs_unlink()` of another thread, after `v9fs_client_unlink()` of that thread had clunked its own fid with the same number | | master, 1 CPU | no fault (57837 operations, 572 rounds): the second release comes right after the clunk, and another thread runs in between only if a time slice ends there | | this PR, 4 CPUs | threads: 41342 operations, 0 errors; processes: 569 rounds, 0 errors; no fault | | this PR, 1 CPU | threads: 55326 operations, 0 errors; processes: 571 rounds, 0 errors | With this PR, `mkdir`, `rm` and `rmdir` on the 9p mount work as before, and the kernel heap does not grow over the runs (a fid that is not released would stay in the heap). `tools/checkpatch.sh -c -u -m -g` passes. Documentation: no change. -- 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]
