fuse: wait for FR_FINISHED on abort_on_kill to prevent use-after-free
Subsystems (3)
PATCH 1/1 fuse: wait for FR_FINISHED on abort_on_kill to prevent use-after-free
The abort_on_kill path in request_wait_answer() calls fuse_abort_conn() and returns without waiting for FR_FINISHED. If fuse_dev_do_write() is concurrently processing the same request (FR_LOCKED set), the caller frees req->args while it is still being accessed, causing a use-after-free.
Fix this by jumping to the existing wait_event(FR_FINISHED) instead of returning early. The wait will not hang because fuse_abort_conn() ensures all requests are ended.
---
Tested by injecting a msleep(100) between spin_unlock(&fpq->lock) and the req->args->page_replace access in fuse_dev_do_write() to widen the race window, then running a reproducer that concurrently writes the INIT reply while SIGKILL is delivered to the mount process. KASAN reliably reports the slab-use-after-free without the fix, and the report is absent with the fix applied.
fs/fuse/dev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/fuse/dev.c +2 -1
@@ -572,7 +572,7 @@ static void request_wait_answer(struct fuse_req *req)if (req->args->abort_on_kill) {fuse_abort_conn (fc); -return ; + goto wait_for_finish; }if (test_bit (FR_URING , &req->flags))
@@ -583,6 +583,7 @@ static void request_wait_answer(struct fuse_req *req)return ; } +wait_for_finish:/* * Either request is already in userspace, or it was forced. * Wait it out.
Signature · 1 line
2.45.2
Quoted 11 lines · Rochan Avlur
The
abort_on_killpath inrequest_wait_answer()callsfuse_abort_conn()and returns without waiting forFR_FINISHED. Iffuse_dev_do_write()is concurrently processing the same request (FR_LOCKEDset), the caller freesreq->argswhile it is still being accessed, causing a use-after-free.Fix this by jumping to the existing
wait_event(FR_FINISHED)instead of returning early. The wait will not hang becausefuse_abort_conn()ensures all requests are ended.
Quoted 5 lines
Reported-by [email protected]Fixes 204aa22a686b ("fuse: abort on fatal signal during sync init")Assisted-by Claude:claude-opus-4-6Signed-off-by Rochan Avlur <[email protected]>
Applied, thanks.
Miklos