🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #11004

Re: [PATCH net 06/15] netfilter: nf_conntrack: limit expectation master chain depth

#11004
From: netdev-bot+sashiko
Date: Wed, 04 Nov 2026 14:29
173 lines
14180 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

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

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

- [High] The new global limit NF_CT_MAX_EXPECT_CHAIN_LEN = 2, enforced by
  nf_ct_master_acceptable() inside nf_ct_expect_alloc(), is lower than…
- [Low] The commit message says only that the patch 'prevents unbounded
  ct->master->master->... chains'.
- [Low] The commit message describes ctnetlink_find_get_master() as
  making 'ctnetlink create paths return -EMLINK instead of falling…

--

netfilter: nf_conntrack: limit expectation master chain depth

This commit adds nf_ct_master_acceptable(), which walks the ct->master
chain. It is called from nf_ct_expect_alloc() so that no expectation can
be created once the chain reaches NF_CT_MAX_EXPECT_CHAIN_LEN (2). The
commit also adds ctnetlink_find_get_master(), so the ctnetlink create
paths reject such masters with -EMLINK.

> Also add ctnetlink_find_get_master and use it so that ctnetlink create
> paths return -EMLINK instead of falling through to nf_ct_expect_alloc()
> and returning a misleading -ENOMEM.

[Severity: Low]
Is this description accurate for ctnetlink_create_conntrack()? That path
never reaches nf_ct_expect_alloc(). For CTA_TUPLE_MASTER it assigns the
master directly:

net/netfilter/nf_conntrack_netlink.c:ctnetlink_create_conntrack() {
    ...
		__set_bit(IPS_EXPECTED_BIT, &ct->status);
		ct->master = master_ct;
    ...
}

So on that path, the check in ctnetlink_find_get_master() is the only
depth enforcement. It does more than fix an errno.

Could the commit message say this, so the hunk isn't read as cosmetic?

The misleading -ENOMEM also remains for the other nf_ct_expect_alloc()
callers, because a NULL return now means either OOM or depth rejection:

- ctnetlink_alloc_expect() still maps NULL to ERR_PTR(-ENOMEM). It is
  also reached from ctnetlink_glue_attach_expect() (nfqueue NFQA_EXP),
  which has no -EMLINK pre-check. nfqnl_ct_parse() ignores that return
  value, though.
- The ftp, irc, sane, tftp, amanda and sip helpers log "cannot alloc
  expectation" and return NF_DROP.
- nft_ct_expect_obj_eval() returns NF_DROP.

> This prevents unbounded ct->master->master->... chains.

[Severity: Low]
Should the commit message say what an unbounded chain leads to?
nf_ct_destroy() releases the master before it frees the ct, so the
release is not a tail call:

net/netfilter/nf_conntrack_core.c:nf_ct_destroy() {
    ...
	if (ct->master)
		nf_ct_put(ct->master);

	nf_conntrack_free(ct);
}

Suppose the masters have already left the hash table and each child
holds the last reference to its master. Freeing the leaf then recurses
nf_ct_put()->nf_ct_destroy()->nf_ct_put()... once per level.

Before this patch, only nf_conntrack_max bounded the depth. There are
two ways to build a long chain:

- ctnetlink CTA_TUPLE_MASTER, which needs CAP_NET_ADMIN (available
  inside a user namespace).
- Q.931 call forwarding from the network. expect_callforwarding() has
  no loop guard, unlike process_gcf().

This looks like a fix for kernel stack exhaustion, and it has a
Reported-by. Should it also carry a Fixes: tag and Cc: stable? The other
netfilter fixes in this batch carry Fixes: tags. Backporters would also
want to know about the H.323 behaviour change described below.

> diff --git a/include/net/netfilter/nf_conntrack_helper.h b/include/net/netfilter/nf_conntrack_helper.h
> index 335b8c43694f8..617178fd4d8bc 100644
> --- a/include/net/netfilter/nf_conntrack_helper.h
> +++ b/include/net/netfilter/nf_conntrack_helper.h
> @@ -29,6 +29,8 @@ enum nf_ct_helper_flags {
>  
>  #define NF_CT_HELPER_NAME_LEN	16
>  
> +#define NF_CT_MAX_EXPECT_CHAIN_LEN	2
> +
>  /* Must be kept in sync with the classes defined by helpers */
>  #define NF_CT_MAX_EXPECT_CLASSES	4
>  
> @@ -159,6 +161,19 @@ static inline void nf_ct_help_put(const struct nf_conn *ct)
>  		kfree_rcu(helper, rcu);
>  }
>  
> +static inline bool nf_ct_master_acceptable(const struct nf_conn *m)
> +{
> +	unsigned int depth = 0;
> +
> +	while (m->master) {
> +		if (++depth >= NF_CT_MAX_EXPECT_CHAIN_LEN)
> +			return false;
> +		m = m->master;
> +	}
> +
> +	return true;
> +}

[Severity: High]
Is a limit of 2 enough for the in-tree H.323 helper? With this check, a
ct that has a grandmaster can no longer create expectations. Normal
gatekeeper operation builds a deeper chain than that:

RAS ct
  expect_q931() / process_acf() / process_lcf()  (assign_helper = q931)
Q.931 ct (master = RAS, set by init_conntrack())
  expect_h245()  (assign_helper = h245)
H.245 ct (master = Q.931, grandmaster = RAS)

Now suppose the H.245 ct sees an OpenLogicalChannel:

h245_help()
  process_h245()
    process_olc()
      process_h245_channel()
        expect_rtp_rtcp() / expect_t120()
          nf_ct_expect_alloc(H.245 ct)
            nf_ct_master_acceptable() -> false

expect_rtp_rtcp() then fails:

	if ((rtp_exp = nf_ct_expect_alloc(ct)) == NULL)
		return -1;

and h245_help() drops the packet:

      drop:
	spin_unlock_bh(&nf_h323_lock);
	nf_ct_helper_log(skb, ct, "cannot process H.245 message");
	return NF_DROP;

Wouldn't this drop the H.245 OLC packets of gatekeeper-admitted calls?
RTP, RTCP and T.120 would then never get expectations.

The GCF case fails one level earlier. In process_gcf(), a discovery RAS
ct expects a registration RAS ct. The helper already bounds this
recursion itself ("Avoid RAS expectation loops").

If the registration RAS then expects Q.931, that Q.931 ct already has
two ancestors. Its expect_h245() and fastStart process_olc() calls fail,
and q931_help() returns NF_DROP with "cannot process Q.931 message".

Does the bound need to be at least 3, or 4 for the GCF plus H.245 plus
RTP case? Or could the limit apply only to the self-recursive cases,
such as Q.931 to Q.931 call forwarding via expect_callforwarding()?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261103140308.591690-3-pablo%40netfilter.org
Technical Details
Message-ID: <179380256479.488856.1820572025839621863@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356503-linux-kernel-netdev=dewy.ru
References: <20261103140308.591690-8-pablo@netfilter.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356503-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 06/15] netfilter: nf_conntrack: limit expectation
 master chain depth
Date: Wed, 04 Nov 2026 14:29:24 +0000
Organization: Usenet Network
Message-ID: <179380256479.488856.1820572025839621863@kernel.org>
References: <20261103140308.591690-8-pablo@netfilter.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3409215"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:+SQMeIK2EODgfc04NlK3r+GLc2g= sha256:6s/4OgRpWCdAVX88Z7lKfrPHcD3vld4Z7tlbGBynPzc=
	sha1:L/vZhketrxWAa9iyjLOW8SewYwQ= sha256:6Z3Cym/BmgsWb7ohChnSF4Kw/UHXWWDobpZ3jtYKoGI=
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 D968E112C08; Wed,  4 Nov 2026 17:33:57 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 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, URIBL_BLOCKED=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 GxJjxsGUT6bL;
	Wed,  4 Nov 2026 17:33:53 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-356503-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 8AD1B112C01; Wed,  4 Nov 2026 17:33:45 +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 C2DE73014F; Wed,  4 Nov 2026 14:29:27 +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=1793802567;
	b=EG0V6mzWE+/BYQ+JP7WK0MvisTJmBn859XT7UE6b408uAUVZQs3kw6HIqGne+cQuk2RG
	 zI4SM+wiaiVNsiY33fLebwF8Z0+xT4yIaPhRqL8CC1gdWDejjApsMOWacfNvLzrWZ9qVp
	 wyNAqh+Zmx6cCZkenO0vClVbkJzD8KG7XpSc3zGDPohaxgLI5GUyuuv8YQ9okADZmnNIg
	 Py2UD6daZwReRUN16t8L6VgB4DAI9H7V9rLYz0qMmvw5BimND+WCtbDWPD39bCyYzZeu/
	 NilO456Q/mj1I+1FxW0MF3TYks8dUKD761GO/QBSwfQSO5vplndKmbS96kzsOkCxOPw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793802567;
	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=z3YCQFJFWGrmSKahPQO8CiOfaeEGUDYud9eigNpfAnY=;
	b=aUrwUluS8Ldgdt2vt0d8BjwryX1i+5Ovudw5ufGEYoPXOg0EK7eRHV5bC1mWjNy5E2m1
	 mZp95k7JTyR0Gj6CQ8TfBQcMhxuq04k424K1Pt9wXkkk/gQXGifV9dbLy7+9Tq5dJmNUA
	 v69xAeNecnvBt9+8wVUJafr8fkVoTIrjDo36oKFRqx2AeD4rpPsFP1qeHCHyn9tUuJ3Xv
	 oDob/ENEX5UM+wLtik3IAUTdIlk9sVg9Wt+Rf8uERBP+O4C40u8ynFWSPPuFyHLPc3Vru
	 nqOsvmoRJAv4oLbcqCfgAyd4OomoJEG1PWKfg1RBV0u0KXeamDyIsj8vfij6HJpq8Qg==
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=Wz8axLqu;
	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 18EFF606A332;
	Wed,  4 Nov 2026 14:29:27 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Wz8axLqu
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=1793802566;
	b=od66h8V5IxJcXC4Psbwc7Il9AXDdExQr20SUVPeC3rG8BjQdumNPcBPQgmwKfCHHFG1K
	 C3Vsj3SS60pezy9CdhLrLdiu8Usb8I9kcQAk9qkXCwirpLewnJave04Av//hCje+x4Hlg
	 8LiPGQHDgpGjLjDSgSW90hMGY8T1d75IzOLe1rIcnr10aeZg5RaqA3ek/4DnMGIOBKpni
	 4dez3IhBvDiMtkL7QbinObt2e+x97LZuGEQ5ZahY6wXOLbR3QB1e84CUWhGm169JlimXh
	 gEaasMZ5FYfYSD7F8PGICTjGWjhKV7PWx2LKV3TYWR4cMuAFuDCJcldoLHWvrVZ0l0g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793802566;
	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=z3YCQFJFWGrmSKahPQO8CiOfaeEGUDYud9eigNpfAnY=;
	b=rCCj2YuKhNF7/7eWbKFz8qxQ+yoXn7ZtSIij89tbiYNt/uJRSu5iWRUGVJp0whZsZDrs
	 RWKfxLoQtCMonqNF1u8nnhFlG3lL3P+05KCQKVr42vGZ0pPIC57T8ve/kKDa2FKoDHtAq
	 oZCILmqMG+upBes3A28+N7O6jGjUq8ns2jXGK6XWHRDgKbBA3hV9GVHTlkrZlkeoq+bHM
	 GwgsOhjOgA8E0nuvpINEqOC/B/Ea3tocrvgC38btlXsdqzF3UyVrSE6wtgK2xZk9AKshQ
	 sXx+Us38QJxSfyJmGWypzMJj4Vs0o9UC9DedpJHFMNyBTk++5AJ+VGuX+LnR4xb11Mg==
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=Wz8axLqu;
	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 E97DE606A32E;
	Wed,  4 Nov 2026 14:29:25 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CF761F00A02;
	Wed,  4 Nov 2026 14:29:25 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793802565;
	bh=z3YCQFJFWGrmSKahPQO8CiOfaeEGUDYud9eigNpfAnY=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=Wz8axLquisUvBrqO/qlAphPlBIBt3lk4/ZmPWu2ObWlP4XZpTrFMYMEbQCcYmgsU3
	 jy/yEir9gy2CaXgav/JLAkKtVqnOIILTfTy9Rx5Lfbkw+cW6VEAqVbR3dHvT2w2yPQ
	 ffC/5j6SOsBAREq0fI2fkweSzAd2pw2gYijEYWNaBDFvUP0g1Yl3UfPkQDuuCZXU1j
	 MIFPX3tGYjVMaHjqxDTymhh07p6kWQr+GeG3vSiRoYF0ciV69rwZkTcheg4QZYuBup
	 1GphqF2W1A9vZDRXQMoMFlt/lBBew4anBvydol6cQ59ysZC4b31SYBnw0NKVHa5pge
	 DY6LkDaYozvUw==
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: <20261103140308.591690-8-pablo@netfilter.org>
X-sashiko-severity: High
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