From: Abdifatah Suruur <suruurism@gmail.com>
To: stable@vger.kernel.org
Cc: Pablo Neira Ayuso <pablo@netfilter.org>,
Florian Westphal <fw@strlen.de>,
Greg KH <gregkh@linuxfoundation.org>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.18.y 2/2] netfilter: nft_byteorder: initialise the marked destination span
Date: Mon, 09 Nov 2026 15:23:54 +0300 [thread overview]
Message-ID: <179422703408.5131.108447142790135267@gmail.com> (raw)
In-Reply-To: <179422702104.5131.8115555421206983838@gmail.com>
nft_byteorder_eval() writes only priv->len / priv->size whole elements,
while nft_parse_register_store() marks DIV_ROUND_UP(priv->len, 4) full
32-bit words as initialised. For len/size combinations that do not fill
the last marked word -- for example size 2 with len 1, which writes no
element at all -- the control plane still accepts a later load of the
whole word from another expression. That load reads stale bytes from
the struct nft_regs stack slot in nft_do_chain(), which is not
zero-initialised.
Zero the span that the control plane marks as initialised before the
conversion, but only when the source and destination registers differ.
nft_reg_overlap() allows an in-place conversion (sreg == dreg), and the
source is already initialised in that case; zeroing it would corrupt
the value.
This preserves multi-register support and does not reject any rule, so
old nftables versions that generate len != size continue to load. It
only removes the dependency on some other initialisation of the
register file. Builds with CONFIG_INIT_STACK_ALL_ZERO mask the leak,
but nft_byteorder must not rely on that.
Fixes: 14fb07130c7d ("netfilter: nf_tables: allow loads only when register is initialized")
Cc: stable@vger.kernel.org
Signed-off-by: Abdifatah Suruur <suruurism@gmail.com>
---
diff --git a/net/netfilter/nft_byteorder.c b/net/netfilter/nft_byteorder.c
--- a/net/netfilter/nft_byteorder.c
+++ b/net/netfilter/nft_byteorder.c
@@ -33,6 +33,17 @@ void nft_byteorder_eval(const struct nft_expr *expr,
u16 *s16, *d16;
unsigned int i;
+ /*
+ * nft_parse_register_store() marks DIV_ROUND_UP(priv->len, 4)
+ * words as initialised, but this function only writes whole
+ * len/size elements. Zero the marked span so that a later load
+ * cannot read uninitialised stack data. Do not touch it when
+ * source and destination are the same register: the source is
+ * already initialised and zeroing it would corrupt the value.
+ */
+ if (priv->sreg != priv->dreg)
+ memset(dst, 0, DIV_ROUND_UP(priv->len, 4) * sizeof(u32));
+
s16 = (void *)src;
d16 = (void *)dst;
--
2.53.0
prev parent reply other threads:[~2026-11-09 12:23 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 12:23 [PATCH 6.18.y 0/2] nft_byteorder: fix the uninitialised-stack read without removing multi-register support Abdifatah Suruur
2026-11-09 12:23 ` [PATCH 6.18.y 1/2] Revert "netfilter: nft_byteorder: remove multi-register support" Abdifatah Suruur
2026-11-09 12:25 ` Pablo Neira Ayuso
2026-11-09 12:35 ` Pablo Neira Ayuso
2026-11-09 13:18 ` Abdifatah Suruur
2026-11-09 12:23 ` Abdifatah Suruur [this message]
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=179422703408.5131.108447142790135267@gmail.com \
--to=suruurism@gmail.com \
--cc=fw@strlen.de \
--cc=gregkh@linuxfoundation.org \
--cc=pablo@netfilter.org \
--cc=sashal@kernel.org \
--cc=stable@vger.kernel.org \
/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