🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #19386

Re: [PATCH net] netfilter: ipset: exclude add-path GC during resize

#19386
From: netdev-bot+sashiko
Date: Thu, 19 Nov 2026 21:27
176 lines
14619 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 1 · High: 0 (1) · Medium: 0 · 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).

- [Critical] The fix is incomplete.
- [Low] The commit carries `Cc: stable@vger.kernel.org` and `Fixes:
  f66ee0410b1c`, a 2020 commit, so stable maintainers will try to apply…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but a successful
  resize leaks the comment extensions of elements that had already…

--

netfilter: ipset: exclude add-path GC during resize

This patch takes h->gc.lock around the direct mtype_gc_do() call in
mtype_add() and skips the collection when the pinned table has resizing
set. The goal is to keep the packet-side add path from freeing extensions
of old-table elements that mtype_resize() has already copied into the new
table.

> Fixes: f66ee0410b1c ("netfilter: ipset: Fix "INFO: rcu detected stall in hash_xxx" reports")
> Cc: stable@vger.kernel.org

[Severity: Low]
The new code uses h->gc.lock and t->resizing. Both were added by
cffcf57bf03c ("netfilter: ipset: exclude gc when resize is in progress"),
which has no Fixes: or Cc: stable tag. The commit message mentions it only
as background.

Stable trees that have f66ee0410b1c but not cffcf57bf03c won't build this
patch. A hand-adapted backport could also add the add-path check without
the matching resize-side flag and lock.

Should the stable tag record the dependency, for example
"Cc: stable@vger.kernel.org # depends on cffcf57bf03c", or ask for
cffcf57bf03c to be backported as well?

> diff --git a/net/netfilter/ipset/ip_set_hash_gen.h b/net/netfilter/ipset/ip_set_hash_gen.h
> index 80ca523f304bb..70f768ba7b443 100644
> --- a/net/netfilter/ipset/ip_set_hash_gen.h
> +++ b/net/netfilter/ipset/ip_set_hash_gen.h
> @@ -1009,8 +1009,12 @@ mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,
>  	maxelem = t->maxelem;
>  	if (elements >= maxelem) {
>  		u32 e;
> -		if (SET_WITH_TIMEOUT(set))
> -			mtype_gc_do(set, h, t, r);
> +		if (SET_WITH_TIMEOUT(set)) {
> +			spin_lock_bh(&h->gc.lock);
> +			if (!t->resizing)
> +				mtype_gc_do(set, h, t, r);
> +			spin_unlock_bh(&h->gc.lock);
> +		}
>  		maxelem = h->maxelem;
>  		elements = 0;
>  		for (e = 0; e < ahash_numof_locks(t->htable_bits); e++)

[Severity: Critical]
Does this fully close the double free? Only the direct mtype_gc_do() call
is guarded. Other packet-path sites still call ip_set_ext_destroy() on
elements of the pinned old table while mtype_resize() runs.

mtype_resize() makes a shallow copy of each live element. It holds only
rcu_read_lock_bh() and no hregion locks:

    d = ahash_data(m, m->pos, dsize);
    memcpy(d, data, dsize);

After the copy, both tables point to the same ip_set_comment_rcu. Hash
types set region_lock, so packet-side ip_set_add() and ip_set_del() can
run at the same time as this copy.

The first site is the reuse/forceadd branch later in mtype_add():

    if (reuse || forceadd) {
        if (j == -1)
            j = 0;
        data = ahash_data(n, j, set->dsize);
        if (!deleted) {
            mtype_del_cidr_all(set, h, data);
            ip_set_ext_destroy(set, data);
            t->hregion[r].elements--;
        }
        goto copy_data;
    }

This branch can free the comment of an element that was live when copied
and has expired since. That is the same timing as the race in the commit
message. With forceadd it evicts slot 0, a live element that has already
been copied, so no expiry timing is needed.

GC is now skipped on a resizing table. When expired entries are present,
the recomputed elements stays >= maxelem. Doesn't that make forceadd more
likely to take this eviction path?

The second site is mtype_del():

    mtype_del_cidr_all(set, h, d);
    ip_set_ext_destroy(set, data);

    if (t->resizing && ext && ext->target) {
        ...
            x->ad = IPSET_DEL;

This frees the comment in the old table and queues an IPSET_DEL record.
After the new table is published, mtype_resize() replays the record:

    mtype_del(set, &x->d, NULL, NULL, 0);

The replay finds the copied element in the new table and calls
ip_set_ext_destroy() again on the same comment pointer.

ip_set_comment_free() clears only the slot it is given:

    atomic64_sub(sizeof(*c) + strlen(c->str) + 1, &set->ext_size);
    rcu_assign_pointer(comment->c, NULL);
    kfree_rcu(c, rcu);

In each case the new table keeps a dangling pointer. The next GC, delete,
flush/destroy or backlog replay on it then calls strlen() on freed memory
and does a second kfree_rcu(). A dump would also read freed memory
through ip_set_put_comment().

Would it be better to stop or defer all extension destruction on the old
table while t->resizing is set? Another option is to have the new table
take ownership of the extensions during resize, by transfer or deep copy.

[Severity: High]
This is a pre-existing issue, but does a successful resize leak the
comment extensions of elements that had already expired but had not been
collected yet?

mtype_resize() skips those elements during the copy:

    if (SET_ELEM_EXPIRED(set, data))
        continue;

It then frees the old table without extension cleanup:

    if (atomic_dec_and_test(&orig->uref)) {
        pr_debug("Table destroy by resize %p\n", orig);
        mtype_ahash_destroy(set, orig, false);
    }

With ext_destroy set to false, mtype_ahash_destroy() skips
mtype_ext_cleanup(). orig->resizing stays true after a successful resize,
so mtype_gc() never runs mtype_gc_do() on orig. With this patch the add
path doesn't either:

    if (!t->resizing)
        mtype_gc_do(set, h, t, r);

So the ip_set_comment_rcu objects that ip_set_init_comment() allocated
for those elements are never freed. set->ext_size is never reduced for
them either.

Before this patch, the add-path GC could still free some of those
uncopied expired comments while running on orig. This check closes that
window as well.

ipset netlink commands need only CAP_NET_ADMIN in the caller's own user
and network namespace, and these allocations are not memcg accounted. Can
a user repeat create, expire, resize and destroy to use up host memory?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117092731.14656-1-onleaf322%40gmail.com
Technical Details
Message-ID: <179512365704.3136.7898068439962970821@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367340-linux-kernel-netdev=dewy.ru
References: <20261117092731.14656-1-onleaf322@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367340-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] netfilter: ipset: exclude add-path GC during resize
Date: Thu, 19 Nov 2026 21:27:37 +0000
Organization: Usenet Network
Message-ID: <179512365704.3136.7898068439962970821@kernel.org>
References: <20261117092731.14656-1-onleaf322@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2984952"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:cpB4Ii4LWXgrAq66mQSq97n5VnA= sha256:SIoByXLX0TT69LfDaxyEaSLSKb3fpjgpZBVzX4IOu90=
	sha1:RgGFFJEmZQFFuUlPlRaNViVgsXw= sha256:GoRCth/qUQ1aWa3AnENDl0Cl2DGAdMVZdGwjEkIB3RQ=
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 E4BAC115792; Fri, 20 Nov 2026 00:27:54 +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 DzL8JsZ8lZgA;
	Fri, 20 Nov 2026 00:27:50 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-367340-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 769D811578D; Fri, 20 Nov 2026 00:27:42 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 681C2268FD1; Thu, 19 Nov 2026 21:27:40 +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=1795123659;
	b=Q/WuoJbgfrEIFWWxSWwltFmo0up18QGx5NCpew9vBxJKR268I/2GtGxK1+/2zKFRefNs
	 9EWIs4TpPfZNo4a7RmfdpbsuGyB02MEryaScsNt1LQ5oXReUSDlM6iSJyZKWSv6EgED/b
	 dzdKFgvaltoFT/ZItRj7FzJS58sPowNNfOyf5fxxlOo6KL0IubI3EufFgsoItOiBn9WN9
	 NrpenNShoGMHUL0oMlybWZbx2Oalk+dyJSHWY0mKQJABMz8PvtQ/4bcYpeFChUNhIanfx
	 U8Nej6FL07t3q9YBaA49W25T3gE2SLoLX8vDAL3QW6kGvuS5h/segQu6LXmrL53gaPw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795123659;
	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=FI9vWdua1Ky4pzSvEMEUUts+rWwX6FGvwGpLJLvDzhs=;
	b=PN3aCVtq+76bMnRnzYoIk8NWtexr3/NyuaCELPtD7x1MIC8J9BeZqx1UCDv+LUxxBFTZ
	 Y8NpOF7GOln69A3yoKjyhxn0powicXqmSUQNRoCbl77EvGLyTRWKRqsxv+a4o68gtcotA
	 hwxYci8VUpx77FOFXiPanxYpZLtP9/pwDIaEqX/5eJG8UuLQSj8hKVqCDdPFQS/REJsAd
	 TeKwbiWcpTBuSt2a5FPjJJyHbw8WpWOW+eSFxQGlK2PfXdXG2WichK10VrB5bZHf8Xtsq
	 Kh8IoAqGPKmkZihG5QbVaywOoy1Nm5oOKI4voKHAQV6W5gRFQEyjb811ZI6qPV+22Aw==
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=N5oh2KSP;
	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 946A6606A338;
	Thu, 19 Nov 2026 21:27:39 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=N5oh2KSP
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=1795123658;
	b=Fi/2U1xhlXLJBkMauCugC17U8ooiOGkFezHcsHLbLR4FJvxUGlHi9b8wR6isER+HgCzz
	 vq8LwPUHbwk5GXUd19fS/Vvs0yzhlAVbCguT3tJj8n7mpFfSA2cwH9dK08a5dyi27v1Wc
	 mMqJIfq/8QT8/DM4Tu3TP0/uzswg3yCfLL3VH+bASfAjvefflV0CD+s5ZhXJxO9gwNu3z
	 B6ide7uLficpKmNe1I7XCPM2o9RVb3S+DX13rkNCeTdrW0SoNVKCg8NJQ8hqtdLhCgYgD
	 1Mg9TOW0yQ1SckvB28R4Ghc0OTAsyoGO8M2dyT52bhgrih1SNASu10LRhK6sgCdpNHg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795123658;
	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=FI9vWdua1Ky4pzSvEMEUUts+rWwX6FGvwGpLJLvDzhs=;
	b=PH1t5vSu8WVbiu/bLmug061H1ACL7DZ4XOr9+Tb0rdmNusmdlWrHD8lEJk2lmr9kpwSG
	 JP6UXJLmY48e+Ew4ZGujZ50/hWHJHLOulNYv6854BW6Ojzq0i5gAmdMNmzCuWRyrEcznW
	 9iUKbIYxThfJd1g78OXCfyMnQ1tJrO15saVQc/gxuoCe/r3w/8S2nXEthyvS4BcY3NRjK
	 kSFg0AInW41e+Vyf5u3ySKuLL+trs3Ax5jAifpzuUo2m5FqLEmcLPnmy7y/JznsmltSMM
	 mtGDdtLmFCTg7S/REYAFy4xBerKK+KXVbW/HzE45QnGy8zoTcgG/vDqDxg3aCsMUEOA==
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=N5oh2KSP;
	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 B1BF5606A320;
	Thu, 19 Nov 2026 21:27:38 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E02B1F000C4;
	Thu, 19 Nov 2026 21:27:37 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795123658;
	bh=FI9vWdua1Ky4pzSvEMEUUts+rWwX6FGvwGpLJLvDzhs=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=N5oh2KSPBuNpDFr7xrQyBWbEBYBE+mP27Yec7/RVAcz2gcwbxTLkwqT9e1SAlOfXd
	 IRhC/NZT0Kr9bveewyxi3UWWb/AOYbyqpcxL/l6hGPAiA6OXwSgWo9ZX1hn5R1NW+r
	 1D8pi47FJCyAaQ2mzGKr1r9jjklUj4IWDj6F3RJcZiGaO8jnOBAH0ZW+H/Enb2I1N9
	 47kqZXfoCSkY06rcJ/YVpKW7E4wJl9myAOB+ySpZt4IrMj5mPfSn286ImUxZkRRSEp
	 NsLVPb1zNGoOpJbN9QnUyVKC7TpLqY01mMBfj0x25DDuhlesrVblxdPJNOg8Wk8PMe
	 a4x8kTnmhljLg==
X-Cc: pablo@netfilter.org, fw@strlen.de, phil@nwl.cc, kadlec@netfilter.org,
 davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 horms@kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
 netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org
X-In-Reply-To: <20261117092731.14656-1-onleaf322@gmail.com>
X-sashiko-severity: Critical
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