Article View: linux.kernel.netdev
Article #21862Re: [PATCH net-next 06/15] netfilter: conntrack: harden helper invocation with tuple revalidation
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 14:39
Date: Tue, 24 Nov 2026 14:39
242 lines
17668 bytes
17668 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 1 · High: 2 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Critical] netfilter: conntrack: H.245 l4proto mismatch bypasses TCP
check in helper call
- [High] The new tuple check in nf_confirm_get_protoff()
(net/netfilter/nf_conntrack_proto.c) only passes packets whose headers…
- [High] netfilter: conntrack: missing UDP header size check in
nf_confirm_get_protoff()
--
netfilter: conntrack: harden helper invocation with tuple revalidation
This commit makes nf_confirm_get_protoff() pull the current tuple from
the packet and check it against the conntrack entry. Packets that were
modified after the conntrack lookup (for example by act_ct -> pedit) no
longer reach helpers. It also adds a TCP header sanity check and passes
nhoff to ipv6_skip_exthdr().
> diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
> index 18125aa29e0d0..43bf3a71dbbfc 100644
> --- a/net/netfilter/nf_conntrack_proto.c
> +++ b/net/netfilter/nf_conntrack_proto.c
[ ... ]
> @@ -160,6 +164,41 @@ static bool nf_confirm_get_protoff(struct sk_buff *skb, struct net *net,
> return false;
> }
>
> + if (protoff > skb->len)
> + return false;
> +
> + if (!nf_ct_get_tuplepr(skb, nhoff, nf_ct_l3num(ct), net, &tuple))
> + return false;
> +
> + dir = CTINFO2DIR(ctinfo);
> + if (!nf_ct_invert_tuple(&invert, &tuple))
> + return false;
> +
> + /* This is called after L3/L4 headers have been mangled by NAT:
> + * Packet in original direction has been subject to SNAT, i.e.
> + * inverted reply dir.
> + * Packet in reply direction has been subject to DNAT, i.e.
> + * inverted original direction.
> + */
> + if (!nf_ct_tuple_equal(&invert, nf_ct_tuple(ct, !dir)))
> + return false;
[Severity: High]
On the nf_confirm() hook path NAT has always run before this check. Is
that also true when we get here through nf_ct_helper() from openvswitch
or act_ct?
Both callers only NAT the packet when the ct action has the nat flag,
but they call the helper for any confirmed, non-cached packet. In
net/openvswitch/conntrack.c:__ovs_ct_lookup():
* this by delaying both NAT and helper calls for unconfirmed
* connections until the committing CT action. For later
* packets NAT and Helper may be called in either order.
...
if (info->nat && !(key->ct_state & OVS_CS_F_NAT_MASK) &&
(nf_ct_is_confirmed(ct) || info->commit)) {
int err = ovs_ct_nat(net, key, info, skb, ct, ctinfo);
...
if (nf_ct_is_confirmed(ct) && !cached) {
int err = nf_ct_helper(skb, ct, ctinfo, info->family);
net/sched/act_ct.c behaves the same way. tcf_ct_act_nat() returns early:
if (!(ct_action & TCA_CT_ACT_NAT))
return NF_ACCEPT;
and tcf_ct_act() still calls the helper:
if (nf_ct_is_confirmed(ct) ? (!cached && !skip_add) : commit) {
err = nf_ct_helper(skb, ct, ctinfo, family);
Take a confirmed connection with SNAT/DNAT bindings and a helper such as
FTP, possibly with IPS_SEQ_ADJUST set. Suppose it is first looked up by a
ct action without nat, such as OVS ct(table=N) before a later
ct(commit,nat), or tc ct zone X before ct commit nat.
The packet is still untranslated, so its tuple matches
ct->tuplehash[dir]. Inverting it does not give ct->tuplehash[!dir],
because NAT changed that tuple. nf_ct_tuple_equal() then fails here, and
nf_ct_call_helper() returns early:
if (!nf_confirm_get_protoff(skb, net, ct, ctinfo, &protoff, &pnum))
return NF_ACCEPT;
That skips both helper_cb() and nf_ct_seq_adjust().
The later ct(nat) action in the same zone treats the skb as cached:
skb_nfct_cached() and tcf_ct_skb_nfct_cached() return true when zone and
helper match. Neither caller calls nf_ct_helper() again for that packet.
So the packet never gets helper processing or sequence adjustment. FTP
PORT/PASV commands on the established control connection would create no
expectations. Once seqadj offsets exist, seq/ack numbers would stop being
corrected. Before this patch the helper and seqadj ran on these packets.
The earlier patch in this series, "netfilter: conntrack: validate
skb->_nfct and packet headers", accepts both forms in
nf_ct_get_careful(): tuple equal to tuplehash[dir], or inverted tuple
equal to tuplehash[!dir] with IPS_NAT_MASK set.
Could this check accept either form as well? Packets changed by pedit
would still be rejected.
> +
> + /* Validate that a full, sane TCP header (including options) is
> + * present at protoff before helpers/seqadj are allowed to touch it.
> + */
[ ... ]
> @@ -160,6 +164,41 @@ static bool nf_confirm_get_protoff(struct sk_buff *skb, struct net *net,
> return false;
> }
>
> + if (protoff > skb->len)
> + return false;
> +
> + if (!nf_ct_get_tuplepr(skb, nhoff, nf_ct_l3num(ct), net, &tuple))
> + return false;
> +
> + dir = CTINFO2DIR(ctinfo);
> + if (!nf_ct_invert_tuple(&invert, &tuple))
> + return false;
> +
> + /* This is called after L3/L4 headers have been mangled by NAT:
> + * Packet in original direction has been subject to SNAT, i.e.
> + * inverted reply dir.
> + * Packet in reply direction has been subject to DNAT, i.e.
> + * inverted original direction.
> + */
> + if (!nf_ct_tuple_equal(&invert, nf_ct_tuple(ct, !dir)))
> + return false;
> +
> + /* Validate that a full, sane TCP header (including options) is
> + * present at protoff before helpers/seqadj are allowed to touch it.
> + */
> + if (tuple.dst.protonum == IPPROTO_TCP) {
> + unsigned int tcplen = skb->len - protoff;
> + const struct tcphdr *th;
> + struct tcphdr _tcph;
> +
> + th = skb_header_pointer(skb, protoff, sizeof(_tcph), &_tcph);
> + if (!th)
> + return false;
> +
> + if (th->doff * 4 < sizeof(*th) || tcplen < th->doff * 4)
> + return false;
> + }
> +
> *protoffp = protoff;
> return true;
> }
[Severity: High]
TCP gets a full header check here, but for UDP the only length
validation left is what nf_ct_get_tuplepr() does. That ends up in
nf_ct_get_tuple_ports(), which only pulls the 4 bytes holding the
ports, not sizeof(struct udphdr).
The commit message names act_ct -> pedit as the case being hardened
against. Suppose pedit increases iph->ihl on a UDP packet after act_ct
has attached the conntrack. protoff moves forward, and as long as the
4 bytes at the new protoff carry the original ports, the tuple still
matches. With only 6 bytes left we return true for a truncated UDP
header. nf_ct_get_careful() from earlier in the series does the same
4 byte tuple lookup and returns before udp_error() would run, so
nothing else catches it.
UDP helpers assume the caller already guaranteed a full UDP header.
help() in nf_nat_snmp_basic_main.c only checks that
udp_get_len_short(udph) equals skb->len - (iph->ihl << 2). With
udph->len set to 6 and 6 bytes remaining, that passes, and
snmp_translate() then computes:
u16 datalen = udp_get_len_short(udph) - sizeof(struct udphdr);
which wraps to 65534. asn1_ber_decoder() is handed that length. It
reads up to 64K past skb->tail, and through the mangling callbacks it
also writes there.
Could this add a sizeof(struct udphdr) check for IPPROTO_UDP next to
the TCP one? Should it also reject a uh->len smaller than the header,
or is that left to the individual helpers?
[Severity: Critical]
The TCP header check here is keyed on tuple.dst.protonum, so it
follows the protocol of the packet rather than what the attached
helper is going to parse. Does that hold for nf_conntrack_helper_h245?
h323_helper_init() registers the H.245 helper with IPPROTO_UDP, but
h245_help() treats the payload as TCP. get_tpkt_data() reads a struct
tcphdr at protoff and computes tcpdataoff = protoff + th->doff * 4
without checking that doff is at least 5.
Because the helper's l4proto is UDP, it can be attached to a NATted UDP
conntrack entry, e.g. with a ct helper object or the CT target, which
only needs CAP_NET_ADMIN in a user namespace. For such a flow the doff
validation below is skipped because tuple.dst.protonum is IPPROTO_UDP.
The helper->l4proto != pnum test in nf_ct_call_helper() also passes,
so h245_help() runs on a UDP packet.
th->doff then comes from byte 4 of the UDP payload. With doff == 0,
tcpdataoff equals protoff and the TPKT header is taken from the UDP
ports. If the decoder finds an H245_TransportAddress, set_addr() sees a
UDP packet and calls nf_nat_mangle_udp_packet() with an addroff that
was computed relative to protoff. mangle_contents() then adds
protoff + sizeof(struct udphdr) to it, so the match ends 8 bytes past
skb->tail. The memmove() length underflows and the copy writes beyond
the packet data into skb_shared_info.
The mismatch also breaks the legitimate case. expect_h245() creates TCP
expectations bound to nf_conntrack_helper_h245. For real H.245 traffic
pnum is IPPROTO_TCP while helper->l4proto is IPPROTO_UDP, so
nf_ct_call_helper() returns NF_ACCEPT without calling h245_help().
H.245 address translation would silently stop working.
Should nf_conntrack_helper_h245 be switched to IPPROTO_TCP as part of
this series, now that nf_ct_call_helper() compares helper->l4proto
against pnum? Or should the header validation here be driven by the
helper's l4proto instead of the packet's protocol? Either way,
get_tpkt_data() probably wants its own doff sanity check.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123135726.3940688-2-pablo%40netfilter.org
Technical Details
Message-ID:
<179553117549.3135.4393332546290332600@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370463-linux-kernel-netdev=dewy.ruReferences:
<20261123135726.3940688-7-pablo@netfilter.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370463-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next 06/15] netfilter: conntrack: harden helper invocation with tuple revalidation Date: Tue, 24 Nov 2026 14:39:35 +0000 Organization: Usenet Network Message-ID: <179553117549.3135.4393332546290332600@kernel.org> References: <20261123135726.3940688-7-pablo@netfilter.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="4159871"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:WJw/jTacuaFVNcTDYh3aAKPDRWA= sha256:8h3XozETPmhiq/c5QWsOGcGNRR9TfAzq7dqvqGskV/4= sha1:sFSSbWF8ry1gwtA6qfKstFVvY60= sha256:yMqFFKq3Kk20XIxfSIWG7M/CtaPJon99qKLSPLiIGl0= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id DD28D125E18; Tue, 24 Nov 2026 17:40:05 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6T4YfyW_TFMA; Tue, 24 Nov 2026 17:40:01 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-370463-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id ED989125E1B; Tue, 24 Nov 2026 17:39:50 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 822D73551F; Tue, 24 Nov 2026 14:39:41 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795531177; b=UoDeQXkWQSCbQOMOicXKM0KK0Tn/tpu+Biq6a5Ub8piO5aGk7tY5UAcZkgvWV51nDIFT WPYhAuLJAMytBjVDmLdn7WPTMNjkreGsQn0zJEkmU+/KHyfR3lWM+Kp4CvT/X+EOX24s1 wOIbn5c5H7u3xQL4ZsBTDHKOOI2T0O24Nu3dMgW9r95DoKp+DzlhSptdz/7BXvBOnlsjk e4Mh8nyE31/IEFQ33ezmFtHWUa+V7jXyOZcNBCOIRqEMu604+ptRmL5PsF46CAuIizSGs UxZNzWkwWxgt6AX6V7Pn9zhNDV8bRapiZiezOg20N9KpqtlYktt1yw13miV08d9idlw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795531177; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=VlECLQyycXDLKhXmEjfVRoGtIagJQTFXqDYssZCUVjo=; b=NENEoyfBnMB2LSVlh5DTkCq6rwtvvS3YMI9ebvo76Szf8m+5OZ8WHnk+UILmYtndaL81 LF79gFaiM8aX22AI53vk+E5gKe5bzd060GuCoqlZLQKmbDvmEEfdgfYsHaDZvbHmG0kUb 2GaJORlmf2lvlL6AXhGldJ8dlkc/II/wFBQuEaya061GFhYx/m1U3hH3dfksdMJBZvm+c vtHePAmMDkehdAHK/vcTb9C6FdR1NE2Kdebwo9c/bDU6PnfFpWTrw0n0D7ISbXx3R6x6b msiAVTTLrVcp5D6i5Sfo7oCh0lGnRrVRQTtKoNqMa5NXRx1eNO7xiUfuT3h7S3ifFfw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IleNeSVx; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CE783606A686; Tue, 24 Nov 2026 14:39:37 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IleNeSVx X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795531177; b=Fqt8/xFL8DSaKLIXbbhBjavGgHKjOH9IZ2phitDW3KJ/KKHjv27nmP3liUawLv95Xs5S Z5l8/rakxy8iahpEMRWNW6079zWxsWTKacg05A9r8QYqkBGh8iXz83pIvhGdol6pVqifp 9SZOT4jiJvgWkVF9+aebU69DMzVOYalF9NfaKe9XPYSZbsK98lZ6zKivl7DLkZqOqDH1o wjdW+i94w9+CVHPFQHuikZYqL5psxMzHPzvN8Ffg8+dAofuptNuLTYkzz5A3KxWkWhclx 8fx1wZsHk8XAnJSCQwan1OwVapHLojh97zlhemhLT/RaDwXMemMski65jyzqX7Is8DQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795531177; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=VlECLQyycXDLKhXmEjfVRoGtIagJQTFXqDYssZCUVjo=; b=AIb5gz+BlANnP6CZa7n9f/e2yZDDAuUYKCc3tkfIBIM97zG2XF6i68HCKlk4SGJq8Gvs ujtJwGe0ixo+GfCf3eT3pk/m11V8UkPwS4MV4L4wYSJiXJpxBsKLOUFAEoZbH/piRtT/G x9o7ibiWXjCIhNjEoweg7mJtA9Yeg7Z68iXLt4OXI2ic3LrKSVfMuV62/b6xmgP4Bjj3X jUuJu2Moz+6z+jJgstMGVF3PBiJ/szqYjaySxfH2fHMVVszGnyi8i65Jiy18W5mhAGfma vgtzJvBnikscxyYTyIkkW2qz+LtZsR+wVb3zuYLpcShVeVVbf1L5LJRohGdqlGlNAOw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IleNeSVx; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFA4D606A339; Tue, 24 Nov 2026 14:39:36 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6EC91F000C4; Tue, 24 Nov 2026 14:39:35 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795531176; bh=VlECLQyycXDLKhXmEjfVRoGtIagJQTFXqDYssZCUVjo=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=IleNeSVxBgUsHifP3WvtxicmHrm2dpvlaXnii5sBrRv/8+rIs1PrJdxwajHwljcD/ c8qSpsFfYO3zrR0SwIMe5SdTK6i3y2tWYX/NRe911nxgJbALv38XSziBIZnpzshE4Y z4/BPcHj2SvLD5cIRCtlR3pJUxahoiwn2oUHZUQ3rr12MUdYqcaO6mW711gztDc3s0 tpBOssYjzbxJCfwzHmrGGtGay//bcK2Q5tfpWj7a68CXUyGX3GrRz16IR0TyCk+tJX C6YKgJATGxlQCiYAuJ9k1Re0C8jvNjjVSXoxEQrK6EPULiiuXKPHiOR5dFjIoA6Y// D3lLdgcvBiqMw== X-Cc: netfilter-devel@vger.kernel.org, davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com, edumazet@kernel.org, horms@kernel.org, fw@strlen.de, ja@ssi.bg X-In-Reply-To: <20261123135726.3940688-7-pablo@netfilter.org> X-sashiko-severity: Critical X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list