Netdev List
 help / color / mirror / Atom feed
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 03/15] netfilter: conntrack: refactor helper call logic in nf_confirm()
Date: Tue, 24 Nov 2026 14:39:30 +0000	[thread overview]
Message-ID: <179553117043.3135.12759318924641866063@kernel.org> (raw)
In-Reply-To: <20261123135726.3940688-4-pablo@netfilter.org>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

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).

- [Medium] The patch makes nf_ct_call_helper()/nf_confirm_get_protoff()
  the central place for helper and seqadj invocation and protoff…
- [Low] The new kernel-doc for nf_ct_call_helper() says it "calls the l4
  connection tracking helper (e.g. ftp, sip...) if one was assigned to…

--

netfilter: conntrack: refactor helper call logic in nf_confirm()

This splits nf_confirm() into two parts. nf_confirm_get_protoff() computes
the L4 offset for IPv4/IPv6, and nf_ct_call_helper() decides whether to
run the conntrack helper and/or TCP sequence adjustment. The drop counter
is now bumped in nf_confirm() for any NF_DROP verdict, and followup patches
are meant to add stricter checks to the new functions.

> diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
> index 7a40e4e0e33e6..32f900c155de8 100644
> --- a/net/netfilter/nf_conntrack_proto.c
> +++ b/net/netfilter/nf_conntrack_proto.c

[ ... ]

> @@ -169,16 +149,56 @@ unsigned int nf_confirm(void *priv,

[ ... ]

> +/**
> + * nf_ct_call_helper() - Invoke the connection tracking helper for a packet
> + * @skb:    The socket buffer containing the packet to be processed.
> + * @ct:     The connection tracking entry associated with this packet.
> + * @ctinfo: The current connection track information (state) of the packet.
> + *
> + * This function calls the l4 connection tracking helper (e.g. ftp, sip...) if
> + * one was assigned to the connection.

[Severity: Low]
This isn't a bug, but should this kernel-doc also mention sequence
adjustment? If there is no helper but IPS_SEQ_ADJUST_BIT is set,
nf_ct_call_helper() gets past this check:

	if (!help && !seqadj_needed)
		return NF_ACCEPT;

It can then mangle the packet or return NF_DROP by itself:

	if (seqadj_needed &&
	    !nf_ct_seq_adjust(skb, ct, ctinfo, protoff))
		return NF_DROP;

The new nf_confirm() kernel-doc also lists only helper invocation and
confirmation, and leaves out seqadj. This is still the case at the end of
the series, where nf_ct_helper() has been converted to call this function.

> + *
> + * Return: verdict (NF_ACCEPT, NF_DROP, ...)
> + */
> +int nf_ct_call_helper(struct sk_buff *skb, struct nf_conn *ct,
> +		      enum ip_conntrack_info ctinfo)
> +{

[ ... ]

> +	/* helper->help() do not expect ICMP packets */
> +	if (ctinfo == IP_CT_RELATED_REPLY)
> +		return NF_ACCEPT;
> +
> +	if (!nf_confirm_get_protoff(skb, net, ct, ctinfo, &protoff))
> +		return NF_ACCEPT;

[Severity: Medium]
nf_ct_call_helper() and nf_confirm_get_protoff() are now the central place
for helper/seqadj invocation. Should nf_confirm_cthelper() in
net/netfilter/nf_conntrack_core.c go through them as well?

It runs for every accepted nfqueue verdict:

nfqnl_reinject()
  ct_hook->update()
    nf_conntrack_update()
      nf_confirm_cthelper()
        nf_ct_seq_adjust()

It still open-codes the old protoff calculation:

net/netfilter/nf_conntrack_core.c:nf_confirm_cthelper() {
    ...
	case NFPROTO_IPV4:
		protoff = skb_network_offset(skb) + ip_hdrlen(skb);
		break;
    ...
		protoff = ipv6_skip_exthdr(skb, sizeof(struct ipv6hdr), &pnum,
					   &frag_off);
    ...
	if (test_bit(IPS_SEQ_ADJUST_BIT, &ct->status) &&
	    !nf_is_loopback_packet(skb)) {
		if (!nf_ct_seq_adjust(skb, ct, ctinfo, protoff)) {
    ...
}

This path has no IP_CT_RELATED_REPLY filter, no IPv4 fragment check, and
no L4 protocol, tuple or TCP doff check. The IPv6 case also lacks the
nhoff that the later hardening adds.

Two followups add those checks: "netfilter: conntrack: verify L4 protocol
before calling helper" and "netfilter: conntrack: harden helper invocation
with tuple revalidation". Both put them only inside
nf_confirm_get_protoff() and nf_ct_call_helper().

"netfilter: conntrack: replace open-coded helper invocation" converts
nf_ct_helper() in nf_conntrack_ovs.c. The nfqueue reinject copy is still
not converted at the end of the series.

Can nf_ct_seq_adjust() then rewrite tcph->seq, ack_seq, check and the SACK
blocks at a non-TCP offset? Take a conntrack that has a userspace cthelper
(NF_CT_HELPER_F_USERSPACE) and IPS_SEQ_ADJUST_BIT set. Two cases look
reachable:

  - an ICMP error (IP_CT_RELATED or IP_CT_RELATED_REPLY) related to the
    flow that matches a queue rule

  - a packet whose L3/L4 headers userspace rewrote through NFQA_PAYLOAD

The writes stay in bounds because nf_ct_seq_adjust() and
nf_ct_sack_adjust() call skb_ensure_writable(). The result would be a
corrupted packet, not corrupted memory.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123135726.3940688-2-pablo%40netfilter.org

  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 [this message]
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
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 03/15] netfilter: conntrack: refactor helper call logic in nf_confirm() 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=179553117043.3135.12759318924641866063@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