[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <tencent_000C02641F6250C856D0C26228DE29A3D30A@qq.com>
Date: Wed, 27 Aug 2025 19:44:53 +0800
From: Qingyue Zhang <chunzhennn@...com>
To: axboe@...nel.dk
Cc: io-uring@...r.kernel.org,
linux-kernel@...r.kernel.org,
Qingyue Zhang <chunzhennn@...com>,
Suoxing Zhang <aftern00n@...com>
Subject: [PATCH 2/2] io_uring/kbuf: fix infinite loop in io_kbuf_inc_commit()
In io_kbuf_inc_commit(), buf points to a user-mapped memory region,
which means buf->len might be changed between importing and committing.
Add a check to avoid infinite loop when sum of buf->len is less than
len.
Co-developed-by: Suoxing Zhang <aftern00n@...com>
Signed-off-by: Suoxing Zhang <aftern00n@...com>
Signed-off-by: Qingyue Zhang <chunzhennn@...com>
---
io_uring/kbuf.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c
index 81a13338dfab..80ffe6755598 100644
--- a/io_uring/kbuf.c
+++ b/io_uring/kbuf.c
@@ -34,11 +34,12 @@ struct io_provide_buf {
static bool io_kbuf_inc_commit(struct io_buffer_list *bl, int len)
{
+ struct io_uring_buf *buf, *buf_start;
+
+ buf_start = buf = io_ring_head_to_buf(bl->buf_ring, bl->head, bl->mask);
while (len) {
- struct io_uring_buf *buf;
u32 this_len;
- buf = io_ring_head_to_buf(bl->buf_ring, bl->head, bl->mask);
this_len = min_t(u32, len, buf->len);
buf->len -= this_len;
if (buf->len) {
@@ -47,6 +48,10 @@ static bool io_kbuf_inc_commit(struct io_buffer_list *bl, int len)
}
bl->head++;
len -= this_len;
+
+ buf = io_ring_head_to_buf(bl->buf_ring, bl->head, bl->mask);
+ if (unlikely(buf == buf_start))
+ break;
}
return true;
}
--
2.48.1
Powered by blists - more mailing lists