summaryrefslogtreecommitdiff
path: root/io_uring
diff options
context:
space:
mode:
authorCaleb Sander Mateos <csander@purestorage.com>2025-12-04 15:43:31 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-12-18 14:03:36 +0100
commit0e777da54152fabd626828356f37505344c0ebb2 (patch)
tree70355c602ec695b833113116baa2db945df563ba /io_uring
parent6a960b58df612dec4ca8a85c53019b2bfb70f061 (diff)
downloadlinux-0e777da54152fabd626828356f37505344c0ebb2.tar.gz
linux-0e777da54152fabd626828356f37505344c0ebb2.tar.bz2
linux-0e777da54152fabd626828356f37505344c0ebb2.zip
io_uring/kbuf: use READ_ONCE() for userspace-mapped memory
[ Upstream commit 78385c7299f7514697d196b3233a91bd5e485591 ] The struct io_uring_buf elements in a buffer ring are in a memory region accessible from userspace. A malicious/buggy userspace program could therefore write to them at any time, so they should be accessed with READ_ONCE() in the kernel. Commit 98b6fa62c84f ("io_uring/kbuf: always use READ_ONCE() to read ring provided buffer lengths") already switched the reads of the len field to READ_ONCE(). Do the same for bid and addr. Signed-off-by: Caleb Sander Mateos <csander@purestorage.com> Fixes: c7fb19428d67 ("io_uring: add support for ring mapped supplied buffers") Cc: Joanne Koong <joannelkoong@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'io_uring')
-rw-r--r--io_uring/kbuf.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c
index a727e020fe03..d974381d93ff 100644
--- a/io_uring/kbuf.c
+++ b/io_uring/kbuf.c
@@ -44,7 +44,7 @@ static bool io_kbuf_inc_commit(struct io_buffer_list *bl, int len)
buf_len -= this_len;
/* Stop looping for invalid buffer length of 0 */
if (buf_len || !this_len) {
- buf->addr += this_len;
+ buf->addr = READ_ONCE(buf->addr) + this_len;
buf->len = buf_len;
return false;
}
@@ -198,9 +198,9 @@ static struct io_br_sel io_ring_buffer_select(struct io_kiocb *req, size_t *len,
if (*len == 0 || *len > buf_len)
*len = buf_len;
req->flags |= REQ_F_BUFFER_RING | REQ_F_BUFFERS_COMMIT;
- req->buf_index = buf->bid;
+ req->buf_index = READ_ONCE(buf->bid);
sel.buf_list = bl;
- sel.addr = u64_to_user_ptr(buf->addr);
+ sel.addr = u64_to_user_ptr(READ_ONCE(buf->addr));
if (io_should_commit(req, issue_flags)) {
io_kbuf_commit(req, sel.buf_list, *len, 1);
@@ -280,7 +280,7 @@ static int io_ring_buffers_peek(struct io_kiocb *req, struct buf_sel_arg *arg,
if (!arg->max_len)
arg->max_len = INT_MAX;
- req->buf_index = buf->bid;
+ req->buf_index = READ_ONCE(buf->bid);
do {
u32 len = READ_ONCE(buf->len);
@@ -295,7 +295,7 @@ static int io_ring_buffers_peek(struct io_kiocb *req, struct buf_sel_arg *arg,
}
}
- iov->iov_base = u64_to_user_ptr(buf->addr);
+ iov->iov_base = u64_to_user_ptr(READ_ONCE(buf->addr));
iov->iov_len = len;
iov++;