public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Charles <srijaan@proton.me>, Greg KH <gregkh@linuxfoundation.org>
Cc: "io-uring@vger.kernel.org" <io-uring@vger.kernel.org>
Subject: Re: [BUG + PATCH] io_uring/rsrc: Page-level UAF via IORING_REGISTER_CLONE_BUFFERS on IO_REGBUF_F_KBUF buffers (+ vringh slow_copy OOB)
Date: Sun, 22 Nov 2026 11:55:51 -0700	[thread overview]
Message-ID: <df3337e1-58f6-4a5f-82e5-d9f4fc1ff7c8@kernel.dk> (raw)
In-Reply-To: <EId43tY1y-P05sLvdH6roKq8lEP4Vi7UgmXvVUKIHkGCv3zAD2wMqLoJcTiFMGU0txHfJiAj3Ra1MQ6n8VddmgBZ7FYPwsoWQubLzKIOg1w=@proton.me>

On 11/22/26 6:30 AM, Charles wrote:
> Hi Greg,
> 
>     My apologies for the oversight on maintainer routing and the incomplete DCO identity.
> 
>     My full legal name is Srijan Mandal, and the updated Signed-off-by line for this patch series is:
>     Signed-off-by: Srijan Mandal <srijan@proton.me>
> 
>     I have CC'd Jens Axboe and the io-uring mailing list on this thread for the io_uring/rsrc patch.
> 
>     Below is the standalone io_uring fix with the corrected DCO. The second patch (vringh/vhost bounds check) is an independent issue in drivers/vhost; if preferred, I can break that out into a separate thread directed to Michael S. Tsirkin and virtualization@lists.linux.dev to keep subsystem threads clean.
> 
>     ---
>     From: Srijan Mandal <srijan@proton.me>
>     Subject: [PATCH] io_uring/rsrc: reject IO_REGBUF_F_KBUF buffers in io_clone_buffers()
> 
>     Kernel-registered request buffers initialized via io_kernel_buffer_init()
>     carry the IO_REGBUF_F_KBUF flag and borrow struct page pointers tied to
>     the lifetime of an in-flight kernel request (such as ublk zero-copy I/O).
>     When the request finishes, io_buffer_unregister() removes the buffer from
>     the owning ring and decrements imu->refs.
> 
>     Currently, io_clone_buffers() (IORING_REGISTER_CLONE_BUFFERS) does not
>     reject IO_REGBUF_F_KBUF buffers. If user space clones an active
>     IO_REGBUF_F_KBUF buffer into a second io_ring_ctx, imu->refs is
>     incremented to 2. When io_buffer_unregister() subsequently runs on the
>     source ring, refcount_dec_and_test(&imu->refs) drops the refcount from
>     2 to 1, skips imu->release(), and returns 0 while the destination ring
>     retains arbitrary read/write fixed-buffer access to the freed bio pages.
> 
>     Explicitly reject IO_REGBUF_F_KBUF in io_clone_buffers() with -EOPNOTSUPP.
> 
>     Fixes: 7cc2a6eadcd7 ("io_uring/rsrc: support cloning registered buffers")
>     Signed-off-by: Srijan Mandal <srijan@proton.me>
>     ---
>      io_uring/rsrc.c | 4 ++++
>      1 file changed, 4 insertions(+)
> 
>     diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
>     index 1a2b3c4d5e6f..6f5e4d3c2b1a 100644
>     --- a/io_uring/rsrc.c
>     +++ b/io_uring/rsrc.c
>     @@ -1521,6 +1521,10 @@ int io_clone_buffers(struct io_ring_ctx *ctx, void __user *argp)
>              if (!src_node) {
>                  dst_node = NULL;
>              } else {
>     +            if (src_node->buf->flags & IO_REGBUF_F_KBUF) {
>     +                io_rsrc_data_free(ctx, &data);
>     +                return -EOPNOTSUPP;
>     +            }
>                  /* we don't allow IOPOLL rw with dma-buf for now */
>                  if ((src_node->buf->flags & IO_REGBUF_F_DMABUF) &&
>                      (ctx->flags & IORING_SETUP_IOPOLL)) {
>     --
>     2.47.0


I looked at this, and ran it. The commit message is wrong, the
patch isn't usable as posted, but there is a bug there.

However, it's not a use-after-free. imu->release() isn't what frees the
pages, it's what drops the ublk request referenced. With a clone holding
imu->refs the release is deferred, the request isn't completed, and the
pages stay pinned. If you have a KASAN splat or a reproducer showing
stale access, send it. If not, I'm assuming this is just LLM
hallucinations with zero extra thought or testing being done by the
reporter.

What does happen: clone a KBUF buffer, and the request never
completes. In my test the partition scan read hangs holding the
disk open_mutex, and killing the ublk server leaves it spinning in
io_uring_cancel_generic() at 100% CPU, as it also holds the dst
ring. That is a bug of course, but not a UAF. And since setting up a
ublk instance is a privileged operation, not anything particularly
exciting. Still wants fixing, of course.

Other things:

- Fixes tag is wrong. 7cc2a6eadcd7 is the original clone commit and
  its subject isn't what you quoted. KBUF came with 27cb27b6d5ea.
- The patch doesn't apply: io_clone_buffers() is static and has a
  different signature, the index line is bogus and the whitespace
  is mangled. In other words, this too looks LLM hallucinated and you
  didn't bother to do any checking or work on your own.
- From is srijaan@proton.me, Signed-off-by is srijan@proton.me.
  That's still wrong, they must be the same.

IOW, lots of things for you to fix, please do so and send a v2.

-- 
Jens Axboe

      reply	other threads:[~2026-11-22 18:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <YM-SVvJpDZxNYESMMdnz-t8A2OWKzXnPtdbgqEfG0GVzAHaD9vN5nID1N35dyZGga5yc8LUdNHh_kNJmq5IxnSMeJhpa07ZNGKjwbW0JfvY=@proton.me>
     [not found] ` <2026112255-mooned-scotch-45b8@gregkh>
     [not found]   ` <UAv5iL7TzydEOne6fkMoGjDD9QKLzmvtx6AA13trfoiYHFUvolV_EYYMFyswW641KRNlMGcv1WxmMklsV0MSADeGmREnZjLQsHte1vDdQCk=@proton.me>
     [not found]     ` <2026112210-most-ripple-f0f2@gregkh>
     [not found]       ` <_fCYwLrqH3eCrdhdnhG_jWbqQCM98WLDAPjSUDvybghN1Zt9rVJY4Qq-sdJ3Gv-nwZ7E38Cp4GAfE6SQkqHEdIyi3IWrU6ulDban0e6JPqM=@proton.me>
2026-11-22 13:30         ` [BUG + PATCH] io_uring/rsrc: Page-level UAF via IORING_REGISTER_CLONE_BUFFERS on IO_REGBUF_F_KBUF buffers (+ vringh slow_copy OOB) Charles
2026-11-22 18:55           ` Jens Axboe [this message]

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=df3337e1-58f6-4a5f-82e5-d9f4fc1ff7c8@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=gregkh@linuxfoundation.org \
    --cc=io-uring@vger.kernel.org \
    --cc=srijaan@proton.me \
    /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