From: Bernd Schubert <bernd@bsbernd.com>
To: Berkant Koc <me@berkoc.com>, Greg KH <gregkh@linuxfoundation.org>,
Miklos Szeredi <miklos@szeredi.hu>
Cc: security@kernel.org, Joanne Koong <joannelkoong@gmail.com>,
linux-fuse@vger.kernel.org, linux-kernel@vger.kernel.org,
Zhenghang Xiao <kipreyyy@gmail.com>
Subject: Re: [PATCH 1/2] fuse: io-uring: clear ent->fuse_req in commit_fetch error path
Date: Sun, 17 May 2026 16:11:47 +0200 [thread overview]
Message-ID: <3f1567cf-218e-405b-be7f-e9e9c44205d6@bsbernd.com> (raw)
In-Reply-To: <20260517-fuse-uaf-patch1@berkoc.com>
On 5/17/26 14:59, Berkant Koc wrote:
> [You don't often get email from me@berkoc.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> From: Berkant Koc <me@berkoc.com>
>
> fuse_uring_commit_fetch() locates a request, removes it from the
> processing queue, clears req->ring_entry, then calls
> fuse_ring_ent_set_commit() under queue->lock. On the error branch
> (set_commit returning non-zero because the entry is not in
> FRRS_USERSPACE) the function unlocks the queue and ends the request
> directly with fuse_request_end(), but it never clears ent->fuse_req.
>
> ent->fuse_req then keeps pointing at the freed fuse_req while the entry
> remains on a queue list. Subsequent teardown via
> fuse_uring_entry_teardown() reads ent->fuse_req under queue->lock and
> hands the dangling pointer to fuse_uring_stop_fuse_req_end(), which
> dereferences it and calls fuse_request_end() a second time on freed
> memory.
>
> Route the error branch through fuse_uring_req_end() instead. That
> helper acquires queue->lock, clears ent->fuse_req under the lock,
> removes the request from any list it is still on, drops the lock, sets
> req->out.h.error, clears FR_SENT and ends the request. The
> ent->fuse_req = NULL store under the lock is what closes the window
> for the later teardown reader.
>
> Fixes: c090c8abae4b ("fuse: Add io-uring sqe commit and fetch support")
> Cc: stable@vger.kernel.org # 6.14+
> Signed-off-by: Berkant Koc <me@berkoc.com>
> ---
> fs/fuse/dev_uring.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/fs/fuse/dev_uring.c b/fs/fuse/dev_uring.c
> index 7b9822e8837b..7523569ffdce 100644
> --- a/fs/fuse/dev_uring.c
> +++ b/fs/fuse/dev_uring.c
> @@ -924,9 +924,7 @@ static int fuse_uring_commit_fetch(struct io_uring_cmd *cmd, int issue_flags,
> pr_info_ratelimited("qid=%d commit_id %llu state %d",
> queue->qid, commit_id, ent->state);
> spin_unlock(&queue->lock);
> - req->out.h.error = err;
> - clear_bit(FR_SENT, &req->flags);
> - fuse_request_end(req);
> + fuse_uring_req_end(ent, req, err);
> return err;
> }
>
> --
> 2.47.3
We already had a security report for that on Friday
>
> [You don't often get email from kipreyyy@gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> fuse_uring_commit_fetch() error path calls fuse_request_end(req) without
> clearing ent->fuse_req when fuse_ring_ent_set_commit() fails. The
> still-pending fuse_uring_send_in_task() task-work later dereferences the
> dangling pointer through fuse_uring_prepare_send(), causing a
> use-after-free.
>
> Clear ent->fuse_req under queue->lock in the error path, matching the
> pattern in fuse_uring_req_end(). Add a NULL check in
> fuse_uring_send_in_task() so the entry is gracefully recycled if the
> request was detached.
>
> Fixes: c090c8abae4b ("fuse: Add io-uring sqe commit and fetch support")
> Signed-off-by: Zhenghang Xiao
> ---
> fs/fuse/dev_uring.c | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/fs/fuse/dev_uring.c b/fs/fuse/dev_uring.c
> index 7b9822e8837b..5e51c36ae2a0 100644
> --- a/fs/fuse/dev_uring.c
> +++ b/fs/fuse/dev_uring.c
> @@ -921,6 +921,13 @@ static int fuse_uring_commit_fetch(struct io_uring_cmd *cmd, int issue_flags,
>
> err = fuse_ring_ent_set_commit(ent);
> if (err != 0) {
> + /*
> + * Entry is not in FRRS_USERSPACE state. Clear the
> + * back-pointer to prevent the still-pending
> + * fuse_uring_send_in_task() from dereferencing a request
> + * that is about to be freed.
> + */
> + ent->fuse_req = NULL;
> pr_info_ratelimited("qid=%d commit_id %llu state %d",
> queue->qid, commit_id, ent->state);
> spin_unlock(&queue->lock);
> @@ -1220,6 +1227,15 @@ static void fuse_uring_send_in_task(struct io_tw_req tw_req, io_tw_token_t tw)
> int err;
>
> if (!tw.cancel) {
> + /*
> + * If the request was detached (e.g. by fuse_uring_commit_fetch
> + * error path), fuse_req will be NULL. Bail out and recycle the
> + * entry for the next request.
> + */
> + if (!ent->fuse_req) {
> + fuse_uring_next_fuse_req(ent, queue, issue_flags);
> + return;
> + }
> err = fuse_uring_prepare_send(ent, ent->fuse_req);
> if (err) {
> fuse_uring_next_fuse_req(ent, queue, issue_flags);
> --
I had already replied to Zhenghang on Friday, I don't think it is
enough. This condition
> err = fuse_ring_ent_set_commit(ent);
> if (err != 0) {
can also be triggered by a bad fuse-server / user-space and a teardown
race. The tear down race is easy, I think.
Fuse-server that wants to trick us is harder, as checking for
ent->fuse_req == NULL in fuse_uring_send_in_task() is not enough, the
race is valid all over the copy operation (fuse_uring_prepare_send()). I
didn't come to it yesterday (was working for main work), going to look
into it a bit later today.
Thanks,
Bernd
next prev parent reply other threads:[~2026-05-17 14:11 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260517095846.fuse-iouring-uaf.dc5f5dbb71dc@berkoc.com>
[not found] ` <2026051703-equinox-multitude-91e2@gregkh>
2026-05-17 12:59 ` [PATCH 0/2] fuse: io-uring: fix two UAFs in dev_uring.c teardown Berkant Koc
2026-05-17 12:59 ` [PATCH 1/2] fuse: io-uring: clear ent->fuse_req in commit_fetch error path Berkant Koc
2026-05-17 14:11 ` Bernd Schubert [this message]
2026-05-17 14:24 ` Berkant Koc
2026-05-17 12:59 ` [PATCH 2/2] fuse: wait for aborted connection before releasing last fuse_dev Berkant Koc
2026-05-17 15:00 ` Bernd Schubert
2026-05-18 1:13 ` Berkant Koc
2026-05-18 9:55 ` Bernd Schubert
2026-05-18 11:47 ` Bernd Schubert
2026-05-18 14:32 ` Berkant Koc
2026-05-18 14:46 ` Bernd Schubert
2026-05-18 15:35 ` Joanne Koong
2026-05-18 17:49 ` Berkant Koc
2026-05-18 15:47 ` Berkant Koc
2026-05-18 9:06 ` Pavel Begunkov
2026-05-18 9:50 ` Bernd Schubert
2026-05-18 10:32 ` Pavel Begunkov
2026-05-17 13:14 ` [PATCH 0/2] fuse: io-uring: fix two UAFs in dev_uring.c teardown Berkant Koc
2026-05-17 13:43 ` Bernd Schubert
2026-05-17 14:02 ` Berkant Koc
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=3f1567cf-218e-405b-be7f-e9e9c44205d6@bsbernd.com \
--to=bernd@bsbernd.com \
--cc=gregkh@linuxfoundation.org \
--cc=joannelkoong@gmail.com \
--cc=kipreyyy@gmail.com \
--cc=linux-fuse@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=me@berkoc.com \
--cc=miklos@szeredi.hu \
--cc=security@kernel.org \
/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
Powered by JetHome