๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #24697

Re: [PATCH ipsec v2 1/2] xfrm: advance the route generation when policies are removed

#24697
From: Ralf Lici
Date: Mon, 30 Nov 2026 16:51
62 lines
12127 bytes
On Mon, 30 Nov 2026 11:08:21 +0100, Nicolas Dichtel <nicolas.dichtel@6wind.com> wrote:
> Le 27/11/2026 ร  17:48, Ralf Lici a รฉcritย :> Only xfrm_policy_insert and
> xfrm_set_default advance the IPv4 and IPv6
> > route generations. Deleting, flushing or expiring a policy does not, so
> > a route that a socket cached while an allow policy without templates
> > matched its flow keeps validating after that policy is removed, and the
> > socket keeps sending in plaintext although a policy requiring IPsec now
> > matches. xfrm_policy_insert also advances the generation before
> > unlinking the policy that the new one replaces, which can still be
> > matched until then, since the new policy can be linked behind it.
> > 
> > Advance the generation once a policy is unlinked by a delete or by its
> > expiry, once after all policies are unlinked by a flush, and after the
> > replaced policy is unlinked by an insert. Socket policies only apply to
> > their own socket and are left out.
> > 
> > Fixes: ee8372dd1989 ("xfrm: invalidate dst on policy insertion/deletion")
> > Signed-off-by: Ralf Lici <ralf@mandelbit.com>
>
> Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
>

Thanks Nicolas.

Sashiko raised three points on this patch [1]:

- The IPv6 cookie is still read after the policy lookup, so a lookup
  that matched the allow policy before the unlink can store the new
  serial. That is the late cookie sampling race in general, which the
  writer side cannot close. "ipv6: validate cached dsts against the
  netns route generation" [2] closes it by sampling the generation
  before the lookup.

- rt_genid_bump_ipv4 is a plain atomic_inc, so the unlink is not
  ordered before it on weakly ordered architectures. I'll add
  smp_mb__before_atomic in v3.

- xfrm_policy_delete also runs from the policy timer, in softirq
  context, and for IPv6 the bump is fib6_flush_trees, a walk of every
  route. Policies that expire together would walk the FIB once each in a
  single softirq, and both policies and routes only need CAP_NET_ADMIN
  in the netns. [2] turns the IPv6 bump into a counter increment, but
  that is net-next.

For the last one I see three options for net:

a) defer the bump in xfrm_policy_delete to a per-netns work item, like
   policy_hash_work, so that expiries coalesce into one walk in process
   context;
b) keep the bump synchronous, as in this version; or
c) leave expiry out of this fix.

The first option seems the right fix to me but let me know if you prefer
a more "minimalistic" approach for a bugfix commit.

[1] https://netdev-ai.bots.linux.dev/sashiko/#/patchset/cover.1795797791.git.ralf%40mandelbit.com
[2] https://lore.kernel.org/netdev/cover.1795642432.git.dahern@nvidia.com/

-- 
Ralf Lici
Mandelbit Srl
Technical Details
Message-ID: <20261130165103.526794-1-ralf@mandelbit.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374325-linux-kernel-netdev=dewy.ru
References: <cover.1795797791.git.ralf@mandelbit.com> <3c91d1fc49e074fea1e87a7fdb8d4157fc42b342.1795797791.git.ralf@mandelbit.com> <2027ff78-c342-4ab2-a289-c343f0c4a457@6wind.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374325-linux-kernel-netdev=dewy.ru
From: ralf@mandelbit.com (Ralf Lici)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH ipsec v2 1/2] xfrm: advance the route generation when policies are removed
Date: Mon, 30 Nov 2026 17:51:02 +0100
Organization: Usenet Network
Message-ID: <20261130165103.526794-1-ralf@mandelbit.com>
References: <cover.1795797791.git.ralf@mandelbit.com> <3c91d1fc49e074fea1e87a7fdb8d4157fc42b342.1795797791.git.ralf@mandelbit.com> <2027ff78-c342-4ab2-a289-c343f0c4a457@6wind.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1473763"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:5dwmPCJHSaN+swLniXoWYc91Dd8= sha256:GwnzOJhZaoYujT0ZjBeyq93zOejYNDzPTkv/Dd45eMY=
	sha1:3CEGfJ48ZBNmrGWu16UFjb9wsEk= sha256:Y0wNqoJMpFslLBTQtlda5KyG+Qd45TZigL+hBuziq/M=
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 2BFCB125FF7; Mon, 30 Nov 2026 19:51:39 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.051
X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=mandelbit.com
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 8EnhvALL27mG;
	Mon, 30 Nov 2026 19:51:35 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-374325-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=mandelbit.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 2D042125FF6; Mon, 30 Nov 2026 19:51:27 +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 3999230BA8; Mon, 30 Nov 2026 16:51:24 +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=1796057483;
	b=AUJ/GrNHIKuaJim9yN5lOieDDQVA1jYh8pWO4PEWJx23QKFi3kaRb2Uxn3X0o14RtEdZ
	 K7vMRCJODIp/Dycc/0YNhS8Phatvuc3Vz5lkTXrqv8jpB9+dTdwH7hGzt8OsAyKTKkAyY
	 uC3Px1CJu6nhxECqrnjET3/HAsB0vZfLB9TB6YeT1eNiurqhXj2q6lrZwjcAaDl5sxVo9
	 aXHpX9JoMrUNwyy1d9T4ZUkrBy1qDYFqW+sYnjIggSAl9lEcWFTut5R47YG3wnVfBw4pr
	 HOgpaeWuSr1q41kAmQtX2jGYSJnewjUpbU+RP9UhYqOQabMapszyCQ4q8rxdwMs8ovg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796057483;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:From:To:
	 Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Transfer-Encoding:X-Rspamd-Queue-Id;
	bh=6QFs1pkmzlO4En1S/WCsEIRhxCbPkWIUfNikZc16lXE=;
	b=4Jfcug0cvwcdPQMdnNhyUwEMCrL76FMFZc7cL1P2cEsc8q4/iRLKLKDgqANCuv3O4mLd
	 +XOjiklXlXvYZDTUgJ1SHCTyTOtylQbwTiXfX/rxaZxr1C0WdzZKe7qgZEmKt1H3EFT/l
	 qoWbrNeYi2edGHKaa+GY5FNsLb0h+m6BF45LLeLRvMRcn+ClZLA59kvBjJFsXphf5Asot
	 MszDPcF10EqhfTNCixZMDFwJQxMDjM77F7jK9enIhX69eAQt1IdpWw15cfV6CZlVPr2jE
	 55Gn2z17MUTYcOvPUX97+Cq/a5UzuhXY8mhcznMxDpN0EeB6xM87KUM9Gp7AuzEKblw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=mandelbit.com header.i=@mandelbit.com header.a=rsa-sha256 header.s=MBO0001 header.b=a7dAKuj8;
	dmarc=none header.from=mandelbit.com;
	spf=pass smtp.mailfrom=mandelbit.com;
	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 A62A7606A33A;
	Mon, 30 Nov 2026 16:51:23 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=mandelbit.com header.i=@mandelbit.com header.a=rsa-sha256 header.s=MBO0001 header.b=a7dAKuj8
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.10.208.47
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796057482;
	b=dGMTz2TQAWsnzBYr0eV4X8rcWtZHa7VkpxoKbKfRdukAQzyBkZtn76aLN74yOJtG2OFN
	 RuyybUkqHRhwuKRfbACqt0l6JPGsoReXoZ+qh5kHnnfNBnJsZSNfxOpmvnZcwYKmxYpqD
	 VAmNF5h/OPhcZxylDWJUS7xhHBsgfchXk6ekEmEIDHneDJRYTyYUag3LjiTjcuuNSEOHs
	 hWtOcBnydPDhrooe6v0BmvL+zFKVwLJl5MKhMsToRRhmyZJ6bj8IyHWecFqgo9q6gGDs2
	 F+MAt/aMM2xFeXGtt8A98oZ8HT/AjyEHdG9vR1EzBvG0t7TTMGv3JbS/Vj9RqG7tcnA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796057482;
	h=DMARC-Filter:Received:DKIM-Signature:From:To:Cc:Subject:Date:
	 Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:Content-Type:
	 Content-Transfer-Encoding:X-Rspamd-Queue-Id;
	bh=6QFs1pkmzlO4En1S/WCsEIRhxCbPkWIUfNikZc16lXE=;
	b=jcEfbxg/zUp9LZONpg07ZhIlznTVqDups072aPK/abOvyBMAv8+7qL94bZn8xluKfhI0
	 ydCnYqr02VCYytL/mhYyDjbjkNgutgYLfVUXZ282tAN1v25lBmXAJwRjHy3XxazsUpB96
	 +1lYPqKOuNSwjuESvqAWafj3EHQmZ4BpaUzxGvZBHoF4ab6oJQIqYnspOLe2/NXcEBiSs
	 2YG3jmjyivvI6iJ/2MMnTdxtd1pEdh1IpkzNG0OCUSNzQ8Lzb0n4GAXa9yr6SCZyc0Kpt
	 q8Z/5qyuoBTQdmfZllX7TplBXEEYwt5VMfRkLXrenJqqotRQ+SHkDGexXYarzxPxHYA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=none header.from=mandelbit.com;
	spf=pass smtp.mailfrom=mandelbit.com;
	dkim=pass header.d=mandelbit.com header.i=@mandelbit.com header.a=rsa-sha256 header.s=MBO0001 header.b=a7dAKuj8;
	arc=none smtp.remote-ip=195.10.208.47
X-Received: from mout-b-107.mailbox.org (mout-b-107.mailbox.org [195.10.208.47])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2BE36606A320;
	Mon, 30 Nov 2026 16:51:20 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2BE36606A320
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mandelbit.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mandelbit.com
X-Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by mout-b-107.mailbox.org (Postfix) with ESMTPS id 4jdVQk3sdtz3wYl;
	Mon, 30 Nov 2026 17:51:10 +0100 (CET)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com;
	s=MBO0001; t=1796057470;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=6QFs1pkmzlO4En1S/WCsEIRhxCbPkWIUfNikZc16lXE=;
	b=a7dAKuj8fgZJY7xgPx1y4vDpZV41XiVEKwOVEZ9vaUC1ivonq73zcgH5rMLPxq7F+EjCq6
	CHIJ0bhsUXqe2xyqutheqOnIvZ1mR6Y7yoC3rBHaICohPMlyqx3TbaAIZZovq58+TfUt3P
	HPq+Ul+gBi+Ph7esjGS/JTIxKcygmL07LZ+53Wu5UuaXQhoPUhA7fyIMHbOKyyWh3laJ86
	r/4C3+JVcXusQyEHxsKT8fDdYhB+4LF3TGJB5tycFIDMuKG5jhihW0Rbd+la5stnGq2mmK
	9IO5XX6QJCA6VAH+nN/zpmebqwowYgDQozmS1k2MenGokamcjLoJF73s3y7oUQ==
X-Authentication-Results: outgoing_mbo_mout;
	dkim=none;
	spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::1 as permitted sender) smtp.mailfrom=ralf@mandelbit.com
X-Cc: Steffen Klassert <steffen.klassert@secunet.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>,
	Simon Horman <horms@kernel.org>,
	Shuah Khan <shuah@kernel.org>,
	netdev@vger.kernel.org,
	ipsec@lists.linux.dev,
	linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
X-Mailer: git-send-email 2.56.1
X-In-Reply-To: <2027ff78-c342-4ab2-a289-c343f0c4a457@6wind.com>
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
X-Rspamd-Queue-Id: 4jdVQk3sdtz3wYl