From: David Laight <David.Laight@ACULAB.COM>
To: "'Kees Cook'" <keescook@chromium.org>,
"Horia Geantă" <horia.geanta@nxp.com>
Cc: Pankaj Gupta <pankaj.gupta@nxp.com>,
Gaurav Jain <gaurav.jain@nxp.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
"linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
kernel test robot <lkp@intel.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-hardening@vger.kernel.org"
<linux-hardening@vger.kernel.org>
Subject: RE: [PATCH] crypto/caam: Avoid GCC constprop bug warning
Date: Sat, 29 Oct 2022 11:40:55 +0000 [thread overview]
Message-ID: <560dd92c1f764005b519b038ae82d053@AcuMS.aculab.com> (raw)
In-Reply-To: <20221028210527.never.934-kees@kernel.org>
From: Kees Cook
> Sent: 28 October 2022 22:06
>
> GCC 12 appears to perform constant propagation incompletely(?) and can
> no longer notice that "len" is always 0 when "data" is NULL. Expand the
> check to avoid warnings about memcpy() having a NULL argument:
...
>
> diff --git a/drivers/crypto/caam/desc_constr.h b/drivers/crypto/caam/desc_constr.h
> index 62ce6421bb3f..ddbba8b00ab7 100644
> --- a/drivers/crypto/caam/desc_constr.h
> +++ b/drivers/crypto/caam/desc_constr.h
> @@ -163,7 +163,7 @@ static inline void append_data(u32 * const desc, const void *data, int len)
> {
> u32 *offset = desc_end(desc);
>
> - if (len) /* avoid sparse warning: memcpy with byte count of 0 */
> + if (data && len) /* avoid sparse warning: memcpy with byte count of 0 */
> memcpy(offset, data, len);
I'd guess non-constant zero lengths are unlikely?
So how about:
/* Avoid calling memcpy() when there is never a buffer */
if (!__builtin_constant(len) || len)
memcpy(offset, data, len);
Then the test should never actually end up in the object code.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2022-10-29 11:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-28 21:05 [PATCH] crypto/caam: Avoid GCC constprop bug warning Kees Cook
2022-10-29 11:40 ` David Laight [this message]
2022-11-04 9:03 ` Herbert Xu
2022-12-01 11:52 ` Anders Roxell
2022-12-01 12:10 ` Herbert Xu
2022-12-02 0:59 ` Anders Roxell
2022-12-02 0:58 ` Anders Roxell
2022-12-02 10:01 ` David Laight
2022-12-02 18:58 ` Kees Cook
2022-12-02 22:08 ` David Laight
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=560dd92c1f764005b519b038ae82d053@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=davem@davemloft.net \
--cc=gaurav.jain@nxp.com \
--cc=herbert@gondor.apana.org.au \
--cc=horia.geanta@nxp.com \
--cc=keescook@chromium.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=pankaj.gupta@nxp.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox