From: Florian Westphal <fw@strlen.de>
To: Jiayuan Chen <jiayuan.chen@linux.dev>
Cc: netfilter-devel@vger.kernel.org, Pablo Neira Ayuso <pablo@netfilter.org>
Subject: Re: [PATCH nf] netfilter: nft_ct: fix OOB in NFT_CT_SRC/DST eval
Date: Thu, 28 May 2026 11:31:32 +0200 [thread overview]
Message-ID: <ahgLdDKloq01r7lK@strlen.de> (raw)
In-Reply-To: <c1383a3a-6c76-411a-8ae3-1dfe90052fb7@linux.dev>
Jiayuan Chen <jiayuan.chen@linux.dev> wrote:
[ CC Pablo ]
> > https://sashiko.dev/#/patchset/20260528042620.263828-1-jiayuan.chen%40linux.dev
> >
> > "This is a pre-existing issue, but does copying only addr_len bytes when
> > priv->len is larger leave the remainder of the register uninitialized?
> > In nft_do_chain(), the register array is allocated on the kernel stack
> > without zero-initialization. If priv->len is 16 and addr_len is 4, only
> > the first 4 bytes are written."
>
> I just spotted that too. I think copying priv->len unconditionally
> is enough -- tuple->{src,dst} is zeroed in nf_ct_get_tuple() before the
> protocol pkt_to_tuple callback fills in only the relevant leading bytes,
> so the trailing bytes of tuple->{src,dst}.u3.all are well-defined zeros
> and no wrapper is needed.
Pablo, whats your take?
chain c {
type filter hook output priority -300; policy accept;
ct zone set 1
ct original saddr 0.0.0.0 counter accept
}
Then: ping -c 1 127.0.0.1
should the rule match the template or not?
If not, we need:
diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c
--- a/net/netfilter/nft_ct.c
+++ b/net/netfilter/nft_ct.c
@@ -78,7 +78,7 @@ static void nft_ct_get_eval(const struct nft_expr *expr,
break;
}
- if (ct == NULL)
+ if (!ct || nf_ct_is_template(ct))
goto err;
switch (priv->key) {
diff --git a/net/netfilter/nft_ct_fast.c b/net/netfilter/nft_ct_fast.c
index e684c8a91848..ecf7b3a404be 100644
--- a/net/netfilter/nft_ct_fast.c
+++ b/net/netfilter/nft_ct_fast.c
@@ -30,7 +30,7 @@ void nft_ct_get_fast_eval(const struct nft_expr *expr,
break;
}
- if (!ct) {
+ if (!ct || nf_ct_is_template(ct)) {
regs->verdict.code = NFT_BREAK;
return;
}
If it should match, we need something like this:
diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c
--- a/net/netfilter/nft_ct.c
+++ b/net/netfilter/nft_ct.c
@@ -180,12 +180,14 @@ static void nft_ct_get_eval(const struct nft_expr *expr,
tuple = &ct->tuplehash[priv->dir].tuple;
switch (priv->key) {
case NFT_CT_SRC:
- memcpy(dest, tuple->src.u3.all,
- nf_ct_l3num(ct) == NFPROTO_IPV4 ? 4 : 16);
+ if (nf_ct_l3num(ct) != nft_pf(pkt))
+ goto err;
+ memcpy(dest, tuple->src.u3.all, priv->len);
return;
case NFT_CT_DST:
- memcpy(dest, tuple->dst.u3.all,
- nf_ct_l3num(ct) == NFPROTO_IPV4 ? 4 : 16);
+ if (nf_ct_l3num(ct) != nft_pf(pkt))
+ goto err;
+ memcpy(dest, tuple->dst.u3.all, priv->len);
return;
case NFT_CT_PROTO_SRC:
nft_reg_store16(dest, (__force u16)tuple->src.u.all);
I am leaning towards both changes. What do you think?
next prev parent reply other threads:[~2026-05-28 9:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-28 4:26 [PATCH nf] netfilter: nft_ct: fix OOB in NFT_CT_SRC/DST eval Jiayuan Chen
2026-05-28 5:19 ` Florian Westphal
2026-05-28 5:43 ` Florian Westphal
2026-05-28 7:02 ` Jiayuan Chen
2026-05-28 7:10 ` Florian Westphal
2026-05-28 7:27 ` Jiayuan Chen
2026-05-28 8:01 ` Florian Westphal
2026-05-28 8:25 ` Jiayuan Chen
2026-05-28 9:31 ` Florian Westphal [this message]
2026-05-28 10:03 ` Pablo Neira Ayuso
2026-05-28 10:24 ` Florian Westphal
2026-05-28 10:26 ` Jiayuan Chen
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=ahgLdDKloq01r7lK@strlen.de \
--to=fw@strlen.de \
--cc=jiayuan.chen@linux.dev \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.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