Article View: linux.kernel.netdev
Article #9522[PATCH 01/14] xfrm: retry inexact policy lookup after node reinsertion
From: Steffen Klassert
Date: Mon, 02 Nov 2026 10:03
Date: Mon, 02 Nov 2026 10:03
79 lines
12476 bytes
12476 bytes
From: Chengfeng Ye <nicoyip.dev@gmail.com>
An inexact policy lookup first records pointers to candidate hlist heads
and then traverses the lists. A concurrent policy insertion can merge
inexact tree nodes between those operations:
lookup policy insertion
------ ----------------
find inexact candidates
save obsolete hlist head
write_seqcount_begin(&bin->count)
merge inexact tree nodes
hlist_del_rcu(&policy->bydst)
reinsert policy->bydst in survivor
write_seqcount_end(&bin->count)
evaluate saved candidate list
miss the moved policy
The merge immediately reinserts the same hlist node into the surviving
tree node. RCU keeps the policy alive, but it does not provide a
consistent view while its list node is moved. A lookup that selected the
obsolete list can observe it empty. A lookup already traversing a moved
policy can instead follow the next pointer rewritten by the reinsertion.
Either case can return an incorrect IPsec policy result.
The per-bin sequence counter already brackets calls to
xfrm_policy_inexact_insert_node(), including node merges. The read side,
however, currently validates the counter only while searching an
individual rb-tree. A successful search returns without validation, and
the later candidate-list traversal is outside that read-side section.
Snapshot the per-bin sequence before discovering candidate heads and
validate it after evaluating all candidate lists. Retry the lookup if
the inexact policy tree changes while it is being searched.
Fixes: 9cf545ebd591 ("xfrm: policy: store inexact policies in a tree ordered by destination address")
Cc: stable@vger.kernel.org
Signed-off-by: Chengfeng Ye <nicoyip.dev@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
net/xfrm/xfrm_policy.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 513c9f228334..f6f40ba713d5 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -2157,6 +2157,7 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type,
struct xfrm_pol_inexact_bin *bin;
struct xfrm_policy *pol, *ret;
struct hlist_head *chain;
+ unsigned int inexact_sequence;
unsigned int sequence;
int err;
@@ -2191,12 +2192,18 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type,
goto skip_inexact;
bin = xfrm_policy_inexact_lookup_rcu(net, type, family, dir, if_id);
- if (!bin || !xfrm_policy_find_inexact_candidates(&cand, bin, saddr,
- daddr))
+ if (!bin)
+ goto skip_inexact;
+
+ inexact_sequence = read_seqcount_begin(&bin->count);
+ if (!xfrm_policy_find_inexact_candidates(&cand, bin, saddr, daddr))
goto skip_inexact;
pol = xfrm_policy_eval_candidates(&cand, ret, fl, type,
family, if_id);
+ if (read_seqcount_retry(&bin->count, inexact_sequence))
+ goto retry;
+
if (pol) {
ret = pol;
if (IS_ERR(pol))
--
2.53.0
Technical Details
Message-ID:
<20261102100451.2505200-2-steffen.klassert@secunet.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354523-linux-kernel-netdev=dewy.ruReferences:
<20261102100451.2505200-1-steffen.klassert@secunet.com>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-354523-linux-kernel-netdev=dewy.ru From: steffen.klassert@secunet.com (Steffen Klassert) Newsgroups: linux.kernel.netdev Subject: [PATCH 01/14] xfrm: retry inexact policy lookup after node reinsertion Date: Mon, 2 Nov 2026 10:03:59 +0000 Organization: Usenet Network Message-ID: <20261102100451.2505200-2-steffen.klassert@secunet.com> References: <20261102100451.2505200-1-steffen.klassert@secunet.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2878342"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:rVRsWEkbBKdKK1WX1moWiadXqNA= sha256:tXCrdOL4eT1glKI1yw2m0F/Dk8m4l6qOgS0P/0+ADrM= sha1:HmWI09XWyO4nuEMCx24REdRstJA= sha256:f6k2qBN6z8LNty0efc52zmZgEQZvJrGphb79WIAgL/0= 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 DCB2611245C; Mon, 2 Nov 2026 11:09:32 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.049 X-Spam-Status: No, score=-3.049 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.25, 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=secunet.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 qz7t-srrATGT; Mon, 2 Nov 2026 11:09:30 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-354523-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=secunet.com X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 51F48112453; Mon, 2 Nov 2026 11:09:22 +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 9435B314E6; Mon, 2 Nov 2026 08:05:14 +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=1793606709; b=O8M4XFoJWENb5CNz1JQJHA6TA0hh6JOSl6qqC5mTQ+x3KKjXUQn6Jtgee/OjT9KVFEw4 qRbC3OpzXNG7xa0rX59YYsVY/P+qBJH8gQeKIR91h8aQwPFTlYLWJavCJu0sxU3uwec9V tC9sP0jFtLjKh+PwaSUuyNVQoaj7h8ywzKH/u1GqcAGPKqpNdh4CkdRFRpwf/JdhZsNcx op8EtE6YM8cA4wYSHIg52t7GloxB+nfqji077gO7ANWpQ0kT//qnLW2BQoGlxE/8Q3wcu 03tue2wRnIwapTgyTo/ypfqiFpNM+Eg+fPsK6Yno8iZ70Opts46/2tamEw64P6a4q5Q== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793606709; h=X-Original-To:Received:DMARC-Filter:Received:X-Virus-Scanned: Received:Received:DKIM-Filter:DKIM-Signature:Received:Received: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-Transfer-Encoding:Content-Type:X-ClientProxiedBy; bh=eEfGUM6vhzDXHxofy6JNKvz6IXGC+uZMf/dmhqlPCDg=; b=IafKFKZuR5JIw4MPkO5NIRgvKb+zEBQOAmi9RqTVkvrQcwm0SsXptcaMOyLEETcn6wHj 9i2NjY5IC5xGEIwp/5f0j5QWVTTAl/jJj1Kuc6zKfN9Mx6QdWtftqKKLsbRIk2sn0xrWu DtT15UyrC81NMw5S7ltSrLEBXCnTIxuZOFNXRJ7LQv+4S5K6KyLkze2F9BBueeflabJVw Tv0G9J2OQQnhD1MM8ZrBEVbZqnOQfJ7PpvbthHxMSaUsTSfoyDADeyoW+zOi08GqJQoGd Vh2dYrj4YvbKdcRMWCM1jVf4Hc+mLymjI+lFC8fB3G4q8AAuYBF+VmvjIrK25a/BizA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=HKpQ7AJw; dmarc=pass header.from=secunet.com; spf=pass smtp.mailfrom=secunet.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 5B5FD606A326; Mon, 2 Nov 2026 08:05:09 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=HKpQ7AJw X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=62.96.220.36 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793606695; b=Bk2Y0x7SFVbj8y1sYTx7E9eeI7cwkWpiyN4soFlIpf3p++gVoOwlNACOHZOUXvahNfD9 tFYg5vvgcy17Y35QEhPn9wIfwy/dNv4guyAqxA7RP8cVxZhfApc6Rl/VjHgzcQFEhXIJh 6b5K6hXRRbNq9kQtXiOtHeN5n5cYa99pOLHEBB1hdbn8prme1cwcvu0cB0AzMFe6e25xP NsnEvSWYMGYK8NA0yao/j9DZeFy2flW7/ktp1tu7E1kAdRkj7pTowZa0TM+d8144kSgYZ 2Z+qRM44mnXgMFtuPU80GkU7E2pqIzes1WxaotoTU6PDFCbd781Rh8NvkzKnNAWWuVg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793606695; h=DMARC-Filter:Received:X-Virus-Scanned:Received:Received:DKIM-Filter: DKIM-Signature:Received:Received:From:To:CC:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:Content-Type:X-ClientProxiedBy; bh=eEfGUM6vhzDXHxofy6JNKvz6IXGC+uZMf/dmhqlPCDg=; b=DGnFjmQplBUNxPBlS5tpCSaJRvk05dnqr2nUMQj3MOLh3LlPfRZaamzy/VeSsccSzzB6 F7aMrg61dLAWXT/XBqpW/FPVNlrgm7xwrpVC0d8CFqEor9l2rM0kCgS4BiG11JMD6qqo+ y5IJjOqZwb7noIfFs06uXZjiUV9eVTuJRvKiZ7idHaz9gkj3rFoz4X+DJ+n8YeeLwhrqP A7T7LdTIDd7TVgDotyW829Xfmu28oBRPz3czBlJntpkv+cSunEZbrODZKymB/PpVIIWit vZG3ATIuWhivRcE7Flu7tfa9kugdBp332x/Bq26/b0658UFe2VMwAkWumlEEY3XKJdA== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=secunet.com; spf=pass smtp.mailfrom=secunet.com; dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=HKpQ7AJw; arc=none smtp.remote-ip=62.96.220.36 X-Received: from mx1.secunet.com (mx1.secunet.com [62.96.220.36]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E354160A3814 for <netdev@vger.kernel.org>; Mon, 2 Nov 2026 08:04:54 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E354160A3814 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=secunet.com X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=secunet.com X-Received: from localhost (localhost [127.0.0.1]) by mx1.secunet.com (Postfix) with ESMTP id BE962207A4; Mon, 2 Nov 2026 09:04:53 +0100 (CET) X-Virus-Scanned: by secunet X-Received: from mx1.secunet.com ([127.0.0.1]) by localhost (mx1.secunet.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id w78tEtaJEO5j; Mon, 2 Nov 2026 09:04:53 +0100 (CET) X-Received: from EXCH-01.secunet.de (rl1.secunet.de [10.32.0.231]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.secunet.com (Postfix) with ESMTPS id 25AF0207BB; Mon, 2 Nov 2026 09:04:53 +0100 (CET) X-DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com 25AF0207BB X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com; s=202301; t=1793606693; bh=eEfGUM6vhzDXHxofy6JNKvz6IXGC+uZMf/dmhqlPCDg=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=HKpQ7AJwPZZW4zzHzwi/eS0Mhh2/ZXnqkg4fIvs11+IuY88ZWbpvZ5AA0O/yPcBE+ c9fJigprrw62/PTigCOAdSCRLBYxgnWzO9AXFuTXZkDXZZbXgwXGyuDSu3GHAkU4Ud 46qKQhsKkf5eOikcfkj47jGLgkipSW0KosD37Mv7hYW2m7aAAvQZJV9lPAq7IKsZG3 5weinYxYTgQYYlUOmu0m0ctsLC5TbJlrg5Lkbs8Di2481TdVXLGJvNV3624byJFLDF 9tsBZRH/C0SXcqRVE016uW3bPIk+eKxpkwlafHFQxqvL9gLGL+ifFCta3k18IPqOOM +FyXgZr1K6ukA== X-Received: from gauss4 (10.182.7.102) by EXCH-01.secunet.de (10.32.0.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.49; Mon, 2 Nov 2026 09:04:52 +0100 X-Received: (nullmailer pid 2505891 invoked by uid 1000); Mon, 02 Nov 2026 10:04:58 -0000 X-CC: Herbert Xu <herbert@gondor.apana.org.au>, Steffen Klassert <steffen.klassert@secunet.com>, <netdev@vger.kernel.org> X-Mailer: git-send-email 2.53.0 X-In-Reply-To: <20261102100451.2505200-1-steffen.klassert@secunet.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-ClientProxiedBy: EXCH-01.secunet.de (10.32.0.171) To EXCH-01.secunet.de (10.32.0.171)