Skip to contentSkip to conversation

fuse: remove request-less entries from ent_w_req_queue to fix NULL deref

PATCH Applied Joanne Koong 2 participants 2 messages Jun 9 – Jun 10

Subsystems (2)
lore
Share & tools
lore

Joanne Koong

author maintainer
#0 lore raw

PATCH 1/1 fuse: remove request-less entries from ent_w_req_queue to fix NULL deref

If a copy into the userspace ring buffer fails, a request will be terminated and fuse_uring_req_end() will set ent->fuse_req to NULL but it will leave the entry on ent_w_req_queue in FRRS_FUSE_REQ state. This can lead to a NULL deref if the request expiration logic scans ent_w_req_queue in the window before the entry is moved off it.

Fix this by taking the entry off ent_w_req_queue and changing its state from FRRS_FUSE_REQ to FRRS_INVALID before terminating the request.

Fixes 4fea593e625c ("fuse: optimize over-io-uring request expiration check")
---
 fs/fuse/dev_uring.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
fs/fuse/dev_uring.c +12 -2
index f74ca57f81ec..3a784f182883 100644
@@ -708,10 +708,20 @@ static int fuse_uring_prepare_send(struct fuse_ring_ent *ent,
 	int err;
 
 	err = fuse_uring_copy_to_ring(ent, req);
-	if (!err)
+	if (!err) {
 		set_bit(FR_SENT, &req->flags);
-	else
+	} else {
+		/*
+		 * Copying the request failed. Remove the entry from the
+		 * ent_w_req_queue list and terminate the request
+		 */
+		spin_lock(&ent->queue->lock);
+		list_del_init(&ent->list);
+		ent->state = FRRS_INVALID;
+		spin_unlock(&ent->queue->lock);
+
 		fuse_uring_req_end(ent, req, err);
+	}
 
 	return err;
 }
Signature · 1 line
2.52.0
maintainer Applied
#1 lore raw
Quoted 7 lines · Joanne Koong

If a copy into the userspace ring buffer fails, a request will be terminated and fuse_uring_req_end() will set ent->fuse_req to NULL but it will leave the entry on ent_w_req_queue in FRRS_FUSE_REQ state. This can lead to a NULL deref if the request expiration logic scans ent_w_req_queue in the window before the entry is moved off it.

Quoted 6 lines

Fix this by taking the entry off ent_w_req_queue and changing its state from FRRS_FUSE_REQ to FRRS_INVALID before terminating the request.

Fixes 4fea593e625c ("fuse: optimize over-io-uring request expiration check")

Applied, thanks.

Miklos