Skip to contentSkip to conversation

fuse: check aborted connection before adding requests to pending list for resending

PATCH Applied Joanne Koong 4 participants 4 messages Jul 25, 2024 – Aug 22, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fuse: check aborted connection before adding requests to pending list for resending

There is a race condition where inflight requests will not be aborted if they are in the middle of being re-sent when the connection is aborted.

If fuse_resend has already moved all the requests in the fpq->processing lists to its private queue ("to_queue") and then the connection starts and finishes aborting, these requests will be added to the pending queue and remain on it indefinitely.

Fixes 760eac73f9f6 ("fuse: Introduce a new notification type for resend pending requests")
---
 fs/fuse/dev.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/fuse/dev.c +9 -0
index 9eb191b5c4de..a11461ef6022 100644
@@ -31,6 +31,8 @@ MODULE_ALIAS("devname:fuse");
 
 static struct kmem_cache *fuse_req_cachep;
 
+static void end_requests(struct list_head *head);
+
 static struct fuse_dev *fuse_get_dev(struct file *file)
 {
 	/*
@@ -1820,6 +1822,13 @@ static void fuse_resend(struct fuse_conn *fc)
 	}
 
 	spin_lock(&fiq->lock);
+	if (!fiq->connected) {
+		spin_unlock(&fiq->lock);
+		list_for_each_entry(req, &to_queue, list)
+			clear_bit(FR_PENDING, &req->flags);
+		end_requests(&to_queue);
+		return;
+	}
 	/* iq and pq requests are both oldest to newest */
 	list_splice(&to_queue, &fiq->pending);
 	fiq->ops->wake_pending_and_unlock(fiq);
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Joanne Koong

There is a race condition where inflight requests will not be aborted if they are in the middle of being re-sent when the connection is aborted.

If fuse_resend has already moved all the requests in the fpq->processing lists to its private queue ("to_queue") and then the connection starts and finishes aborting, these requests will be added to the pending queue and remain on it indefinitely.

Fixes 760eac73f9f6 ("fuse: Introduce a new notification type for resend pending requests")

Nice catch, you can add

Thanks,

Josef

Reviewed-by on v1 1/1
#2 lore raw
In reply to Joanne Koong
Quoted 31 lines · Joanne Koong

There is a race condition where inflight requests will not be aborted if they are in the middle of being re-sent when the connection is aborted.

If fuse_resend has already moved all the requests in the fpq->processing lists to its private queue ("to_queue") and then the connection starts and finishes aborting, these requests will be added to the pending queue and remain on it indefinitely.

Fixes 760eac73f9f6 ("fuse: Introduce a new notification type for resend pending requests")
---
 fs/fuse/dev.c | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/fuse/dev.c +2 -0
index 9eb191b5c4de..a11461ef6022 100644
@@ -31,6 +31,8 @@ MODULE_ALIAS("devname:fuse");
 
 static struct kmem_cache *fuse_req_cachep;
 
+static void end_requests(struct list_head *head);
+
 static struct fuse_dev *fuse_get_dev(struct file *file)
 {
 	/*
@@ -1820,6 +1822,13 @@ static void fuse_resend(struct fuse_conn *fc)
 	}
 
 	spin_lock(&fiq->lock);

fs/fuse/dev.c static void fuse_resend(struct fuse_conn *fc) · line 1834

Quoted 10 lines
fs/fuse/dev.c +7 -0
+	if (!fiq->connected) {
+		spin_unlock(&fiq->lock);
+		list_for_each_entry(req, &to_queue, list)
+			clear_bit(FR_PENDING, &req->flags);
+		end_requests(&to_queue);
+		return;
+	}
 	/* iq and pq requests are both oldest to newest */
 	list_splice(&to_queue, &fiq->pending);
 	fiq->ops->wake_pending_and_unlock(fiq);

LGTM.

Signature · 2 lines
Thanks,
Jingbo
maintainer Applied
#3 lore raw
In reply to Joanne Koong
Quoted 11 lines · Joanne Koong

There is a race condition where inflight requests will not be aborted if they are in the middle of being re-sent when the connection is aborted.

If fuse_resend has already moved all the requests in the fpq->processing lists to its private queue ("to_queue") and then the connection starts and finishes aborting, these requests will be added to the pending queue and remain on it indefinitely.

Fixes 760eac73f9f6 ("fuse: Introduce a new notification type for resend pending requests")

Applied, thanks.

Miklos