lkml.org 
[lkml]   [2022]   [Oct]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [PATCH] crypto/caam: Avoid GCC constprop bug warning
Date
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)
\
 
 \ /
  Last update: 2022-10-29 13:42    [W:0.407 / U:0.388 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site