Linux filesystem development
 help / color / mirror / Atom feed
From: Jian Huang Li <ali@ddn.com>
To: linux-fsdevel@vger.kernel.org
Cc: miklos@szeredi.hu, bschubert@ddn.com
Subject: [PATCH v2] fs/fuse: fix potential memory leak from fuse_uring_cancel
Date: Thu, 11 Sep 2025 15:33:25 +0800	[thread overview]
Message-ID: <94377ddf-9d04-4181-a632-d8c393dcd240@ddn.com> (raw)

This issue could be observed sometimes during libfuse xfstests, from
dmseg prints some like "kernel: WARNING: CPU: 4 PID: 0 at
fs/fuse/dev_uring.c:204 fuse_uring_destruct+0x1f5/0x200 [fuse]".

The cause is, if when fuse daemon just submitted
FUSE_IO_URING_CMD_REGISTER SQEs, then umount or fuse daemon quits at
this very early stage. After all uring queues stopped, might have one or
more unprocessed FUSE_IO_URING_CMD_REGISTER SQEs get processed then some
new ring entities are created and added to ent_avail_queue, and
immediately fuse_uring_cancel moves them to ent_in_userspace after SQEs
get canceled. These ring entities will not be moved to ent_released, and
will stay in ent_in_userspace when fuse_uring_destruct is called, needed
be freed by the function.

Fixes: b6236c8407cb ("fuse: {io-uring} Prevent mount point hang on 
fuse-server termination")
Signed-off-by: Jian Huang Li <ali@ddn.com>
---
  fs/fuse/dev_uring.c | 15 ++++++++++++++-
  1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/fs/fuse/dev_uring.c b/fs/fuse/dev_uring.c
index 249b210becb1..eed0fc6c8b05 100644
--- a/fs/fuse/dev_uring.c
+++ b/fs/fuse/dev_uring.c
@@ -201,7 +201,20 @@ void fuse_uring_destruct(struct fuse_conn *fc)
  		WARN_ON(!list_empty(&queue->ent_avail_queue));
  		WARN_ON(!list_empty(&queue->ent_w_req_queue));
  		WARN_ON(!list_empty(&queue->ent_commit_queue));
-		WARN_ON(!list_empty(&queue->ent_in_userspace));
+
+		/*
+		 * ent_in_userspace might not be empty, because
+		 * FUSE_IO_URING_CMD_REGISTER is not accounted yet
+		 * in ring->queue_refs and fuse_uring_wait_stopped_queues()
+		 * then passes too early. fuse_uring_cancel() adds these
+		 * commands to queue->ent_in_userspace - they need
+		 * to be freed here
+		 */
+		list_for_each_entry_safe(ent, next, &queue->ent_in_userspace,
+					 list) {
+			list_del_init(&ent->list);
+			kfree(ent);
+		}

  		list_for_each_entry_safe(ent, next, &queue->ent_released,
  					 list) {
-- 
2.47.1

             reply	other threads:[~2025-09-11  7:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-11  7:33 Jian Huang Li [this message]
2025-09-11  7:37 ` [PATCH v2] fs/fuse: fix potential memory leak from fuse_uring_cancel Jian Huang Li
2025-09-15 18:15 ` Joanne Koong
2025-09-15 20:15   ` Bernd Schubert
2025-09-15 21:23     ` Joanne Koong
2025-09-15 21:46       ` Bernd Schubert
2025-09-15 21:57         ` Bernd Schubert
2025-09-15 23:04           ` Joanne Koong
2025-09-16  9:17             ` Bernd Schubert
2025-09-16 20:12               ` Joanne Koong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=94377ddf-9d04-4181-a632-d8c393dcd240@ddn.com \
    --to=ali@ddn.com \
    --cc=bschubert@ddn.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox