From: Dickson Wu via B4 Relay <devnull+dickson.wu.certik.com@kernel.org>
To: netfilter-devel@vger.kernel.org
Cc: Pablo Neira Ayuso <pablo@netfilter.org>,
Florian Westphal <fw@strlen.de>, Phil Sutter <phil@nwl.cc>,
coreteam@netfilter.org, netdev@vger.kernel.org
Subject: [PATCH nf 2/2] netfilter: conntrack: reject timeout protocol mismatch
Date: Fri, 27 Nov 2026 18:12:11 +0000 [thread overview]
Message-ID: <20261127-nf-ctproto2-v1-2-b5383cef8da2@certik.com> (raw)
In-Reply-To: <20261127-nf-ctproto2-v1-0-b5383cef8da2@certik.com>
From: Dickson Wu <dickson.wu@certik.com>
A conntrack template can carry a timeout policy selected from rule
metadata instead of the packet protocol. nft_compat does not enforce its
compatibility protocol when evaluating packets, so an ICMP or UDP policy
can be copied to a TCP conntrack.
Timeout data is laid out for one protocol tracker, so an ICMP policy on
a TCP conntrack makes nf_conntrack_tcp_packet() read past the end of the
timeout object. Copy a template timeout only when its protocol matches
the new conntrack.
Fixes: 24de58f46516 ("netfilter: xt_CT: allow to attach timeout policy + glue code")
Signed-off-by: Dickson Wu <dickson.wu@certik.com>
---
This was found and the fix prepared with AI coding tools (OpenAI Codex
agents, with review by Claude). I went over the analysis and the patch
before signing off.
net/netfilter/nf_conntrack_core.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 931b76aacd..eaae27bf09 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -1782,9 +1782,13 @@ init_conntrack(struct net *net, struct nf_conn *tmpl,
timeout_ext = tmpl ? nf_ct_timeout_find(tmpl) : NULL;
- if (timeout_ext)
- nf_ct_timeout_ext_add(ct, rcu_dereference(timeout_ext->timeout),
- GFP_ATOMIC);
+ if (timeout_ext) {
+ struct nf_ct_timeout *timeout;
+
+ timeout = rcu_dereference(timeout_ext->timeout);
+ if (timeout && timeout->l4proto->l4proto == nf_ct_protonum(ct))
+ nf_ct_timeout_ext_add(ct, timeout, GFP_ATOMIC);
+ }
nf_ct_acct_ext_add(ct, GFP_ATOMIC);
nf_ct_tstamp_ext_add(ct, GFP_ATOMIC);
--
2.43.0
prev parent reply other threads:[~2026-11-27 21:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 21:09 [PATCH nf 0/2] netfilter: reject mismatched conntrack template protocols Dickson Wu via B4 Relay
2026-11-27 18:12 ` [PATCH nf 1/2] netfilter: conntrack: reject helper protocol mismatch Dickson Wu via B4 Relay
2026-11-28 22:02 ` Pablo Neira Ayuso
2026-11-28 22:34 ` Dickson Wu
2026-11-27 18:12 ` Dickson Wu via B4 Relay [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=20261127-nf-ctproto2-v1-2-b5383cef8da2@certik.com \
--to=devnull+dickson.wu.certik.com@kernel.org \
--cc=coreteam@netfilter.org \
--cc=dickson.wu@certik.com \
--cc=fw@strlen.de \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--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