All of lore.kernel.org
 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 06/10] netfilter: conntrack: limit master chain depth
Date: Tue, 01 Dec 2026 22:45:22 +0000	[thread overview]
Message-ID: <179616512219.3146.18170714509207765392@kernel.org> (raw)
In-Reply-To: <20261130215141.1009148-7-pablo@netfilter.org>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] This patch makes nf_ct_expect_alloc() return NULL for a permanent
  reason: nf_ct_master_acceptable(me) fails when the conntrack already…

--

netfilter: conntrack: limit master chain depth

This commit caps the ct->master chain depth at 8 levels.
nf_ct_expect_alloc() now refuses to allocate an expectation once the
master chain is too deep. A ctnetlink_find_get_master() helper performs
the same check for ctnetlink conntrack and expectation creation, and
returns -EMLINK.

> diff --git a/net/netfilter/nf_conntrack_expect.c b/net/netfilter/nf_conntrack_expect.c
> index 06242c86e1dc8..62e434cd57c9f 100644
> --- a/net/netfilter/nf_conntrack_expect.c
> +++ b/net/netfilter/nf_conntrack_expect.c
> @@ -299,13 +299,22 @@ void nf_ct_unexpect_related(struct nf_conntrack_expect *exp)
>  }
>  EXPORT_SYMBOL_GPL(nf_ct_unexpect_related);
>  
> -/* We don't increase the master conntrack refcount for non-fulfilled
> - * conntracks. During the conntrack destruction, the expectations are
> - * always killed before the conntrack itself */
> +/**
> + * nf_ct_expect_alloc - allocate a new conntrack expectation
> + * @me: The conntrack to be used as master.
> + *
> + * The master conntrack refcount is not incremented; expectations
> + * are always killed before the master conntrack is destroyed.
> + *
> + * Return: a new expectation on success or NULL on failure.
> + */
>  struct nf_conntrack_expect *nf_ct_expect_alloc(struct nf_conn *me)
>  {
>  	struct nf_conntrack_expect *new;
>  
> +	if (!nf_ct_master_acceptable(me))
> +		return NULL;
> +

[Severity: Low]

With this change, nf_ct_expect_alloc() also returns NULL for a permanent
condition: the master already has 8 or more ancestors. Callers can't tell
this apart from a transient GFP_ATOMIC failure, and the kernel-doc above
still only says "NULL on failure".

Every in-tree caller treats NULL as out of memory, and most of them drop
the packet. For example, help() in nf_conntrack_ftp.c does this:

	exp = nf_ct_expect_alloc(ct);
	if (exp == NULL) {
		nf_ct_helper_log(skb, ct, "cannot alloc expectation");
		ret = NF_DROP;

Other callers follow the same pattern:

  - irc, tftp, amanda, sane and sip process_register_request() do the
    same thing.
  - sip set_expected_rtp_rtcp() jumps to err1 while ret is still NF_DROP.
  - The h323 expect_*() helpers, including expect_callforwarding(),
    return -1. That turns into goto drop / NF_DROP in q931_help(),
    h245_help() and ras_help().

nft_ct_expect_obj_eval() also drops here:

	exp = nf_ct_expect_alloc(ct);
	if (!exp)
		return NF_DROP;

That function returns NF_ACCEPT when nf_ct_expect_related() fails.

ct->master is fixed when the conntrack is created. Once a conntrack hits
the depth limit, won't every packet that tries to create an expectation
be dropped, retransmissions included?

The commit message says this "restricts the number of call
forward/redirects that h323 and sip helpers will follow". It looks like
the 8th h323 call forward, or SIP SDP on a deeply nested ct, would break
the session rather than the helper just not following it. The helper log
would also report "cannot alloc expectation" as the reason.

Separately, the commit message says:

  For too long chains, ctnetlink returns -ENOMEM when creating long master
  chains through expectations, ...

Is that still accurate? ctnetlink_create_expect() now calls
ctnetlink_find_get_master() first and returns -EMLINK in this case. Only
the nfqueue glue path, ctnetlink_glue_attach_expect() ->
ctnetlink_alloc_expect(), would still return -ENOMEM.

>  	new = kmem_cache_zalloc(nf_ct_expect_cachep, GFP_ATOMIC);
>  	if (!new)
>  		return NULL;

[ ... ]

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

  reply	other threads:[~2026-12-01 22:45 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 21:51 [PATCH net,v2 RESEND 00/10] Netfilter fixes for net Pablo Neira Ayuso
2026-11-30 21:51 ` [PATCH net 01/10] netfilter: conntrack: prevent helper extension relocation Pablo Neira Ayuso
2026-11-30 21:54   ` netdev-bot+sinfo
2026-11-30 21:56     ` Pablo Neira Ayuso
2026-12-01 22:10   ` patchwork-bot+netdevbpf
2026-12-01 22:45   ` netdev-bot+sashiko
2026-11-30 21:51 ` [PATCH net 02/10] netfilter: xt_IDLETIMER: restrict to init_net Pablo Neira Ayuso
2026-11-30 21:51 ` [PATCH net 03/10] netfilter: synproxy: prevent unbounded recursion in transmit path Pablo Neira Ayuso
2026-11-30 21:51 ` [PATCH net 04/10] netfilter: conntrack: wait for RCU readers before freeing the hash Pablo Neira Ayuso
2026-11-30 21:51 ` [PATCH net 05/10] netfilter: nft_synproxy: only handle pure SYN and ACK packets Pablo Neira Ayuso
2026-11-30 21:51 ` [PATCH net 06/10] netfilter: conntrack: limit master chain depth Pablo Neira Ayuso
2026-12-01 22:45   ` netdev-bot+sashiko [this message]
2026-11-30 21:51 ` [PATCH net 07/10] netfilter: conntrack: skip unconfirmed entries in /proc/net/nf_conntrack Pablo Neira Ayuso
2026-11-30 21:51 ` [PATCH net 08/10] netfilter: bridge: detach conntrack template on invalid IP frames Pablo Neira Ayuso
2026-12-01 22:45   ` netdev-bot+sashiko
2026-11-30 21:51 ` [PATCH net 09/10] netfilter: synproxy: fix double tsoff application in server ACK TSecr Pablo Neira Ayuso
2026-11-30 21:51 ` [PATCH net 10/10] netfilter: nf_tables: only disable tables on a dormant transition Pablo Neira Ayuso
  -- strict thread matches above, loose matches on Subject: below --
2026-11-30 21:25 [PATCH net,v2 00/10] Netfilter fixes for net Pablo Neira Ayuso
2026-11-30 21:25 ` [PATCH net 06/10] netfilter: conntrack: limit master chain depth 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=179616512219.3146.18170714509207765392@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.