From: netdev-bot+sashiko@kernel.org
To: pablo@netfilter.org
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
Subject: Re: [PATCH net-next 06/15] netfilter: conntrack: harden helper invocation with tuple revalidation
Date: Tue, 24 Nov 2026 14:39:35 +0000 [thread overview]
Message-ID: <179553117549.3135.4393332546290332600@kernel.org> (raw)
In-Reply-To: <20261123135726.3940688-7-pablo@netfilter.org>
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
next prev parent reply other threads:[~2026-11-24 14:39 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 13:57 [PATCH net-next,v2 00/15] Netfilter updates for net-next Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 01/15] netfilter: conntrack: prevent nf_conntrack_buckets race condition Pablo Neira Ayuso
2026-11-23 14:02 ` netdev-bot+sinfo
2026-11-23 14:17 ` Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 02/15] netfilter: conntrack: validate skb->_nfct and packet headers Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 03/15] netfilter: conntrack: refactor helper call logic in nf_confirm() Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 04/15] netfilter: conntrack: verify L4 protocol before calling helper Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 05/15] netfilter: conntrack: replace open-coded helper invocation Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 06/15] netfilter: conntrack: harden helper invocation with tuple revalidation Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko [this message]
2026-11-23 13:57 ` [PATCH net-next 07/15] netfilter: nft_ct: validate timeout object protocol Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 08/15] netfilter: nft_synproxy: only handle pure SYN and ACK packets Pablo Neira Ayuso
2026-11-23 13:57 ` [PATCH net-next 09/15] netfilter: nft_ct: validate hook and priority for ct zone set Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 10/15] rhashtable: Add rhashtable_flush_and_free helper Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 11/15] netfilter: ipset: add rhashtable boilerplate stubs Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 12/15] netfilter: ipset: replace internal hash table with rhashtable Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 13/15] netfilter: ipset: also report mem size for cidr storage to userspace Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 14/15] netfilter: ipset: re-add IP_SET_HASH_WITH_MULTI support Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-23 13:57 ` [PATCH net-next 15/15] netfilter: ipset: re-add forceadd support Pablo Neira Ayuso
2026-11-24 14:39 ` netdev-bot+sashiko
2026-11-24 12:27 ` [PATCH net-next,v2 00/15] Netfilter updates for net-next Paolo Abeni
2026-11-24 12:36 ` Florian Westphal
2026-11-24 13:47 ` Paolo Abeni
2026-11-24 13:33 ` Pablo Neira Ayuso
2026-11-24 13:43 ` Paolo Abeni
-- strict thread matches above, loose matches on Subject: below --
2026-11-23 13:54 [PATCH net-next " Pablo Neira Ayuso
2026-11-23 13:54 ` [PATCH net-next 06/15] netfilter: conntrack: harden helper invocation with tuple revalidation Pablo Neira Ayuso
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=179553117549.3135.4393332546290332600@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=fw@strlen.de \
--cc=horms@kernel.org \
--cc=ja@ssi.bg \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--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