🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #22980

Re: [PATCH ipsec v2 1/1] xfrm: free the policies already cloned when a socket clone fails

#22980
From: Steffen Klassert
Date: Thu, 26 Nov 2026 08:57
45 lines
11226 bytes
On Mon, Nov 23, 2026 at 01:29:42PM +0900, Kyuwon Cho wrote:
> __xfrm_sk_clone_policy() clones the parent's socket policies one
> direction at a time and returns -ENOMEM at the first failure. If the
> policy for the second direction cannot be cloned, the clone of the
> first one is already set in the new socket and linked on
> net->xfrm.policy_all. sk_clone() then frees the new socket without
> xfrm_sk_free_policy(), and the policy is leaked until the network
> namespace goes away:
> 
>   WARNING: net/xfrm/xfrm_policy.c:4303 at xfrm_policy_fini+0x24c/0x300
>   Call Trace:
>    xfrm_net_exit (net/xfrm/xfrm_policy.c:4372)
>    ops_undo_list (net/core/net_namespace.c:253)
>    cleanup_net (net/core/net_namespace.c:713)
> 
> Delete the policies cloned so far before returning the error.
> xfrm_sk_clone_policy() clears the new socket's slots before cloning,
> so a slot that is set holds one of these clones.
> 
> Fixes: d188ba86dd07 ("xfrm: add rcu protection to sk->sk_policy[]")
> Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
> ---
>  net/xfrm/xfrm_policy.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
> index cea6842e6454..dba1851f0b3d 100644
> --- a/net/xfrm/xfrm_policy.c
> +++ b/net/xfrm/xfrm_policy.c
> @@ -2460,6 +2460,13 @@ int __xfrm_sk_clone_policy(struct sock *sk, const struct sock *osk)
>  			rcu_assign_pointer(sk->sk_policy[i], np);
>  		}
>  	}
> +	while (unlikely(ret) && i--) {
> +		np = rcu_dereference(sk->sk_policy[i]);
> +		if (np) {
> +			RCU_INIT_POINTER(sk->sk_policy[i], NULL);
> +			xfrm_policy_delete(np, XFRM_POLICY_MAX + i);
> +		}
> +	}

Do you really need an unroll loop here? This function clones
at most two policies. If the second fails, just delete the
first one.
Technical Details
Message-ID: <awf0ibmT7f-IzSup@gauss4>
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-371972-linux-kernel-netdev=dewy.ru
References: <179540803323.3139700.5340002553684152759@gmail.com> <179540803323.3139700.15088508372382876389@gmail.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-371972-linux-kernel-netdev=dewy.ru
From: steffen.klassert@secunet.com (Steffen Klassert)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH ipsec v2 1/1] xfrm: free the policies already cloned when
 a socket clone fails
Date: Thu, 26 Nov 2026 09:57:45 +0100
Organization: Usenet Network
Message-ID: <awf0ibmT7f-IzSup@gauss4>
References: <179540803323.3139700.5340002553684152759@gmail.com>
 <179540803323.3139700.15088508372382876389@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Injection-Info: usenet.network;
	logging-data="420970"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:M7ggfVxni8VptvPMD4FJA4YpS0s= sha256:BV0sPt762wA6zADD7tXfUGieCZMOopF1yuBexltOtGE=
	sha1:RJ1sp8sWDVkpz38ohwEpaNoi6tY= sha256:HMTihdeyrQJsnQIBIQ6ptu4vpRD3S3Wo9G8YpFP4qjA=
Content-Disposition: inline
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 6313F125EB5; Thu, 26 Nov 2026 11:58:04 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.15
X-Spam-Status: No, score=-3.15 tagged_above=-9999 required=6.31
	tests=[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,
	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 EYhfNQ1AfdEX;
	Thu, 26 Nov 2026 11:58:01 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-371972-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 0DB30125EB6; Thu, 26 Nov 2026 11:57:52 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id 19B3A6062B5; Thu, 26 Nov 2026 08:57:52 +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=1795683470;
	b=OEHA9+/KjOYQ1wfFvWkjeVCkRSa+3y6d8epOqTHGLGOsgWnqFr13vFpce7YQtVQGUl2m
	 8UMzQQ0bl5yKD3if/LsEOPZy3o0K2x9QoSshPFr7E219LXs5hgG+a25dbvBRMltfRmQBb
	 mL8VTFhqhxwMoD3LCzpjiPR2jU+UQztQcT9QlvFUAFMh4N1sr8mRSSrC72Fs7X7ELICeL
	 MjAjzT35Q2MEmPo9jZNUxx/6j3hu0WowHtmMrYpYGcxh36LpN1F29/9C6GpMDDDMjOGEv
	 TB8vJmFKQDt6toojJGoyQ6fAOhWiTZ9CIlq14PQTMvGCoYQOoWCQAkfUlp8XlGRy6Aw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795683470;
	h=X-Original-To:Received:DMARC-Filter:Received:X-Virus-Scanned:
	 Received:Received:DKIM-Filter:DKIM-Signature:Received:Received:Date:
	 From:To:CC:Subject:Message-ID:References:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:Content-Type:Content-Disposition:In-Reply-To:
	 X-ClientProxiedBy;
	bh=AdLL3Q53BHJLoBt9CSRYGYry3kTUEfgH4omIXprvDe8=;
	b=O5Olu4cwv/UWELY2D4g+K+tNr6ahniGmjB8WhpJwqyvjfAIIUpYRv1RWlbbuWwlxS9jQ
	 2LNfVYYuR412U800+2mZh6w31Psnz7zxW4fzGAt6HPRSpfv6Hn3rSa9QA5FtnfAO4Hzka
	 jUCvyTzbaFP2sOIInKAljTw+X2qEJgcLamaZ7VEb+lssEo4dk19Cb2JxoQuUgCv4zje/Y
	 VzjJYZxYJo71xVMJ7TUwbmPmC4Sl7trwvADiD4Yqfqsv6hvU3DRnSE6xcKmsCH3X9zob2
	 Fqm48YkzaIe13nkVPAGgQPJ9Olivcr77T2ps1GYiDXgx4LWCtp2H+xe2howK3kuoRlw==
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=uG0UZuWs;
	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 6BE69606A33E;
	Thu, 26 Nov 2026 08:57:50 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=uG0UZuWs
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=1795683469;
	b=hhum1VfhI3A8TiGujKg4pys+qln+Yv0+Tkm/80EAir4ymV8gCQQnvypb1JDd2w5FzOG1
	 uWm67H+NELwuUCIfJ/wqFqY7PYKnFW62BlCp0NcUeL8BhsZgHfAt7QEumCuzV7AeFioD4
	 QD1UlFK3DBGZL811FOOr2mkdlY5hmPzObdovPvYyUu+rQcu6vE0oBSpV/kJBHNuoRuiE7
	 vJdUAubYjXjFr5rJyGHXEgMLtxwDJt+J24fQ3y7oNgKvweAWxEmBu+37lZX4euyB3pwVs
	 bKwLLx2xK5UyKrMxNx2SLcXE9wmlTmMJP+01tPePHi18diGukdSWl4yg38Ky3VVK1Lg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795683469;
	h=DMARC-Filter:Received:X-Virus-Scanned:Received:Received:DKIM-Filter:
	 DKIM-Signature:Received:Received:Date:From:To:CC:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To:
	 X-ClientProxiedBy;
	bh=AdLL3Q53BHJLoBt9CSRYGYry3kTUEfgH4omIXprvDe8=;
	b=wvdQgwLGmZ4AGH9C2rBep0pqH7a5SPdWwiGk6GqOfwfE3l6eT4WxbctiG1Ljnga1BqhO
	 ZoxEVKliRdKq6v+QO0TNLhqKyhdFcohQaU8hheXjhad/NFCnnssIybMtDljdL7gIqeHx3
	 D6KWrr6uu6hKTVSWxpbq9yt9aq5/FoSxIz3DO+2STHChzfcmc619a1XODvYBaTLekFa5q
	 AQuR3KzvMaBLVDYPYm4SUr25hZSj9z8vdzQSj8PBnHOit9vtB33JOt3TuRn/64uyTsPVc
	 8JSmpbso9+zPYEaZ3nmcJO6spc05UZsRq2hbXOPw0zRlPIgPth57lfT4MZIPrLug8PA==
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=uG0UZuWs;
	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 C7A62606A32A;
	Thu, 26 Nov 2026 08:57:48 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C7A62606A32A
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 B5A8620758;
	Thu, 26 Nov 2026 09:57:46 +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 8zdpgIyEFP4v; Thu, 26 Nov 2026 09:57:46 +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 21FB7206B1;
	Thu, 26 Nov 2026 09:57:46 +0100 (CET)
X-DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com 21FB7206B1
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com;
	s=202301; t=1795683466;
	bh=AdLL3Q53BHJLoBt9CSRYGYry3kTUEfgH4omIXprvDe8=;
	h=Date:From:To:CC:Subject:References:In-Reply-To:From;
	b=uG0UZuWs5XmZi7MZQ9zamgII2bTngTWGFGOex3D+bxcFooMsSC2G7ZIWNUzyzJ11I
	 ld5z8ORp7SGRslMa8exrbAfRu6oUk8FRwWLaBAwkNr8WyJF+sue/wOhUiMpYFPdPRX
	 C+0Wx2BBJ8Wb4/IHgchCz0RJPJHYBAnpvkHE9grcVUGmpj8n6W5YWOVzvK7r9R6dQ/
	 mbXWyYf0lhLQ/IrpJWg7sq3PWBK+M6zzRPvanbcgMbM76UCflduxpdtQ3yXco/DhaG
	 20RNmFoUiEUZINEuwLVHB5+97N19q+LQXRtw5bKtzHrxzcIFxiFTiNbRQ1oW2IL5eM
	 LaOVOkNS5nFUA==
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; Thu, 26 Nov
 2026 09:57:45 +0100
X-Received: (nullmailer pid 2021184 invoked by uid 1000);
	Thu, 26 Nov 2026 08:57:45 -0000
X-CC: 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>, Kuniyuki Iwashima
	<kuniyu@google.com>, <netdev@vger.kernel.org>, <ipsec@lists.linux.dev>,
	<linux-kernel@vger.kernel.org>
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-In-Reply-To: <179540803323.3139700.15088508372382876389@gmail.com>
X-ClientProxiedBy: EXCH-01.secunet.de (10.32.0.171) To EXCH-01.secunet.de
 (10.32.0.171)