public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Laurent Vivier <lvivier@redhat.com>
To: Stefano Brivio <sbrivio@redhat.com>, Jon Maloy <jmaloy@redhat.com>
Cc: david@gibson.dropbear.id.au, passt-dev@passt.top, contact@jbartunek.de
Subject: Re: [PATCH] tcp_vu: Fix assert/error-check order in tcp_vu_sock_recv()
Date: Tue, 10 Nov 2026 10:47:31 +0100	[thread overview]
Message-ID: <d1dd7d87-6731-4723-b1c1-9a7c70d3fc4b@redhat.com> (raw)
In-Reply-To: <20261110102925.1fbb87ff@elisabeth>

On 11/10/26 10:29, Stefano Brivio wrote:
> [Cc: Johannes, Laurent]
> 
> Thanks for the patch and the explanation, but shouldn't this be:
> 
> On Mon,  9 Nov 2026 17:13:42 -0500
> Jon Maloy <jmaloy@redhat.com> wrote:
> 
> From: Johannes Bartunek <contact@jbartunek.de>
> 
> and:
> 
>> iov_tail_clone() returns a ssize_t. However, the assert comparing
>> it against (ARRAY_SIZE(iov_msg) - j), which yields size_t, comes
>> before the negative-value check. Hence, when iov_tail_clone() fails
>> and returns -1, the signed-to-unsigned promotion turns -1 into
>> SIZE_MAX, and causes the assert to fire.
>>
>> We fix this by moving the error check before the assert, while casting
>> the counter and the index inside the assert to size_t.
> 
> Reported-by: Johannes Bartunek <contact@jbartunek.de>
> Suggested-by: Laurent Vivier <lvivier@redhat.com>

Not exactly...

> 
> ?
> 
>> Signed-off-by: Jon Maloy <jmaloy@redhat.com>
>> ---
>>   tcp_vu.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tcp_vu.c b/tcp_vu.c
>> index 868a35b9..c052d8e2 100644
>> --- a/tcp_vu.c
>> +++ b/tcp_vu.c
>> @@ -291,9 +291,9 @@ static ssize_t tcp_vu_sock_recv(const struct ctx *c, struct vu_virtq *vq,
>>   
>>   		cnt = iov_tail_clone(&iov_msg[j], ARRAY_SIZE(iov_msg) - j,
>>   				     &data);
>> -		assert(cnt < ARRAY_SIZE(iov_msg) - j);
>>   		if (cnt < 0)
>>   			die("Missing entries in iov_msg");
>> +		assert((size_t)cnt < ARRAY_SIZE(iov_msg) - (size_t)j);

The real fix is:

assert((size_t)cnt <= ARRAY_SIZE(iov_msg) - (size_t)j);

>>   
>>   		j += cnt;
>>   	}
> 

Thanks,
Laurent


      reply	other threads:[~2026-11-10  9:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 22:13 Jon Maloy
2026-11-10  9:29 ` Stefano Brivio
2026-11-10  9:47   ` Laurent Vivier [this message]

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=d1dd7d87-6731-4723-b1c1-9a7c70d3fc4b@redhat.com \
    --to=lvivier@redhat.com \
    --cc=contact@jbartunek.de \
    --cc=david@gibson.dropbear.id.au \
    --cc=jmaloy@redhat.com \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).