public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Jon Maloy <jmaloy@redhat.com>
Cc: sbrivio@redhat.com, passt-dev@passt.top
Subject: Re: [PATCH v2 2/6] udp_vu: Check iov_tail_clone() return before assigning to msg_iovlen
Date: Fri, 10 Jul 2026 11:32:06 +1000	[thread overview]
Message-ID: <alBLkWLvdCVfzxMJ@zatzit> (raw)
In-Reply-To: <20260709215656.1351549-3-jmaloy@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1655 bytes --]

On Thu, Jul 09, 2026 at 05:56:52PM -0400, Jon Maloy wrote:
> iov_tail_clone() returns ssize_t and can return -1 if the destination
> iov array is too small. Its return value was assigned directly to
> msg.msg_iovlen which is size_t, wrapping a negative value to a large
> unsigned number passed to recvmsg().
> 
> Check for failure and return early, letting the caller rewind the
> virtqueue.
> 
> Signed-off-by: Jon Maloy <jmaloy@redhat.com>

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> 
> ---
> v2: Use if-guard instead of assert(), since the error path is
>     a legitimate (if unlikely) condition handled by the caller.
> ---
>  udp_vu.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/udp_vu.c b/udp_vu.c
> index e4fb1057..edd9cae7 100644
> --- a/udp_vu.c
> +++ b/udp_vu.c
> @@ -67,11 +67,15 @@ static ssize_t udp_vu_sock_recv(struct iov_tail *payload, size_t *cnt, int s)
>  	struct iovec msg_iov[VIRTQUEUE_MAX_SIZE];
>  	struct msghdr msg  = { 0 };
>  	size_t iov_used;
> +	ssize_t iovlen;
>  	ssize_t dlen;
>  
> +	iovlen = iov_tail_clone(msg_iov, ARRAY_SIZE(msg_iov), payload);
> +	if (iovlen < 0)
> +		return -1;
> +
>  	msg.msg_iov = msg_iov;
> -	msg.msg_iovlen = iov_tail_clone(msg.msg_iov, ARRAY_SIZE(msg_iov),
> -					payload);
> +	msg.msg_iovlen = iovlen;
>  
>  	/* read data from the socket */
>  	dlen = recvmsg(s, &msg, 0);
> -- 
> 2.52.0
> 

-- 
David Gibson (he or they)	| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you, not the other way
				| around.
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2026-07-10  1:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09 21:56 [PATCH v2 0/6] Fix issues and false positives from static analysis Jon Maloy
2026-07-09 21:56 ` [PATCH v2 1/6] passt: Initialise listening socket fds to -1 Jon Maloy
2026-07-09 21:56 ` [PATCH v2 2/6] udp_vu: Check iov_tail_clone() return before assigning to msg_iovlen Jon Maloy
2026-07-10  1:32   ` David Gibson [this message]
2026-07-09 21:56 ` [PATCH v2 3/6] tap: Guard IPv6 tail size subtraction against underflow Jon Maloy
2026-07-10  1:36   ` David Gibson
2026-07-09 21:56 ` [PATCH v2 4/6] doc/migration: Use snprintf() for socket path and fix argv access Jon Maloy
2026-07-10  1:37   ` David Gibson
2026-07-09 21:56 ` [PATCH v2 5/6] doc/migration: Fix buffer type mismatch in recv() call Jon Maloy
2026-07-09 21:56 ` [PATCH v2 6/6] doc/platform-requirements: Close leaked sockets in test_close_dup() Jon Maloy

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=alBLkWLvdCVfzxMJ@zatzit \
    --to=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).