Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/net/ipsec: Fix variable size type not at the end of struct

The "struct alg" object contains a union of 3 xfrm structures:

union {
struct xfrm_algo;
struct xfrm_algo_aead;
struct xfrm_algo_auth;
}

All of them end with a flexible array member used to store key material,
but the flexible array appears at *different offsets* in each struct.
bcz of this, union itself is of variable-sized & Placing it above
char buf[...] triggers:

ipsec.c:835:5: warning: field 'u' with variable sized type 'union
(unnamed union at ipsec.c:831:3)' not at the end of a struct or class
is a GNU extension [-Wgnu-variable-sized-type-not-at-end]
835 | } u;
| ^

one fix is to use "TRAILING_OVERLAP()" which works with one flexible
array member only.

But In "struct alg" flexible array member exists in all union members,
but not at the same offset, so TRAILING_OVERLAP cannot be applied.

so the fix is to explicitly overlay the key buffer at the correct offset
for the largest union member (xfrm_algo_auth). This ensures that the
flexible-array region and the fixed buffer line up.

No functional change.

Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Ankit Khushwaha <ankitkhushwaha.linux@gmail.com>
Link: https://patch.msgid.link/20260109152201.15668-1-ankitkhushwaha.linux@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Ankit Khushwaha and committed by
Jakub Kicinski
088f35ab e405b3c9

+9 -2
+9 -2
tools/testing/selftests/net/ipsec.c
··· 43 43 44 44 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) 45 45 46 + #ifndef offsetof 47 + #define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER) 48 + #endif 49 + 46 50 #define IPV4_STR_SZ 16 /* xxx.xxx.xxx.xxx is longest + \0 */ 47 51 #define MAX_PAYLOAD 2048 48 52 #define XFRM_ALGO_KEY_BUF_SIZE 512 ··· 831 827 static int xfrm_state_pack_algo(struct nlmsghdr *nh, size_t req_sz, 832 828 struct xfrm_desc *desc) 833 829 { 834 - struct { 830 + union { 835 831 union { 836 832 struct xfrm_algo alg; 837 833 struct xfrm_algo_aead aead; 838 834 struct xfrm_algo_auth auth; 839 835 } u; 840 - char buf[XFRM_ALGO_KEY_BUF_SIZE]; 836 + struct { 837 + unsigned char __offset_to_FAM[offsetof(struct xfrm_algo_auth, alg_key)]; 838 + char buf[XFRM_ALGO_KEY_BUF_SIZE]; 839 + }; 841 840 } alg = {}; 842 841 size_t alen, elen, clen, aelen; 843 842 unsigned short type;