From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.netfilter.org (mail.netfilter.org [217.70.190.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C95B3C9893; Tue, 23 Jun 2026 22:16:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.190.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782252977; cv=none; b=LJdaMVgoqOww43+K+3yKAWl4nzhWiy7NbdKg7BOZ20j/mBRVXiY8SIRNg0Dx6XOFtWkgRrxqBjcpfKa9oNa6ntUETXNW6PKeSpX/i/S2i1CDoRCRT4iwBeeKGfVpRsQmystFab3GFIRrk1eVVeA4QYAYisOYQuMn4O+d6bbdPn0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782252977; c=relaxed/simple; bh=aA431i9XHRwdlz8EXIoj3qjcwhsOtUVntti4s7Sj03g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uN93MToZ5yyoDXPqNFNmbhpWa9f+G6dZRNAf1cpnQ7OMnUZQjIaot/RMszeHrx77BqEVRlUutXobas0w61ZEPPtQf29deBJiI3rObiGsytpT7K+FP6/I1z2yx95hZG8T0I+hrfGKYyGU5IVSzPFejCxluCjrDuvGCgtFDiXZbcY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org; spf=pass smtp.mailfrom=netfilter.org; dkim=pass (2048-bit key) header.d=netfilter.org header.i=@netfilter.org header.b=W6HL6ici; arc=none smtp.client-ip=217.70.190.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=netfilter.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=netfilter.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=netfilter.org header.i=@netfilter.org header.b="W6HL6ici" Received: from localhost.localdomain (mail-agni [217.70.190.124]) by mail.netfilter.org (Postfix) with ESMTPSA id 9632D60578; Wed, 24 Jun 2026 00:16:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netfilter.org; s=2025; t=1782252971; bh=8VfnkJwQXW/HFVNgcjfeUuskYH2HnWdXcjQVzz2LOa8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W6HL6iciUkQedLDsERjpIYM8Bri4Xexj1/vg4VYpvNZ95XXYLAiQRhhnkAPKHHVYZ a7qm/m+pCsWTjvYp69E8AWxXDN50N+mtC69PN7JDaz0LGAsL1vDI3jTwKTyIabzHAH RaX3pLbnOVB1X90yaFgJmiaDSezIOssl2LFR7Cvw2zwzoutdB/wM5/Kj7rATQeZTmx AU2U7SlHYy3UWYm2Eu+IxbPtSLM2ByUJFELmXJutU+cMjy5kQ/1IKG3l+/z6FlK5dJ hIfVb2gfkdYxQ0GBT4VXfV0fE8jJmRBUo/4S+QGSfZf0YNLSW2RrFZpLnuLt9Zn1FE FQe/bAnob+SMg== From: Pablo Neira Ayuso To: netfilter-devel@vger.kernel.org Cc: davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com, edumazet@google.com, fw@strlen.de, horms@kernel.org Subject: [PATCH net 14/14] netfilter: nf_conntrack_helper: cap maximum number of expectation at helper registration Date: Wed, 24 Jun 2026 00:15:47 +0200 Message-ID: <20260623221548.701545-15-pablo@netfilter.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260623221548.701545-1-pablo@netfilter.org> References: <20260623221548.701545-1-pablo@netfilter.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On helper registration, the maximum number of expectations cannot go over NF_CT_EXPECT_MAX_CNT (255), but zero can be specified then nf_conntrack_expect_max applies. Turn zero into NF_CT_EXPECT_MAX_CNT otherwise, expectation LRU eviction on insertion is disabled. Moreover, expand this sanity check all expectation classes. This max_expecy policy is only tunable since userspace helpers are available, set Fixes: tag to the commit that adds such infrastructure. Remove the check for p->max_expected given this field must always be non-zero after this patch. Fixes: 12f7a505331e ("netfilter: add user-space connection tracking helper infrastructure") Signed-off-by: Pablo Neira Ayuso --- net/netfilter/nf_conntrack_expect.c | 3 +-- net/netfilter/nf_conntrack_helper.c | 9 +++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/net/netfilter/nf_conntrack_expect.c b/net/netfilter/nf_conntrack_expect.c index 113bb1cb1683..38630c5e006f 100644 --- a/net/netfilter/nf_conntrack_expect.c +++ b/net/netfilter/nf_conntrack_expect.c @@ -496,8 +496,7 @@ static inline int __nf_ct_expect_check(struct nf_conntrack_expect *expect, lockdep_is_held(&nf_conntrack_expect_lock)); if (helper) { p = &helper->expect_policy[expect->class]; - if (p->max_expected && - master_help->expecting[expect->class] >= p->max_expected) + if (master_help->expecting[expect->class] >= p->max_expected) evict_oldest_expect(master_help, expect, p); } else { const struct nf_conntrack_expect_policy default_exp_policy = { diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c index 8b94001c2430..500509b17663 100644 --- a/net/netfilter/nf_conntrack_helper.c +++ b/net/netfilter/nf_conntrack_helper.c @@ -374,8 +374,13 @@ int __nf_conntrack_helper_register(struct nf_conntrack_helper *me) if (!nf_ct_helper_hash) return -ENOENT; - if (me->expect_policy->max_expected > NF_CT_EXPECT_MAX_CNT) - return -EINVAL; + for (i = 0; i <= me->expect_class_max; i++) { + if (!me->expect_policy[i].max_expected) + me->expect_policy[i].max_expected = NF_CT_EXPECT_MAX_CNT; + + if (me->expect_policy[i].max_expected > NF_CT_EXPECT_MAX_CNT) + return -EINVAL; + } mutex_lock(&nf_ct_helper_mutex); for (i = 0; i < nf_ct_helper_hsize; i++) { -- 2.47.3