fuse: fix request lifetime races in the resend path
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest2 patches 7 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | fuse: set FR_PENDING under fiq->lock in fuse_chan_resend()fs/ | +10 | 5 replies | |
| 2/2 | fuse: don't queue an interrupt for a request that is back on fiq->pendingfs/ | +5 | 1 reply |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/2] fuse: fix request lifetime races in the resend path
Two fixes for races introduced together with FUSE_NOTIFY_RESEND (760eac73f9f6, v6.9), where fuse_chan_resend() moves in-flight requests from fpq->processing back onto fiq->pending.
Both concern the same invariant. FR_PENDING means "queued on fiq->pending, protected by fiq->lock", and it is what fuse_remove_pending_req() relies on to unlink a request and drop the queue's reference. A request on fiq->pending can therefore be released without going through fuse_request_end(), so anything that sets FR_PENDING, or that leaves a request linked elsewhere while FR_PENDING is set, has to be done under fiq->lock.
Patch 1 sets FR_PENDING under fiq->lock. fuse_chan_resend() currently publishes the bit while the requests are reachable only through a stack-local list, so a concurrent waiter can unlink and release a request that fuse_chan_resend() is still iterating over.
Patch 2 re-checks FR_SENT under fiq->lock in fuse_dev_queue_interrupt(). Its callers sample FR_SENT unlocked and fuse_chan_resend() clears it under fiq->lock, so a request can end up queued on fiq->pending and linked on fiq->interrupts at the same time.
Dependency between the two patches
==================================
They are independent and neither supersedes the other, so please apply them together rather than picking one. Patch 2 does not affect the unlocked FR_PENDING publish that patch 1 fixes. Patch 1 cannot catch an intr_entry that is linked after its locked walk has already run, because that link happens once fuse_chan_resend() has released fiq->lock. Patch 1 on its own also makes the condition patch 2 fixes easier to hit, since requests that would previously have been torn out of the resend list now survive to be re-queued.
Both were found by code audit and confirmed on v7.2-rc6 (075b74841bd0), where the series was built and tested; the resend and interrupt paths were verified to still be exercised with the series applied.
A KASAN reproducer for this issue is available if requested.
Jun Yang (2):
fuse: set FR_PENDING under fiq->lock in fuse_chan_resend()
fuse: don't queue an interrupt for a request that is back on
fiq->pending
fs/fuse/dev.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
Signature · 1 line
2.43.7