From: Aayush7352 <aayushdixit924@gmail.com>
To: io-uring@vger.kernel.org
Cc: Jens Axboe <axboe@kernel.dk>,
linux-kernel@vger.kernel.org,
Aayush7352 <aayushdixit924@gmail.com>
Subject: [PATCH] io_uring/kbuf: fix UAF in buffer selection when access_ok fails on expanded iovec
Date: Tue, 21 Jul 2026 14:17:52 +0530 [thread overview]
Message-ID: <20260721084752.79346-1-aayushdixit924@gmail.com> (raw)
In io_ring_buffers_peek(), when the buffer ring is expanded
(KBUF_MODE_EXPAND), arg->iovs is set to a newly kmalloced array.
If access_ok() then fails on a buffer entry, the error path kfrees
the new array but does not restore arg->iovs to the original value
(org_iovs). arg->iovs is left dangling and will be reused on retry,
causing a use-after-free when the caller retries the buffer selection.
Fix by restoring arg->iovs = org_iovs after the kfree on the error
path, so the caller's state remains coherent on retry.
Fixes: b3e0216c97e3 ("io_uring: add buffer ring support")
Cc: io-uring@vger.kernel.org
Signed-off-by: Aayush7352 <aayushdixit924@gmail.com>
---
io_uring/kbuf.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c
index de0129bce..eab4de8a7 100644
--- a/io_uring/kbuf.c
+++ b/io_uring/kbuf.c
@@ -314,8 +314,10 @@ static int io_ring_buffers_peek(struct io_kiocb *req, struct buf_sel_arg *arg,
iov->iov_base = u64_to_user_ptr(READ_ONCE(buf->addr));
iov->iov_len = len;
if (unlikely(!access_ok(iov->iov_base, len))) {
- if (arg->iovs != org_iovs)
+ if (arg->iovs != org_iovs) {
kfree(arg->iovs);
+ arg->iovs = org_iovs;
+ }
return -EFAULT;
}
iov++;
--
2.55.0
next reply other threads:[~2026-07-21 8:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-21 8:47 Aayush7352 [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-07-21 9:57 [PATCH] io_uring/kbuf: fix UAF in buffer selection when access_ok fails on expanded iovec Aayush7352
2026-07-21 14:54 ` Jens Axboe
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=20260721084752.79346-1-aayushdixit924@gmail.com \
--to=aayushdixit924@gmail.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=linux-kernel@vger.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