All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] crypto: drbg - Avoid -Wflex-array-member-not-at-end warning
@ 2025-11-10 10:44 Gustavo A. R. Silva
  2025-11-19  4:38 ` [v2 PATCH] crypto: drbg - Delete unused ctx from struct sdesc Herbert Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2025-11-10 10:44 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller
  Cc: linux-crypto, linux-kernel, Gustavo A. R. Silva, linux-hardening

-Wflex-array-member-not-at-end was introduced in GCC-14, and we are
getting ready to enable it, globally.

Use the new TRAILING_OVERLAP() helper to fix the following warning:

crypto/drbg.c:1445:27: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]

This helper creates a union between a flexible-array member (FAM) and a
set of MEMBERS that would otherwise follow it.

This overlays the trailing MEMBER char ctx[]; onto the FAM struct
shash_desc::__ctx,[] while keeping the FAM and the start of MEMBER
aligned.

The static_assert() ensures this alignment remains, and it's
intentionally placed inmediately after the corresponding structures --no
blank line in between.

Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 crypto/drbg.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/crypto/drbg.c b/crypto/drbg.c
index 511a27c91813..e9f9775c237f 100644
--- a/crypto/drbg.c
+++ b/crypto/drbg.c
@@ -1442,9 +1442,12 @@ static void drbg_kcapi_set_entropy(struct crypto_rng *tfm,
 
 #if defined(CONFIG_CRYPTO_DRBG_HASH) || defined(CONFIG_CRYPTO_DRBG_HMAC)
 struct sdesc {
-	struct shash_desc shash;
-	char ctx[];
+	/* Must be last as it ends in a flexible-array member. */
+	TRAILING_OVERLAP(struct shash_desc, shash, __ctx,
+		char ctx[];
+	);
 };
+static_assert(offsetof(struct sdesc, shash.__ctx) == offsetof(struct sdesc, ctx));
 
 static int drbg_init_hash_kernel(struct drbg_state *drbg)
 {
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [v2 PATCH] crypto: drbg - Delete unused ctx from struct sdesc
  2025-11-10 10:44 [PATCH][next] crypto: drbg - Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
@ 2025-11-19  4:38 ` Herbert Xu
  2025-11-19  4:47   ` Gustavo A. R. Silva
  0 siblings, 1 reply; 3+ messages in thread
From: Herbert Xu @ 2025-11-19  4:38 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: David S. Miller, linux-crypto, linux-kernel, linux-hardening,
	Stephan Mueller

On Mon, Nov 10, 2025 at 07:44:56PM +0900, Gustavo A. R. Silva wrote:
>
> diff --git a/crypto/drbg.c b/crypto/drbg.c
> index 511a27c91813..e9f9775c237f 100644
> --- a/crypto/drbg.c
> +++ b/crypto/drbg.c
> @@ -1442,9 +1442,12 @@ static void drbg_kcapi_set_entropy(struct crypto_rng *tfm,
>  
>  #if defined(CONFIG_CRYPTO_DRBG_HASH) || defined(CONFIG_CRYPTO_DRBG_HMAC)
>  struct sdesc {
> -	struct shash_desc shash;
> -	char ctx[];
> +	/* Must be last as it ends in a flexible-array member. */
> +	TRAILING_OVERLAP(struct shash_desc, shash, __ctx,
> +		char ctx[];
> +	);
>  };
> +static_assert(offsetof(struct sdesc, shash.__ctx) == offsetof(struct sdesc, ctx));

This isn't even used.  Just delete it:

---8<---
The ctx array in struct sdesc is never used.  Delete it as it's
bogus since the previous member ends with a flexible array.

Reported-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/crypto/drbg.c b/crypto/drbg.c
index 511a27c91813..1d433dae9955 100644
--- a/crypto/drbg.c
+++ b/crypto/drbg.c
@@ -1443,7 +1443,6 @@ static void drbg_kcapi_set_entropy(struct crypto_rng *tfm,
 #if defined(CONFIG_CRYPTO_DRBG_HASH) || defined(CONFIG_CRYPTO_DRBG_HMAC)
 struct sdesc {
 	struct shash_desc shash;
-	char ctx[];
 };
 
 static int drbg_init_hash_kernel(struct drbg_state *drbg)
-- 
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] 3+ messages in thread

* Re: [v2 PATCH] crypto: drbg - Delete unused ctx from struct sdesc
  2025-11-19  4:38 ` [v2 PATCH] crypto: drbg - Delete unused ctx from struct sdesc Herbert Xu
@ 2025-11-19  4:47   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2025-11-19  4:47 UTC (permalink / raw)
  To: Herbert Xu, Gustavo A. R. Silva
  Cc: David S. Miller, linux-crypto, linux-kernel, linux-hardening,
	Stephan Mueller



On 11/19/25 13:38, Herbert Xu wrote:
> On Mon, Nov 10, 2025 at 07:44:56PM +0900, Gustavo A. R. Silva wrote:
>>
>> diff --git a/crypto/drbg.c b/crypto/drbg.c
>> index 511a27c91813..e9f9775c237f 100644
>> --- a/crypto/drbg.c
>> +++ b/crypto/drbg.c
>> @@ -1442,9 +1442,12 @@ static void drbg_kcapi_set_entropy(struct crypto_rng *tfm,
>>   
>>   #if defined(CONFIG_CRYPTO_DRBG_HASH) || defined(CONFIG_CRYPTO_DRBG_HMAC)
>>   struct sdesc {
>> -	struct shash_desc shash;
>> -	char ctx[];
>> +	/* Must be last as it ends in a flexible-array member. */
>> +	TRAILING_OVERLAP(struct shash_desc, shash, __ctx,
>> +		char ctx[];
>> +	);
>>   };
>> +static_assert(offsetof(struct sdesc, shash.__ctx) == offsetof(struct sdesc, ctx));
> 
> This isn't even used.  Just delete it:

Awesome. :)

Thanks!
-Gustavo

> 
> ---8<---
> The ctx array in struct sdesc is never used.  Delete it as it's
> bogus since the previous member ends with a flexible array.
> 
> Reported-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
> 
> diff --git a/crypto/drbg.c b/crypto/drbg.c
> index 511a27c91813..1d433dae9955 100644
> --- a/crypto/drbg.c
> +++ b/crypto/drbg.c
> @@ -1443,7 +1443,6 @@ static void drbg_kcapi_set_entropy(struct crypto_rng *tfm,
>   #if defined(CONFIG_CRYPTO_DRBG_HASH) || defined(CONFIG_CRYPTO_DRBG_HMAC)
>   struct sdesc {
>   	struct shash_desc shash;
> -	char ctx[];
>   };
>   
>   static int drbg_init_hash_kernel(struct drbg_state *drbg)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-19  4:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-10 10:44 [PATCH][next] crypto: drbg - Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
2025-11-19  4:38 ` [v2 PATCH] crypto: drbg - Delete unused ctx from struct sdesc Herbert Xu
2025-11-19  4:47   ` Gustavo A. R. Silva

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.