public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] io_uring/kbuf: fix signedness in this_len calculation
@ 2025-08-27 11:43 Qingyue Zhang
  2025-08-27 14:40 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Qingyue Zhang @ 2025-08-27 11:43 UTC (permalink / raw)
  To: axboe; +Cc: io-uring, linux-kernel, Qingyue Zhang, Suoxing Zhang

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 buffer is large enough to be
interpreted as a negative value. Make min_t calculation unsigned.

Co-developed-by: Suoxing Zhang <aftern00n@qq.com>
Signed-off-by: Suoxing Zhang <aftern00n@qq.com>
Signed-off-by: Qingyue Zhang <chunzhennn@qq.com>
---
 io_uring/kbuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c
index f2d2cc319faa..81a13338dfab 100644
--- a/io_uring/kbuf.c
+++ b/io_uring/kbuf.c
@@ -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;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/2] io_uring/kbuf: fix signedness in this_len calculation
  2025-08-27 11:43 [PATCH 1/2] io_uring/kbuf: fix signedness in this_len calculation Qingyue Zhang
@ 2025-08-27 14:40 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2025-08-27 14:40 UTC (permalink / raw)
  To: Qingyue Zhang; +Cc: io-uring, linux-kernel, Suoxing Zhang


On Wed, 27 Aug 2025 19:43:39 +0800, Qingyue Zhang wrote:
> 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 buffer is large enough to be
> interpreted as a negative value. Make min_t calculation unsigned.
> 
> 

Applied, thanks!

[1/2] io_uring/kbuf: fix signedness in this_len calculation
      commit: c64eff368ac676e8540344d27a3de47e0ad90d21

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-08-27 14:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-27 11:43 [PATCH 1/2] io_uring/kbuf: fix signedness in this_len calculation Qingyue Zhang
2025-08-27 14:40 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox