From nobody Wed Apr 1 09:43:21 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F7B33E9F96; Mon, 30 Mar 2026 22:39:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774910365; cv=none; b=dgxntStS5+7kuey6BLkjmgpBYN2aUQnr1xj2e/9PJIRuag/VdLy+nz9TeVAlpdaJBkn0d3HkRG3TCm/gpktTisfYJWpK8jghu1ogO8UtEompAfY/iFTCURhYEmHqCBvE4f91GLrSAVPdSedZ13Z64WsvQUtVvQr6httAzZjv15Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774910365; c=relaxed/simple; bh=TwsrmNJ7QssX1MDhmOKLBLHVuRzzNYSq93LE55QsCVc=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=gvqnkI64DkpFZEoj8lXF+X1EpdZL2RUJ+eQI+7smwvaiOCXaCO37uhCXNzdtDP9cBAxJ2XsSAsHSvuz1w/LYCEI5S9w39nv1gYkM5A5a3QRdQzzjc3rxyWPqr7tWbyJjXsgFNtGn7Ll/Te4n36tq+6c/8epZYXP47h4HvKJSPyA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GwdqFiTo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GwdqFiTo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8AC12C4CEF7; Mon, 30 Mar 2026 22:39:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774910364; bh=TwsrmNJ7QssX1MDhmOKLBLHVuRzzNYSq93LE55QsCVc=; h=Date:From:To:Cc:Subject:From; b=GwdqFiTogc7F2gsU+gMrS6MyLFsi0Z2jZ+MtjuE3l52DlAaQgpBkftxgsoTTB9jSa PPzBO537tnppzqKFwmisVIe/ZjYklkkMTal7xkBy3EP3M1J+NPyxkNckpJFWYdtUzF rKToAB2AE11OqXOD3Ib3N47fuaPAVaw6hEvblflyrK7htesktJCcZqB2xcIKjs2nlP 9HMTg1tHgfTUH1wSgz3urU6s4DEMpNwntLn7lMN7W+Pja2VG7Y2DXAKeDpuu7TeAUT x0Nvum+zUm3klepemH1UTsEDY0CHkQcl11AyBa0EtWN9QRO4f9jhRThx3YJbDXKBGh VK6Kr2w/eJ65Q== Date: Mon, 30 Mar 2026 16:38:18 -0600 From: "Gustavo A. R. Silva" To: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org, Kees Cook Subject: [PATCH v2][next] bpf: Avoid thousands of -Wflex-array-members-not-at-end warnings Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Apparently, struct bpf_empty_prog_array exists entirely to populate a single element of "items" in a global variable. "null_prog" is only used during the initializer. None of this is needed; globals will be correctly sized with an array initializer of a flexible-array member. So, remove struct bpf_empty_prog_array and adjust the rest of the code, accordingly.=20 With these changes, fix the following warnings: 7659 ./include/linux/bpf.h:2369:31: warning: structure containing a flexibl= e array member is not at the end of another structure [-Wflex-array-member-= not-at-end] Signed-off-by: Gustavo A. R. Silva Acked-by: Mykyta Yatsenko --- Changes in v2: - Remove struct bpf_empty_prog_array. (Kees) v1: -Link: https://lore.kernel.org/linux-hardening/aaZr2A1UPJq33127@kspp/ include/linux/bpf-cgroup.h | 2 +- include/linux/bpf.h | 7 +------ kernel/bpf/core.c | 12 +++++++----- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h index 2f535331f926..b2e79c2b41d5 100644 --- a/include/linux/bpf-cgroup.h +++ b/include/linux/bpf-cgroup.h @@ -184,7 +184,7 @@ static inline bool cgroup_bpf_sock_enabled(struct sock = *sk, struct bpf_prog_array *array; =20 array =3D rcu_access_pointer(cgrp->bpf.effective[type]); - return array !=3D &bpf_empty_prog_array.hdr; + return array !=3D &bpf_empty_prog_array; } =20 /* Wrappers for __cgroup_bpf_run_filter_skb() guarded by cgroup_bpf_enable= d. */ diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 05b34a6355b0..4f5b9e85a20c 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -2365,18 +2365,13 @@ struct bpf_prog_array { struct bpf_prog_array_item items[]; }; =20 -struct bpf_empty_prog_array { - struct bpf_prog_array hdr; - struct bpf_prog *null_prog; -}; - /* to avoid allocating empty bpf_prog_array for cgroups that * don't have bpf program attached use one global 'bpf_empty_prog_array' * It will not be modified the caller of bpf_prog_array_alloc() * (since caller requested prog_cnt =3D=3D 0) * that pointer should be 'freed' by bpf_prog_array_free() */ -extern struct bpf_empty_prog_array bpf_empty_prog_array; +extern struct bpf_prog_array bpf_empty_prog_array; =20 struct bpf_prog_array *bpf_prog_array_alloc(u32 prog_cnt, gfp_t flags); void bpf_prog_array_free(struct bpf_prog_array *progs); diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 67eb12b637a5..ca39d2e690b9 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -2613,8 +2613,10 @@ static struct bpf_prog_dummy { }, }; =20 -struct bpf_empty_prog_array bpf_empty_prog_array =3D { - .null_prog =3D NULL, +struct bpf_prog_array bpf_empty_prog_array =3D { + .items =3D { + { .prog =3D NULL }, + }, }; EXPORT_SYMBOL(bpf_empty_prog_array); =20 @@ -2625,14 +2627,14 @@ struct bpf_prog_array *bpf_prog_array_alloc(u32 pro= g_cnt, gfp_t flags) if (prog_cnt) p =3D kzalloc_flex(*p, items, prog_cnt + 1, flags); else - p =3D &bpf_empty_prog_array.hdr; + p =3D &bpf_empty_prog_array; =20 return p; } =20 void bpf_prog_array_free(struct bpf_prog_array *progs) { - if (!progs || progs =3D=3D &bpf_empty_prog_array.hdr) + if (!progs || progs =3D=3D &bpf_empty_prog_array) return; kfree_rcu(progs, rcu); } @@ -2653,7 +2655,7 @@ static void __bpf_prog_array_free_sleepable_cb(struct= rcu_head *rcu) =20 void bpf_prog_array_free_sleepable(struct bpf_prog_array *progs) { - if (!progs || progs =3D=3D &bpf_empty_prog_array.hdr) + if (!progs || progs =3D=3D &bpf_empty_prog_array) return; call_rcu_tasks_trace(&progs->rcu, __bpf_prog_array_free_sleepable_cb); } --=20 2.43.0