linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pradeep P V K <quic_pragalla@quicinc.com>
To: miklos@szeredi.hu
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Pradeep P V K <quic_pragalla@quicinc.com>
Subject: [PATCH V1] fuse: Abort the requests under processing queue with a spin_lock
Date: Wed, 31 May 2023 14:56:43 +0530	[thread overview]
Message-ID: <20230531092643.45607-1-quic_pragalla@quicinc.com> (raw)

There is a potential race/timing issue while aborting the
requests on processing list between fuse_dev_release() and
fuse_abort_conn(). This is resulting into below warnings
and can even result into UAF issues.

[22809.190255][T31644] refcount_t: underflow; use-after-free.
[22809.190266][T31644] WARNING: CPU: 2 PID: 31644 at lib/refcount.c:28
refcount_warn_saturate+0x110/0x158
...
[22809.190567][T31644] Call trace:
[22809.190567][T31644]  refcount_warn_saturate+0x110/0x158
[22809.190569][T31644]  fuse_file_put+0xfc/0x104
[22809.190575][T31644]  fuse_readpages_end+0x210/0x29c
[22809.190579][T31644]  fuse_request_end+0x17c/0x200
[22809.190580][T31644]  fuse_dev_release+0xe0/0x1e4
[22809.190582][T31644]  __fput+0xfc/0x294
[22809.190588][T31644]  ____fput+0x18/0x2c
[22809.190590][T31644]  task_work_run+0xd8/0x104
[22809.190599][T31644]  do_exit+0x2a8/0xa5c
[22809.190605][T31644]  do_group_exit+0x78/0xa4
[22809.190608][T31644]  get_signal+0x778/0x8a8
[22809.190614][T31644]  do_notify_resume+0x134/0x340
[22809.190617][T31644]  el0_svc+0x68/0xc4
[22809.190623][T31644]  el0t_64_sync_handler+0x8c/0xfc
[22809.190626][T31644]  el0t_64_sync+0x1a0/0x1a4

Fix this by aborting the requests in fuse_dev_release()
under fpq spin lock.

Signed-off-by: Pradeep P V K <quic_pragalla@quicinc.com>
---
 fs/fuse/dev.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 1a8f82f478cb..bbc33a97ab7c 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -2208,9 +2208,8 @@ int fuse_dev_release(struct inode *inode, struct file *file)
 		WARN_ON(!list_empty(&fpq->io));
 		for (i = 0; i < FUSE_PQ_HASH_SIZE; i++)
 			list_splice_init(&fpq->processing[i], &to_end);
-		spin_unlock(&fpq->lock);
-
 		end_requests(&to_end);
+		spin_unlock(&fpq->lock);
 
 		/* Are we the last open device? */
 		if (atomic_dec_and_test(&fc->dev_count)) {
-- 
2.17.1


             reply	other threads:[~2023-05-31  9:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-31  9:26 Pradeep P V K [this message]
2023-05-31 11:52 ` [PATCH V1] fuse: Abort the requests under processing queue with a spin_lock Miklos Szeredi
2023-06-01 10:02   ` Pradeep Pragallapati
2023-06-01 12:13     ` Miklos Szeredi

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=20230531092643.45607-1-quic_pragalla@quicinc.com \
    --to=quic_pragalla@quicinc.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@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;
as well as URLs for NNTP newsgroup(s).