From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 9F6475A026D for ; Wed, 15 Nov 2023 09:11:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1700035884; bh=TifUxXNrk+FhDcryWFIsN4qjj77VVvt9w7lx4tZYQSc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gXbNYXY7rnY0k3P92EzOlwvJyix11eXfRtXR8NMqzEtrEi7zfysGXgjujpQWa6vXO r7qQH4Lzq0F0hAFS3Sohxgv5KCX2cbUeVOsXityJuOB37m5ApbH/iQgMCuvGluygoO 77Drh3xl+aN0AMR9p8KwKAQULi1XyV+8Krlkl5uA= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4SVbTm40zPz4xSn; Wed, 15 Nov 2023 19:11:24 +1100 (AEDT) Date: Wed, 15 Nov 2023 19:11:19 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH] cppcheck,valgrind: Don't pass NULL to recv() with MSG_TRUNC Message-ID: References: <20231115044124.1496698-1-david@gibson.dropbear.id.au> <20231115063259.2c7bc5b0@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="7/SjbNO9qQbdzBjF" Content-Disposition: inline In-Reply-To: <20231115063259.2c7bc5b0@elisabeth> Message-ID-Hash: QFUHAKIK5XRHMM3EUKCUPXSUAL52LE2S X-Message-ID-Hash: QFUHAKIK5XRHMM3EUKCUPXSUAL52LE2S X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --7/SjbNO9qQbdzBjF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Nov 15, 2023 at 06:32:59AM +0100, Stefano Brivio wrote: > On Wed, 15 Nov 2023 15:41:24 +1100 > David Gibson wrote: >=20 > > Usually, of course, it's invalid to pass a NULL buffer to recv(). Howe= ver, > > it's acceptable when using MSG_TRUNC, because that suppresses actually > > writing to the buffer. So, we pass NULL in tcp_sock_consume(). > >=20 > > Unfortunately, checker tools aren't always aware of that special case: = we > > already have a suppression for cppcheck to cover this. valgrind-3.22.0 > > (present in Fedora 39) has a similar problem, generating a spurious war= ning > > here. >=20 > I haven't tried valgrind 3.22 yet, but... do you happen to know why > test/valgrind.supp doesn't cover this anymore? Huh.. I hadn't spotted there was an existing suppression. I don't know why that's not working any more, I can have a closer look. > > We could generate another suppression for valgrind, however, it so happ= ens > > that we already have tcp_buf_discard ready to hand. If we pass this > > instead of NULL it makes both cppcheck and valgrind happy. We're still > > using the MSG_TRUNC flag, the kernel doesn't actually have to copy data, > > so we should still have the performance benefits of it. >=20 > I'm not enthusiastic about this, because using tcp_buf_discard there > might tell an optimising compiler that it's useful to prefetch it. >=20 > We would also pass the actual address of tcp_buf_discard to the kernel, > and I'm not sure if this has further subtle implications on possible > optimisations in the kernel implementation (even though as you said no > data is actually copied). Ok, fair points. I'll revisit this. --=20 David Gibson | 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 --7/SjbNO9qQbdzBjF Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmVUfR4ACgkQzQJF27ox 2GenbQ/+MT6yX3CxnTDDGLL5RuLq8piTdUivYRNRj/y+jyJf/kfEzI86i7ulvVzQ oQEfg48GeL5cRJyJdO9AyOf+pNiibzEKsCWj5LVjAEouXGGC/lDUdexIKbAsy8oS dYOI/IqwCZH44Y55V5S3yNDlHs9lNjWXSh2tLlpqgoPXzF5A74kTrzgazLD4sgBs dMtoDFn0ZqbYMr7HMcCeCKqffFZrxC1m5DubvHdl9RT7w/KqcxHGlcSqGjoSADDd 1G7g6U5a5cqSX+KtLdr135xJ9idPtdqgSwzO0ezohZmUdjrs4i4HMThVVqM2GCWI sWBSOUoiKMP2HtrrZfU57sWSY/DMKQpfJV2sDNhfLD1LmGMUmR6MIyTg9grTpAC8 LEMmOubWX9S6Y7pF3i2V6Zk4wNJhWBVlkpWj/mk/3i7sPElxIPJptfyXjxBc0Jz9 0XoCwQl7+ul7P28J5KCHmcN5YzisEPFHe0hx6HWKFVHlFj//S0TXLvHs8uTdCOhu nWoQ+K/KQCijbDCidr5nQv/cCtPf+JwV8Kchv5rDe1AJWPpqtkZUtg+j9o+VihJz xHgv0oxfvmQHjQz1/7m5m7YA/R/MTDBhS3pVhWZIwI+W3E9v11t8wng0XRAowEBJ AUZSW23bsPhzJndzKuGh0wLHms5f0Av8dRNNO7b2FZvvA21F0zM= =du8x -----END PGP SIGNATURE----- --7/SjbNO9qQbdzBjF--