* [PATCH][next] KEYS: Avoid -Wflex-array-member-not-at-end warning
@ 2025-11-10 10:46 Gustavo A. R. Silva
2025-11-11 16:51 ` Ignat Korchagin
2025-11-22 3:14 ` Herbert Xu
0 siblings, 2 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2025-11-10 10:46 UTC (permalink / raw)
To: David Howells, Lukas Wunner, Ignat Korchagin, Herbert Xu,
David S. Miller
Cc: keyrings, 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/asymmetric_keys/restrict.c:20:34: 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 unsigned char data[10]; onto the FAM
struct asymmetric_key_id::data[], 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/asymmetric_keys/restrict.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/crypto/asymmetric_keys/restrict.c b/crypto/asymmetric_keys/restrict.c
index afcd4d101ac5..86292965f493 100644
--- a/crypto/asymmetric_keys/restrict.c
+++ b/crypto/asymmetric_keys/restrict.c
@@ -17,9 +17,12 @@ static struct asymmetric_key_id *ca_keyid;
#ifndef MODULE
static struct {
- struct asymmetric_key_id id;
- unsigned char data[10];
+ /* Must be last as it ends in a flexible-array member. */
+ TRAILING_OVERLAP(struct asymmetric_key_id, id, data,
+ unsigned char data[10];
+ );
} cakey;
+static_assert(offsetof(typeof(cakey), id.data) == offsetof(typeof(cakey), data));
static int __init ca_keys_setup(char *str)
{
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH][next] KEYS: Avoid -Wflex-array-member-not-at-end warning
2025-11-10 10:46 [PATCH][next] KEYS: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
@ 2025-11-11 16:51 ` Ignat Korchagin
2025-11-22 3:14 ` Herbert Xu
1 sibling, 0 replies; 3+ messages in thread
From: Ignat Korchagin @ 2025-11-11 16:51 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: David Howells, Lukas Wunner, Herbert Xu, David S. Miller,
keyrings, linux-crypto, linux-kernel, linux-hardening
On Mon, Nov 10, 2025 at 10:46 AM Gustavo A. R. Silva
<gustavoars@kernel.org> wrote:
>
> -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/asymmetric_keys/restrict.c:20:34: 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 unsigned char data[10]; onto the FAM
> struct asymmetric_key_id::data[], 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>
Reviewed-by: Ignat Korchagin <ignat@cloudflare.com>
> ---
> crypto/asymmetric_keys/restrict.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/crypto/asymmetric_keys/restrict.c b/crypto/asymmetric_keys/restrict.c
> index afcd4d101ac5..86292965f493 100644
> --- a/crypto/asymmetric_keys/restrict.c
> +++ b/crypto/asymmetric_keys/restrict.c
> @@ -17,9 +17,12 @@ static struct asymmetric_key_id *ca_keyid;
>
> #ifndef MODULE
> static struct {
> - struct asymmetric_key_id id;
> - unsigned char data[10];
> + /* Must be last as it ends in a flexible-array member. */
> + TRAILING_OVERLAP(struct asymmetric_key_id, id, data,
> + unsigned char data[10];
> + );
> } cakey;
> +static_assert(offsetof(typeof(cakey), id.data) == offsetof(typeof(cakey), data));
The whole thing looks a bit convoluted to me just to declare a
fixed-sized static buffer and call sizeof() in one place in the code.
But I couldn't come up with a better refactor not introducing
potential alignment side-effects. So LGTM.
> static int __init ca_keys_setup(char *str)
> {
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][next] KEYS: Avoid -Wflex-array-member-not-at-end warning
2025-11-10 10:46 [PATCH][next] KEYS: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
2025-11-11 16:51 ` Ignat Korchagin
@ 2025-11-22 3:14 ` Herbert Xu
1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2025-11-22 3:14 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: David Howells, Lukas Wunner, Ignat Korchagin, David S. Miller,
keyrings, linux-crypto, linux-kernel, linux-hardening
On Mon, Nov 10, 2025 at 07:46:45PM +0900, Gustavo A. R. Silva wrote:
> -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/asymmetric_keys/restrict.c:20:34: 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 unsigned char data[10]; onto the FAM
> struct asymmetric_key_id::data[], 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/asymmetric_keys/restrict.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
Patch applied. Thanks.
--
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] 3+ messages in thread
end of thread, other threads:[~2025-11-22 3:14 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:46 [PATCH][next] KEYS: Avoid -Wflex-array-member-not-at-end warning Gustavo A. R. Silva
2025-11-11 16:51 ` Ignat Korchagin
2025-11-22 3:14 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).