From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.10.208.47 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== 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== 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 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) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2BE36606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mandelbit.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mandelbit.com 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 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) 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== 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 From: Ralf Lici To: nicolas.dichtel@6wind.com Cc: Steffen Klassert , Herbert Xu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Shuah Khan , netdev@vger.kernel.org, ipsec@lists.linux.dev, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org 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 Message-ID: <20261130165103.526794-1-ralf@mandelbit.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <2027ff78-c342-4ab2-a289-c343f0c4a457@6wind.com> References: <3c91d1fc49e074fea1e87a7fdb8d4157fc42b342.1795797791.git.ralf@mandelbit.com> <2027ff78-c342-4ab2-a289-c343f0c4a457@6wind.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4jdVQk3sdtz3wYl On Mon, 30 Nov 2026 11:08:21 +0100, Nicolas Dichtel 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 > > Reviewed-by: Nicolas Dichtel > 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