io_uring/kbuf: fix signedness in this_len calculation

When importing and using buffers, buf->len is considered unsigned.
However, buf->len is converted to signed int when committing. This can
lead to unexpected behavior if the buffer is large enough to be
interpreted as a negative value. Make min_t calculation unsigned.

Fixes: ae98dbf43d ("io_uring/kbuf: add support for incremental buffer consumption")
Co-developed-by: Suoxing Zhang <aftern00n@qq.com>
Signed-off-by: Suoxing Zhang <aftern00n@qq.com>
Signed-off-by: Qingyue Zhang <chunzhennn@qq.com>
Link: https://lore.kernel.org/r/tencent_4DBB3674C0419BEC2C0C525949DA410CA307@qq.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
pull/1334/head
Qingyue Zhang 2025-08-27 19:43:39 +08:00 committed by Jens Axboe
parent e4e6aaea46
commit c64eff368a
1 changed files with 1 additions and 1 deletions

View File

@ -39,7 +39,7 @@ static bool io_kbuf_inc_commit(struct io_buffer_list *bl, int len)
u32 this_len;
buf = io_ring_head_to_buf(bl->buf_ring, bl->head, bl->mask);
this_len = min_t(int, len, buf->len);
this_len = min_t(u32, len, buf->len);
buf->len -= this_len;
if (buf->len) {
buf->addr += this_len;