From: Gabriel Krisman Bertazi <krisman@suse.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: io-uring@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 2/2] io_uring/net: don't overconsume buffers when using MSG_TRUNC
Date: Thu, 10 Sep 2026 13:08:15 -0300 [thread overview]
Message-ID: <87a4pp2iog.fsf@mailhost.krisman.be> (raw)
In-Reply-To: <0f5e8693-dcba-4fa8-87d1-570ac08e2d83@kernel.dk>
Jens Axboe <axboe@kernel.dk> writes:
>> When a recv/recvmsg is issued with MSG_TRUNC and the incoming packet is
>> larger than the provided buffer, the net layer returns the full length
>> of the packet rather than the number of bytes actually copied into the
>> buffer. As a result, io_uring advances more of the provided buffer ring
>> than was actually filled. Use the actual filled region size to consume
>> the buffer, but still return the full size to preserve MSG_TRUNC
>> semantics.
>>
>> Take care with multishot, because that seems to already truncate the
>> consumption based on the available payload size.
>>
>> This was reported in https://github.com/axboe/liburing/issues/1619.
>>
>> Fixes: ae98dbf43d75 ("io_uring/kbuf: add support for incremental buffer consumption")
>> Cc: stable@vger.kernel.org
>> Link: https://patch.msgid.link/20260728191454.1850326-1-krisman@suse.de
>> Signed-off-by: Gabriel Krisman Bertazi <krisman@suse.de>
>> ---
>> io_uring/net.c | 38 +++++++++++++++++++++++++++++++-------
>> 1 file changed, 31 insertions(+), 7 deletions(-)
>>
>> diff --git a/io_uring/net.c b/io_uring/net.c
>> index 647156c9331a..f8110dc9f860 100644
>> --- a/io_uring/net.c
>> +++ b/io_uring/net.c
>> @@ -853,7 +853,7 @@ int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
>> static inline bool io_recv_finish(struct io_kiocb *req,
>> struct io_async_msghdr *kmsg,
>> struct io_br_sel *sel, bool mshot_finished,
>> - unsigned issue_flags)
>> + unsigned issue_flags, size_t consumed)
>> {
>
> Not sure this is correct. If consumed is a size_t, then the comparison
> between ret > len is an unsigned comparison, and every error will then
> get clamped?
>
> Will need something like this folded in.
Indeed. thanks for catching it.
I'm folding your fix up in the v3, modulo a compilation error. It only
changes the error path, the bug is still fixed on 7.3 with your patch
folded in. Any suggestions on how to test this error path for liburing?
I got a test for the bug, but testing ret<0 means failing the socket.
--
Gabriel Krisman Bertazi
next prev parent reply other threads:[~2026-09-10 16:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 23:00 [PATCH 0/2] Fix return with MSG_TUNC overtruncating buffers Gabriel Krisman Bertazi
2026-09-02 23:00 ` [PATCH 1/2] io_uring/net: let io_recv_buf_select return the length of the buffer region Gabriel Krisman Bertazi
2026-09-02 23:00 ` [PATCH 2/2] io_uring/net: don't overconsume buffers when using MSG_TRUNC Gabriel Krisman Bertazi
2026-09-09 13:56 ` Jens Axboe
2026-09-09 13:58 ` Jens Axboe
2026-09-10 16:08 ` Gabriel Krisman Bertazi [this message]
2026-09-10 16:11 ` Gabriel Krisman Bertazi
2026-09-10 20:42 ` Jens Axboe
2026-09-10 15:18 ` [PATCH 0/2] Fix return with MSG_TUNC overtruncating buffers 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=87a4pp2iog.fsf@mailhost.krisman.be \
--to=krisman@suse.de \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=stable@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