From nobody Sat Feb 7 15:10:34 2026 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72C0735C18C for ; Fri, 9 Jan 2026 15:22:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767972140; cv=none; b=VWkoWNk1i2GbPasXqY7ogis2lTByS/Op3jnUkYJr4SgHcGhrFP3gYh96Y/SBKA2rABGQZQAv6MgTL+TiY/tetNOgDgMgeuXpBeoHPLHQ2TTuxUUv0v0TmvEwyWetCz8H35hk/AhpTgcbbuYovsxwzHtPefU9/X7IUHL+BWeIySs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767972140; c=relaxed/simple; bh=/0dRPRjqg3IHIqgYOrn2vyyviwdlxxFzHDkKNcZEB7U=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=PdgG2MawvbTUrEMRd5ua+i0gmbL5v+ZCmeHvE3QPVL+FUsLCdrpYw0iwyv5trAoLxAF2Fy8s7Cz/E5Ac2B3l8AXreuY/G+mLiv+1zRTJ7dXcuQ25twWLVVrSSM7uAfcXX+znB4Oq5HA0qvg+sRBhszUmQ15FN4ODA6LYkA8kYKc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KOcCxIYH; arc=none smtp.client-ip=209.85.215.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KOcCxIYH" Received: by mail-pg1-f195.google.com with SMTP id 41be03b00d2f7-b6ce6d1d3dcso1989637a12.3 for ; Fri, 09 Jan 2026 07:22:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767972137; x=1768576937; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=l02srCpqwS/PPVAYoAwmWqO0txf7t8pnFoogY5rh/QA=; b=KOcCxIYH7ZfzPZW1EgMeCaHB8qzTB4V8M6dVzLqboXwd/Hov8grmVhhBnWFEZruIAI PMH0+w7EJVtTiszm0ibb3c6A+OO7Fbgdc6nvKgbjcB/ADx8G31SitVtH4IoVhgsx4gvb sXkIFHmq2xukww/+00iDj7O+MzukW+exdkkWyyC64XiVGnGYNfn3cvvHzInhciOS9u7m lSCrsIQ4YHxdDejbHnoGFTEbDhuoPsCCCRQ1KbvSzb+cS9Yc91uEZeq2K22cxB9sA84Y 4MUtGye4XgcRrX8rQ/8/62/jgNMMSPOVG4ORPFgv9S9137O29rxrOFAkUd3PXIWZlr4r 9Tcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767972137; x=1768576937; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=l02srCpqwS/PPVAYoAwmWqO0txf7t8pnFoogY5rh/QA=; b=wIadhpkkJikdg0rb8jX3hXMoghEmM8WHajR+cMglWhemdpV62xPFixgEcHQJFvEOu4 niZyfF8+9ZyUi2GpDoBa3kBlF+7yuYuHIPpn6VHy6N+YiVwXb7GmISPToD2OVi19dtp4 JZZmx8MGlcuqz664WEIRvtbVj3LRTzszaQ5vAZ+RGLlHh3X2meQCr5te+McdeecRTsuI z9djkrRjbg0lE+QzTeIY6SzWcub3AgEhpUhz+gCO+4uANUHIzWv2KLNvLYPa43yQEEp9 YZxhGbMmo05WK+cFaSyMIsqBv/uyuPB7vxigpGQd9aKZmLHMhEvGx4eV78DipNHEBh5v Pf+A== X-Forwarded-Encrypted: i=1; AJvYcCWVeiD1GgVmcKK6DSjUZR2Sf/9Tm6FdFfCCDHjMB+MIcRA1EmLRxbfHuS1LWUm+0lUmzd183XTaf637044=@vger.kernel.org X-Gm-Message-State: AOJu0YxX2tAhDYoDXh+S316rr5jhkuJkppTavhAZKJ3tLS8GkS9gQdHm GvAo46PT6VZ3Xto+COKVx0oJSzGc0StHVBhUBPj8LcdWaW2RklH4/hrO X-Gm-Gg: AY/fxX5sgsSFkia/SbKC3NrXsuxWFg0QyIgAr8q5W9hHckJU7+UkVYZEkGWTFRw4Vpr AUsRTf3MgPjmUUFQZSpEELSjJwbbLQTwI6veHwceG3rP/p5RZnpgIoscGQAzmg62Y5Dij/EHU4w i+68xOi9ZBitKkDTdW2TVSDDSngEJWhMT9oQ1TSRQgO/mCMDIvWm/UPrhnXs0o2ZSCQsCtmO2y4 TiQNaYbq6wNxjbH6p2dGbKfuFmI6eofa79/g1MkFOo7owLQT9s54VBRiNyUQgvVvWfKkGeA8z1Y KGrDOxYjtGRzGtBZhs37IK00uJIlfhzWhgP1OV22N6AvvD0PyMetHCMtj66wXdGggGipENPkG5I Kt1bC7sxPSg/7T7TPWgmWyelDcciOKcaxiYBXD1ioEMZSxwLquu5ypA2S8wM5By1sjqeaxhVyUZ 4BgAkmmwampbYmwVeGRlM60IB4du1DtGceFz0Xb4cj X-Google-Smtp-Source: AGHT+IFjwhs5i9G743dkgLzBhWBTZ55yy5yc6JsaoH2/JUYyPH+SQo8zbecqIuA/7HClY6kISME1yw== X-Received: by 2002:a17:903:478d:b0:2a0:b438:fc15 with SMTP id d9443c01a7336-2a3ee468407mr97193875ad.11.1767972136629; Fri, 09 Jan 2026 07:22:16 -0800 (PST) Received: from fedora ([103.120.31.122]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a3e3cc87f8sm108021895ad.77.2026.01.09.07.22.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jan 2026 07:22:16 -0800 (PST) From: Ankit Khushwaha To: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Cc: Steffen Klassert , Herbert Xu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan , "Gustavo A. R. Silva" , Ankit Khushwaha Subject: [PATCH RESEND net-next] selftests/net/ipsec: Fix variable size type not at the end of struct Date: Fri, 9 Jan 2026 20:52:01 +0530 Message-ID: <20260109152201.15668-1-ankitkhushwaha.linux@gmail.com> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Ankit Khushwaha --- CCed Gustavo and linux-hardening as suggested by Simon. Previous patch: https://lore.kernel.org/all/aSiXmp4mh7M3RaRv@horms.kernel.o= rg/t/#u --- tools/testing/selftests/net/ipsec.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/ipsec.c b/tools/testing/selftests/= net/ipsec.c index 0ccf484b1d9d..f4afef51b930 100644 --- a/tools/testing/selftests/net/ipsec.c +++ b/tools/testing/selftests/net/ipsec.c @@ -43,6 +43,10 @@ #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) +#ifndef offsetof +#define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER) +#endif + #define IPV4_STR_SZ 16 /* xxx.xxx.xxx.xxx is longest + \0 */ #define MAX_PAYLOAD 2048 #define XFRM_ALGO_KEY_BUF_SIZE 512 @@ -827,13 +831,16 @@ static int xfrm_fill_key(char *name, char *buf, static int xfrm_state_pack_algo(struct nlmsghdr *nh, size_t req_sz, struct xfrm_desc *desc) { - struct { + union { union { struct xfrm_algo alg; struct xfrm_algo_aead aead; struct xfrm_algo_auth auth; } u; - char buf[XFRM_ALGO_KEY_BUF_SIZE]; + struct { + unsigned char __offset_to_FAM[offsetof(struct xfrm_algo_auth, alg_key)]; + char buf[XFRM_ALGO_KEY_BUF_SIZE]; + }; } alg =3D {}; size_t alen, elen, clen, aelen; unsigned short type; -- 2.52.0