From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
Pablo Neira Ayuso <pablo@netfilter.org>,
Florian Westphal <fw@strlen.de>, Phil Sutter <phil@nwl.cc>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, Kees Cook <kees@kernel.org>
Cc: netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH v2][next] netfilter: x_tables: Avoid a couple -Wflex-array-member-not-at-end warnings
Date: Thu, 9 Apr 2026 16:09:21 -0600 [thread overview]
Message-ID: <96b116e4-d91d-456a-9a08-fb3de4822a62@embeddedor.com> (raw)
In-Reply-To: <adgL5wPm9VpaV3MO@kspp>
BTW folks,
We can use the TRAILING_OVERLAP() helper and address these warnings with
the following patch instead:
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index b39017c80548..9dd5957d9ed4 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -819,13 +819,15 @@ EXPORT_SYMBOL_GPL(xt_compat_match_to_user);
/* non-compat version may have padding after verdict */
struct compat_xt_standard_target {
- struct compat_xt_entry_target t;
- compat_uint_t verdict;
+ TRAILING_OVERLAP(struct compat_xt_entry_target, t, data,
+ compat_uint_t verdict;
+ );
};
struct compat_xt_error_target {
- struct compat_xt_entry_target t;
- char errorname[XT_FUNCTION_MAXNAMELEN];
+ TRAILING_OVERLAP(struct compat_xt_entry_target, t, data,
+ char errorname[XT_FUNCTION_MAXNAMELEN];
+ );
};
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. It was created to address exactly these sorts of
issues where flexible-array members end up embedded in the middle
of structs.
You tell me what you prefer.
Thanks
-Gustavo
On 4/9/26 14:28, 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.
>
> struct compat_xt_standard_target and struct compat_xt_error_target are
> only used in xt_compat_check_entry_offsets(). Remove these structs and
> instead define the same memory layout on the stack via flexible struct
> compat_xt_entry_target and DEFINE_RAW_FLEX(). Adjust the rest of the
> code accordingly.
>
> With these changes, fix the following warnings:
>
> 1 net/netfilter/x_tables.c:816:39: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> 1 net/netfilter/x_tables.c:811:39: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> Changes in v2:
> - Update verdict after (compat_uint_t *)st->data;
>
> v1:
> - Link: https://lore.kernel.org/linux-hardening/adbIKC0cZcK7VcCF@kspp/
>
> net/netfilter/x_tables.c | 31 ++++++++++++++-----------------
> 1 file changed, 14 insertions(+), 17 deletions(-)
>
> diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
> index b39017c80548..746012196d83 100644
> --- a/net/netfilter/x_tables.c
> +++ b/net/netfilter/x_tables.c
> @@ -817,17 +817,6 @@ int xt_compat_match_to_user(const struct xt_entry_match *m,
> }
> EXPORT_SYMBOL_GPL(xt_compat_match_to_user);
>
> -/* non-compat version may have padding after verdict */
> -struct compat_xt_standard_target {
> - struct compat_xt_entry_target t;
> - compat_uint_t verdict;
> -};
> -
> -struct compat_xt_error_target {
> - struct compat_xt_entry_target t;
> - char errorname[XT_FUNCTION_MAXNAMELEN];
> -};
> -
> int xt_compat_check_entry_offsets(const void *base, const char *elems,
> unsigned int target_offset,
> unsigned int next_offset)
> @@ -850,18 +839,26 @@ int xt_compat_check_entry_offsets(const void *base, const char *elems,
> return -EINVAL;
>
> if (strcmp(t->u.user.name, XT_STANDARD_TARGET) == 0) {
> - const struct compat_xt_standard_target *st = (const void *)t;
> + DEFINE_RAW_FLEX(const struct compat_xt_entry_target, st, data,
> + sizeof(compat_uint_t));
> + compat_uint_t *verdict;
>
> - if (COMPAT_XT_ALIGN(target_offset + sizeof(*st)) != next_offset)
> + st = (const void *)t;
> + verdict = (compat_uint_t *)st->data;
> +
> + if (COMPAT_XT_ALIGN(target_offset + __struct_size(st)) !=
> + next_offset)
> return -EINVAL;
>
> - if (!verdict_ok(st->verdict))
> + if (!verdict_ok(*verdict))
> return -EINVAL;
> } else if (strcmp(t->u.user.name, XT_ERROR_TARGET) == 0) {
> - const struct compat_xt_error_target *et = (const void *)t;
> + DEFINE_RAW_FLEX(const struct compat_xt_entry_target, et, data,
> + XT_FUNCTION_MAXNAMELEN);
> + et = (const void *)t;
>
> - if (!error_tg_ok(t->u.target_size, sizeof(*et),
> - et->errorname, sizeof(et->errorname)))
> + if (!error_tg_ok(t->u.target_size, __struct_size(et),
> + et->data, __member_size(et->data)))
> return -EINVAL;
> }
>
next prev parent reply other threads:[~2026-04-09 22:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-09 20:28 [PATCH v2][next] netfilter: x_tables: Avoid a couple -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
2026-04-09 22:09 ` Gustavo A. R. Silva [this message]
2026-04-09 22:18 ` Florian Westphal
2026-04-09 22:23 ` Gustavo A. R. Silva
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=96b116e4-d91d-456a-9a08-fb3de4822a62@embeddedor.com \
--to=gustavo@embeddedor.com \
--cc=coreteam@netfilter.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fw@strlen.de \
--cc=gustavoars@kernel.org \
--cc=horms@kernel.org \
--cc=kees@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pablo@netfilter.org \
--cc=phil@nwl.cc \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox