From: Bernd Schubert <bschubert@ddn.com>
To: Berkant Koc <me@berkoc.com>, Greg KH <gregkh@linuxfoundation.org>,
Miklos Szeredi <miklos@szeredi.hu>
Cc: "security@kernel.org" <security@kernel.org>,
Joanne Koong <joannelkoong@gmail.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"io-uring@vger.kernel.org" <io-uring@vger.kernel.org>,
Jens Axboe <axboe@kernel.dk>,
Pavel Begunkov <asml.silence@gmail.com>,
fuse-devel <fuse-devel@lists.linux.dev>
Subject: Re: [PATCH 2/2] fuse: wait for aborted connection before releasing last fuse_dev
Date: Mon, 18 May 2026 11:47:08 +0000 [thread overview]
Message-ID: <2889c98c-21e8-47eb-903a-ea40bf5c8c04@ddn.com> (raw)
In-Reply-To: <fb437530-94f1-4f06-98d9-a252e4ff1315@ddn.com>
[-- Attachment #1: Type: text/plain, Size: 2480 bytes --]
On 5/18/26 11:55, Bernd Schubert wrote:
> On 5/18/26 03:13, Berkant Koc wrote:
>> [You don't often get email from me@berkoc.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>>
>> Bernd, thanks for pushing back. Stepping through this against the trace:
>>
>> fuse_conn_destroy() in fs/fuse/inode.c calls fuse_wait_aborted()
>> between fuse_abort_conn() and the eventual fuse_conn_put() (from
>> fuse_sb_destroy). fuse_dev_release() in fs/fuse/dev.c does not wait
>> between its fuse_abort_conn() and fuse_conn_put(). That asymmetry is
>> the race.
>>
>> On topologies where the last fud release IS the last conn ref
>> (no superblock mount, no other fud open — exactly the PoC setup),
>> fuse_conn_put() drops the count to zero, call_rcu schedules
>> delayed_release, and fuse_uring_destruct kfrees ring/queue/ent_released
>> slabs. async_teardown_work, scheduled by fuse_uring_async_stop_queues
>> via the teardown-interval delayed_work, then runs on freed memory.
>>
>> The KASAN trace at top-finding/kasan-trace.txt shows exactly that
>> interleaving:
>>
>> free site: fuse_uring_destruct ← delayed_release ← rcu_core
>> use site: fuse_uring_teardown_all_queues ← async_teardown_work
>> (workqueue), reading ent->list.next from
>> kmalloc-192 freed by destruct
>>
>> Your in-flight cmd ref invariant holds on both fixed and non-fixed
>> paths (non-fixed via per-cmd io_put_file in io_free_batch_list, fixed
>> via the io_uring file table slot pinning struct file → fud → fuse_conn).
>> But neither covers the gap between fuse_abort_conn (which schedules
>> the async work and returns immediately) and the RCU callback. The
>> PoC topology removes every other ref-holder, so that gap becomes the
>> last conn ref.
>>
>> The patch restores symmetry with fuse_conn_destroy by waiting on
>> ring->queue_refs == 0 (via fuse_wait_aborted → fuse_uring_wait_stopped_queues)
>> before the put. That guarantees async_teardown_work has finished
>> before RCU is armed.
>>
>> The race is reproducible with mdelay-widening; without widening I see
>> 0 trips in 50 iter, but the window is in the code paths.
>
> I think I see what the actual issue is, we need an fc (or in linux-next
> struct fuse_chan) reference as long as fuse_uring_async_stop_queues()
> runs. Patch follows.
>
Would it be possible for you to test the attached patch?
Thanks,
Bernd
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: fuse_uring_async_stop_queues.patch --]
[-- Type: text/x-patch; name="fuse_uring_async_stop_queues.patch", Size: 1561 bytes --]
commit b6f63cc1d2f7b8d690835c965d600fda47ffd79b
Author: Bernd Schubert <bernd@bsbernd.com>
Date: Mon May 18 13:30:30 2026 +0200
fuse: Avoid use-after-free in fuse_uring_async_stop_queues
fuse_uring_async_stop_queues() might run when the last reference
on ring->queue_refs was already dropped.
In order to avoid an early destruction a reference on struct fuse_conn
is now taken before starting fuse_uring_async_stop_queues() and that
reference is only released when that delayed work queue terminates.
Fixes: 4a9bfb9b6850 ("fuse: {io-uring} Handle teardown of ring entries")
Cc: stable@kernel.org # 6.14
Reported-by: Berkant Koc <me@berkoc.com>
Signed-off-by: Bernd Schubert <bernd@bsbernd.com>
diff --git a/fs/fuse/dev_uring.c b/fs/fuse/dev_uring.c
index e467b23e6895..c96d72250830 100644
--- a/fs/fuse/dev_uring.c
+++ b/fs/fuse/dev_uring.c
@@ -465,7 +465,10 @@ static void fuse_uring_async_stop_queues(struct work_struct *work)
schedule_delayed_work(&ring->async_teardown_work,
FUSE_URING_TEARDOWN_INTERVAL);
} else {
+ struct fuse_chan *chan = ring->chan;
+
wake_up_all(&ring->stop_waitq);
+ fuse_conn_put(chan->conn);
}
}
@@ -477,6 +480,9 @@ void fuse_uring_stop_queues(struct fuse_ring *ring)
fuse_uring_teardown_all_queues(ring);
if (atomic_read(&ring->queue_refs) > 0) {
+ struct fuse_chan *chan = ring->chan;
+
+ fuse_conn_get(chan->conn);
ring->teardown_time = jiffies;
INIT_DELAYED_WORK(&ring->async_teardown_work,
fuse_uring_async_stop_queues);
next prev parent reply other threads:[~2026-05-18 11:47 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
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 [this message]
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=2889c98c-21e8-47eb-903a-ea40bf5c8c04@ddn.com \
--to=bschubert@ddn.com \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=fuse-devel@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=io-uring@vger.kernel.org \
--cc=joannelkoong@gmail.com \
--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
all inboxes | Powered by JetHome®