Skip to contentSkip to conversation

tls: Avoid -Wflex-array-member-not-at-end warning

PATCH Superseded Gustavo A. R. Silva 3 participants 5 messages Sep 22, 2025 – Sep 23, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tls: Avoid -Wflex-array-member-not-at-end warning

-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:

net/tls/tls.h:131:29: 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 members onto the FAM while preserving the original memory layout.

---
 net/tls/tls.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/tls/tls.h +3 -2
index 4e077068e6d9..d06435d186c0 100644
@@ -128,8 +128,9 @@ struct tls_rec {
 
 	char aad_space[TLS_AAD_SPACE_SIZE];
 	u8 iv_data[TLS_MAX_IV_SIZE];
-	struct aead_request aead_req;
-	u8 aead_req_ctx[];
+	TRAILING_OVERLAP(struct aead_request, aead_req, __ctx,
+		u8 aead_req_ctx[];
+	);
 };
 
 int __net_init tls_proc_init(struct net *net);
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 11 lines · Gustavo A. R. Silva

-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:

net/tls/tls.h:131:29: 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 members onto the FAM while preserving the original memory layout.

Do we need to keep aead_req_ctx in tls_rec? It doesn't seem to be used, and I don't see it ever being used since it was introduced in commit a42055e8d2c3 ("net/tls: Add support for async encryption of records for performance").

Signature · 1 line
Sabrina
#2 lore raw
Quoted 13 lines · Sabrina Dubroca
Quoted 11 lines · Gustavo A. R. Silva

-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:

net/tls/tls.h:131:29: 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 members onto the FAM while preserving the original memory layout.

Quoted 4 lines

Do we need to keep aead_req_ctx in tls_rec? It doesn't seem to be used, and I don't see it ever being used since it was introduced in commit a42055e8d2c3 ("net/tls: Add support for async encryption of records for performance").

If this (flex array) is not going to be needed in the future, I'm happy to remove it. :)

Thanks
-Gustavo

maintainer
#3 lore raw
Quoted 16 lines · Gustavo A. R. Silva
Quoted 13 lines · Sabrina Dubroca
Quoted 11 lines · Gustavo A. R. Silva

-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:

net/tls/tls.h:131:29: 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 members onto the FAM while preserving the original memory layout.

Quoted 7 lines
Quoted 4 lines

Do we need to keep aead_req_ctx in tls_rec? It doesn't seem to be used, and I don't see it ever being used since it was introduced in commit a42055e8d2c3 ("net/tls: Add support for async encryption of records for performance").

If this (flex array) is not going to be needed in the future, I'm happy to remove it. :)

I don't see what we'd use it for, aead_request.__ctx contains private data from the crypto code (all accesses seem to be through aead_request_ctx defined in include/crypto/internal/aead.h, see also the kdoc: "Start of private context data").
And we haven't seen the author of a42055e8d2c3 in a while, so we can't ask about the intention behind this field.

So IMO, tls_rec.aead_req_ctx can simply go away. Would you send the patch?

Signature · 1 line
Sabrina
#4 lore raw
Quoted 13 lines
Quoted 5 lines

If this (flex array) is not going to be needed in the future, I'm happy to remove it. :)

I don't see what we'd use it for, aead_request.__ctx contains private data from the crypto code (all accesses seem to be through aead_request_ctx defined in include/crypto/internal/aead.h, see also the kdoc: "Start of private context data").
And we haven't seen the author of a42055e8d2c3 in a while, so we can't ask about the intention behind this field.

Quoted 3 lines

So IMO, tls_rec.aead_req_ctx can simply go away. Would you send the patch?

Done: https://lore.kernel.org/linux-hardening/aNMG1lyXw4XEAVaE@kspp/

Thank you for the feedback. :)

-Gustavo