public inbox for io-uring@vger.kernel.org
 help / color / mirror / Atom feed
From: Qingyue Zhang <chunzhennn@qq.com>
To: axboe@kernel.dk
Cc: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org,
	Qingyue Zhang <chunzhennn@qq.com>,
	Suoxing Zhang <aftern00n@qq.com>
Subject: [PATCH 1/2] io_uring/kbuf: fix signedness in this_len calculation
Date: Wed, 27 Aug 2025 19:43:39 +0800	[thread overview]
Message-ID: <tencent_4DBB3674C0419BEC2C0C525949DA410CA307@qq.com> (raw)

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


             reply	other threads:[~2025-08-27 11:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-27 11:43 Qingyue Zhang [this message]
2025-08-27 14:40 ` [PATCH 1/2] io_uring/kbuf: fix signedness in this_len calculation 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=tencent_4DBB3674C0419BEC2C0C525949DA410CA307@qq.com \
    --to=chunzhennn@qq.com \
    --cc=aftern00n@qq.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