* [PATCH] crypto: caam - Avoid GCC memset bug warning [not found] ` <20221223174719.4n6pmwio4zycj2qm@pengutronix.de> @ 2022-12-28 8:46 ` Herbert Xu 2022-12-28 9:39 ` Uwe Kleine-König 2022-12-28 11:30 ` [PATCH] " Uwe Kleine-König 0 siblings, 2 replies; 6+ messages in thread From: Herbert Xu @ 2022-12-28 8:46 UTC (permalink / raw) To: Uwe Kleine-König Cc: Horia Geantă, Gaurav Jain, Pankaj Gupta, linux-crypto, kernel, David S. Miller, Kees Cook, kernel test robot, Anders Roxell, linux-kernel, linux-hardening Certain versions of gcc don't like the memcpy with a NULL dst (which only happens with a zero length). This only happens when debugging is enabled so add an if clause to work around these warnings. A similar warning used to be generated by sparse but that was fixed years ago. Link: https://lore.kernel.org/lkml/202210290446.qBayTfzl-lkp@intel.com Reported-by: kernel test robot <lkp@intel.com> Reported-by: Kees Cook <keescook@chromium.org> Reported-by: Uwe Kleine-K�nig <u.kleine-koenig@pengutronix.de> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> diff --git a/drivers/crypto/caam/desc_constr.h b/drivers/crypto/caam/desc_constr.h index 62ce6421bb3f..824c94d44f94 100644 --- a/drivers/crypto/caam/desc_constr.h +++ b/drivers/crypto/caam/desc_constr.h @@ -163,7 +163,8 @@ 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 */ + /* Avoid gcc warning: memcpy with data == NULL */ + if (!IS_ENABLED(CONFIG_CRYPTO_DEV_FSL_CAAM_DEBUG) || data) memcpy(offset, data, len); (*desc) = cpu_to_caam32(caam32_to_cpu(*desc) + -- Email: Herbert Xu <herbert@gondor.apana.org.au> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: caam - Avoid GCC memset bug warning 2022-12-28 8:46 ` [PATCH] crypto: caam - Avoid GCC memset bug warning Herbert Xu @ 2022-12-28 9:39 ` Uwe Kleine-König 2022-12-28 11:03 ` [v2 PATCH] " Herbert Xu 2022-12-28 11:30 ` [PATCH] " Uwe Kleine-König 1 sibling, 1 reply; 6+ messages in thread From: Uwe Kleine-König @ 2022-12-28 9:39 UTC (permalink / raw) To: Herbert Xu Cc: Anders Roxell, Kees Cook, Horia Geantă, Gaurav Jain, Pankaj Gupta, linux-kernel, linux-hardening, linux-crypto, kernel, David S. Miller, kernel test robot [-- Attachment #1: Type: text/plain, Size: 960 bytes --] On Wed, Dec 28, 2022 at 04:46:39PM +0800, Herbert Xu wrote: > Certain versions of gcc don't like the memcpy with a NULL dst > (which only happens with a zero length). This only happens > when debugging is enabled so add an if clause to work around > these warnings. > > A similar warning used to be generated by sparse but that was > fixed years ago. > > Link: https://lore.kernel.org/lkml/202210290446.qBayTfzl-lkp@intel.com > Reported-by: kernel test robot <lkp@intel.com> > Reported-by: Kees Cook <keescook@chromium.org> > Reported-by: Uwe Kleine-K�nig <u.kleine-koenig@pengutronix.de> Huh, broken encoding in the mail. I'd appreciate someone to doublecheck it's fine in the final commit. Tested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ | [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* [v2 PATCH] crypto: caam - Avoid GCC memset bug warning 2022-12-28 9:39 ` Uwe Kleine-König @ 2022-12-28 11:03 ` Herbert Xu 0 siblings, 0 replies; 6+ messages in thread From: Herbert Xu @ 2022-12-28 11:03 UTC (permalink / raw) To: Uwe Kleine-König Cc: Anders Roxell, Kees Cook, Horia Geantă, Gaurav Jain, Pankaj Gupta, linux-kernel, linux-hardening, linux-crypto, kernel, David S. Miller, kernel test robot On Wed, Dec 28, 2022 at 10:39:17AM +0100, Uwe Kleine-König wrote: > > Huh, broken encoding in the mail. I'd appreciate someone to doublecheck > it's fine in the final commit. > > Tested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Sorry. Let me try again: ---8<--- Certain versions of gcc don't like the memcpy with a NULL dst (which only happens with a zero length). This only happens when debugging is enabled so add an if clause to work around these warnings. A similar warning used to be generated by sparse but that was fixed years ago. Link: https://lore.kernel.org/lkml/202210290446.qBayTfzl-lkp@intel.com Reported-by: kernel test robot <lkp@intel.com> Reported-by: Kees Cook <keescook@chromium.org> Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Tested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> diff --git a/drivers/crypto/caam/desc_constr.h b/drivers/crypto/caam/desc_constr.h index 62ce6421bb3f..824c94d44f94 100644 --- a/drivers/crypto/caam/desc_constr.h +++ b/drivers/crypto/caam/desc_constr.h @@ -163,7 +163,8 @@ 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 */ + /* Avoid gcc warning: memcpy with data == NULL */ + if (!IS_ENABLED(CONFIG_CRYPTO_DEV_FSL_CAAM_DEBUG) || data) memcpy(offset, data, len); (*desc) = cpu_to_caam32(caam32_to_cpu(*desc) + -- Email: Herbert Xu <herbert@gondor.apana.org.au> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: caam - Avoid GCC memset bug warning 2022-12-28 8:46 ` [PATCH] crypto: caam - Avoid GCC memset bug warning Herbert Xu 2022-12-28 9:39 ` Uwe Kleine-König @ 2022-12-28 11:30 ` Uwe Kleine-König 2022-12-29 1:48 ` Herbert Xu 1 sibling, 1 reply; 6+ messages in thread From: Uwe Kleine-König @ 2022-12-28 11:30 UTC (permalink / raw) To: Herbert Xu Cc: Anders Roxell, Kees Cook, Horia Geantă, Gaurav Jain, Pankaj Gupta, linux-kernel, linux-hardening, linux-crypto, kernel, David S. Miller, kernel test robot [-- Attachment #1: Type: text/plain, Size: 2235 bytes --] On Wed, Dec 28, 2022 at 04:46:39PM +0800, Herbert Xu wrote: > Certain versions of gcc don't like the memcpy with a NULL dst > (which only happens with a zero length). This only happens > when debugging is enabled so add an if clause to work around > these warnings. > > A similar warning used to be generated by sparse but that was > fixed years ago. > > Link: https://lore.kernel.org/lkml/202210290446.qBayTfzl-lkp@intel.com > Reported-by: kernel test robot <lkp@intel.com> > Reported-by: Kees Cook <keescook@chromium.org> > Reported-by: Uwe Kleine-K�nig <u.kleine-koenig@pengutronix.de> > Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> > > diff --git a/drivers/crypto/caam/desc_constr.h b/drivers/crypto/caam/desc_constr.h > index 62ce6421bb3f..824c94d44f94 100644 > --- a/drivers/crypto/caam/desc_constr.h > +++ b/drivers/crypto/caam/desc_constr.h > @@ -163,7 +163,8 @@ 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 */ > + /* Avoid gcc warning: memcpy with data == NULL */ > + if (!IS_ENABLED(CONFIG_CRYPTO_DEV_FSL_CAAM_DEBUG) || data) I just tried: For me a plain if (data) is also enough to make both gcc and sparse happy. (On a related note, sparse reports: CHECK drivers/crypto/caam/jr.c drivers/crypto/caam/jr.c: note: in included file (through arch/arm64/include/asm/io.h, include/linux/io.h, include/linux/irq.h, ...): include/asm-generic/io.h:290:22: warning: incorrect type in argument 1 (different base types) include/asm-generic/io.h:290:22: expected unsigned long long [usertype] val include/asm-generic/io.h:290:22: got restricted __le64 [usertype] include/asm-generic/io.h:290:22: warning: incorrect type in argument 1 (different base types) include/asm-generic/io.h:290:22: expected unsigned long long [usertype] val include/asm-generic/io.h:290:22: got restricted __le64 [usertype] Didn't look into that though.) Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ | [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] crypto: caam - Avoid GCC memset bug warning 2022-12-28 11:30 ` [PATCH] " Uwe Kleine-König @ 2022-12-29 1:48 ` Herbert Xu 2022-12-31 16:44 ` David Laight 0 siblings, 1 reply; 6+ messages in thread From: Herbert Xu @ 2022-12-29 1:48 UTC (permalink / raw) To: Uwe Kleine-König Cc: Anders Roxell, Kees Cook, Horia Geantă, Gaurav Jain, Pankaj Gupta, linux-kernel, linux-hardening, linux-crypto, kernel, David S. Miller, kernel test robot On Wed, Dec 28, 2022 at 12:30:35PM +0100, Uwe Kleine-König wrote: > > > - if (len) /* avoid sparse warning: memcpy with byte count of 0 */ > > + /* Avoid gcc warning: memcpy with data == NULL */ > > + if (!IS_ENABLED(CONFIG_CRYPTO_DEV_FSL_CAAM_DEBUG) || data) > > I just tried: For me a plain > > if (data) > > is also enough to make both gcc and sparse happy. Of course it is. The point of the extra condition is to remove the unnecessary check on data unless we are in debugging mode (as it is only needed in debugging mode to work around the buggy compiler). > (On a related note, sparse reports: > > CHECK drivers/crypto/caam/jr.c > drivers/crypto/caam/jr.c: note: in included file (through arch/arm64/include/asm/io.h, include/linux/io.h, include/linux/irq.h, ...): > include/asm-generic/io.h:290:22: warning: incorrect type in argument 1 (different base types) > include/asm-generic/io.h:290:22: expected unsigned long long [usertype] val > include/asm-generic/io.h:290:22: got restricted __le64 [usertype] > include/asm-generic/io.h:290:22: warning: incorrect type in argument 1 (different base types) > include/asm-generic/io.h:290:22: expected unsigned long long [usertype] val > include/asm-generic/io.h:290:22: got restricted __le64 [usertype] That's a bug in include/asm-generic/io.h. It feeds an __le64 to __raw_writeq which wants a u64. Cheers, -- Email: Herbert Xu <herbert@gondor.apana.org.au> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt ^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH] crypto: caam - Avoid GCC memset bug warning 2022-12-29 1:48 ` Herbert Xu @ 2022-12-31 16:44 ` David Laight 0 siblings, 0 replies; 6+ messages in thread From: David Laight @ 2022-12-31 16:44 UTC (permalink / raw) To: 'Herbert Xu', Uwe Kleine-König Cc: Anders Roxell, Kees Cook, Horia Geantă, Gaurav Jain, Pankaj Gupta, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, linux-crypto@vger.kernel.org, kernel@pengutronix.de, David S. Miller, kernel test robot From: Herbert Xu > Sent: 29 December 2022 01:49 > > On Wed, Dec 28, 2022 at 12:30:35PM +0100, Uwe Kleine-König wrote: > > > > > - if (len) /* avoid sparse warning: memcpy with byte count of 0 */ > > > + /* Avoid gcc warning: memcpy with data == NULL */ > > > + if (!IS_ENABLED(CONFIG_CRYPTO_DEV_FSL_CAAM_DEBUG) || data) > > > > I just tried: For me a plain > > > > if (data) > > > > is also enough to make both gcc and sparse happy. > > Of course it is. The point of the extra condition is to remove > the unnecessary check on data unless we are in debugging mode > (as it is only needed in debugging mode to work around the buggy > compiler). IIRC the 'problematic' case is one where 'len' and 'data' are actually compile-time zeros - in which case you don't want to call memcpy() at all. In all other cases I think there is something to copy so you don't really want the check (or the one in memcpy() will do). Whether (builtin_constant_p(data) && !data) is good enough is another matter. It might need the (sizeof *(1 ? (void *)(data) : (int *)0) == 1) test. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-12-31 16:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20221222162513.4021928-1-u.kleine-koenig@pengutronix.de>
[not found] ` <Y6VK4IJkHiawAbJz@gondor.apana.org.au>
[not found] ` <20221223174719.4n6pmwio4zycj2qm@pengutronix.de>
2022-12-28 8:46 ` [PATCH] crypto: caam - Avoid GCC memset bug warning Herbert Xu
2022-12-28 9:39 ` Uwe Kleine-König
2022-12-28 11:03 ` [v2 PATCH] " Herbert Xu
2022-12-28 11:30 ` [PATCH] " Uwe Kleine-König
2022-12-29 1:48 ` Herbert Xu
2022-12-31 16:44 ` David Laight
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox