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] udp: Provide dummy iov in udp_peek_addr() to avoid Coverity warning
Date: Tue, 2 Jun 2026 11:55:23 +1000 [thread overview]
Message-ID: <ah44CxeoQF1UXq7D@zatzit> (raw)
In-Reply-To: <20260531202027.1721248-1-jmaloy@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2552 bytes --]
On Sun, May 31, 2026 at 04:20:27PM -0400, Jon Maloy wrote:
> udp_peek_addr() initialises struct msghdr without setting msg_iov,
> leaving it implicitly NULL. Coverity flags this as FORWARD_NULL,
> believing recvmsg() will dereference the NULL pointer.
>
> In practice, msg_iovlen being zero means the kernel never touches
> msg_iov, so the warning is a false positive. We now provide a
> one-byte dummy iov to make msg_iov non-NULL, hence suppressing this
> warning without changing the function's behaviour.
>
> Signed-off-by: Jon Maloy <jmaloy@redhat.com>
Oof. I mean, yes, it's worth some amount of code ugliness to prevent
Coverity warnings, but this is definitely on the high end of that
ugliness. This doesn't have zero runtime cost, since it requires
extra stack jiggery pokery to set up.
The question is how to do it better without explicit Coverity
suppressions or at least mentioning Coverity in line. This isn't
quite as similar to an existing workaround as I initially thought.
The triggering situation is similar the one handled by #ifdef VALGRIND
in tcp.c + test/valgrind.supp, but that doesn't really help us
Arguably this is a Coverity defect - it should be able to see that
msg_iovlen is statically zero and accept this. So there's some hope
of the error just going away in future. Not sure whether that's
likely, or if we can do anything to expedite it.
Hrm. We don't want to reference Coverity in the code for an explicit
suppression, so I guess using a #if conditional on coverity would have
the same problem. Could we use a conditional but not refer
specifically to which static checker it's working around?
> ---
> udp.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/udp.c b/udp.c
> index c28d6ee2..f648cb8b 100644
> --- a/udp.c
> +++ b/udp.c
> @@ -734,9 +734,16 @@ static int udp_peek_addr(int s, union sockaddr_inany *src,
> {
> char sastr[SOCKADDR_STRLEN], dstr[INANY_ADDRSTRLEN];
> char cmsg[PKTINFO_SPACE];
> + char dummy;
> + struct iovec iov = {
> + .iov_base = &dummy,
> + .iov_len = sizeof(dummy),
> + };
> struct msghdr msg = {
> .msg_name = src,
> .msg_namelen = sizeof(*src),
> + .msg_iov = &iov,
> + .msg_iovlen = 1,
> .msg_control = cmsg,
> .msg_controllen = sizeof(cmsg),
> };
> --
> 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 --]
prev parent reply other threads:[~2026-06-02 1:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-31 20:20 Jon Maloy
2026-06-02 1:55 ` David Gibson [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=ah44CxeoQF1UXq7D@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).