Article View: linux.kernel.netdev
Article #27121Re: [PATCH ipsec v3] net: free the socket policies when sk_clone() fails
From: Simon Horman
Date: Fri, 04 Dec 2026 20:20
Date: Fri, 04 Dec 2026 20:20
48 lines
10586 bytes
10586 bytes
On Fri, Nov 27, 2026 at 01:58:10PM +0900, Kyuwon Cho wrote:
> sk_clone() clones the parent's socket policies with
> xfrm_sk_clone_policy() and then its BPF socket storage with
> bpf_sk_storage_clone(). If either fails once a policy has been cloned,
> the new socket goes to the "free" label, which only clears sk_destruct
> and calls sk_free(), as the socket is still a raw copy of the parent.
> Nothing frees the cloned policies: they stay on the namespace's policy
> list and in its count, and the namespace teardown warns in
> xfrm_policy_fini().
>
> __xfrm_sk_clone_policy() fails that way when cloning the second policy
> fails, with the clone of the first already in the new socket.
> bpf_sk_storage_clone() fails when memory is short or when the copy does
> not fit into net.core.optmem_max.
>
> Free the policies in a new label at the end of the function. A failed
> filter charge still goes to the old one: xfrm_sk_clone_policy() has not
> run then, and sk_policy[] still holds the parent's pointers.
>
> Fixes: d188ba86dd07 ("xfrm: add rcu protection to sk->sk_policy[]")
> Fixes: 8f51dfc73bf1 ("bpf: support cloning sk storage on accept()")
> Suggested-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
> ---
> v3:
> - Free the policies at the end of sk_clone() instead of in
> __xfrm_sk_clone_policy(), so there is no unwind loop (Steffen), and a
> later failure of bpf_sk_storage_clone() is covered too (the AI review
> Steffen forwarded). This is the unwind Jakub asked for on Josef's
> patch for the second case:
> https://lore.kernel.org/all/20261020192044.7c3a58a1@kernel.org/
> - Hence the new subject; nothing in net/xfrm/ changes any more.
> v2: https://lore.kernel.org/all/179540803323.3139700.5340002553684152759@gmail.com/
> v1: https://lore.kernel.org/netdev/179505710269.3511679.8893709762919027206@gmail.com/
>
> Both cases reproduce as root in a new network namespace with a loopback
> TCP listener that has IP_XFRM_POLICY set in both directions. For the
> first, failslab fails the second clone_policy() (a stack filter on
> __xfrm_sk_clone_policy() and interval 2). For the second, the listener
> also gets an element of a BPF_F_CLONE sk_storage map, and
> net.core.optmem_max is then lowered so that the child's copy cannot be
> charged. Without the patch, the clones are left behind and the
> namespace teardown warns in xfrm_policy_fini(); with it, it does not.
>
> The patch was written with LLM assistance; we reviewed and tested it.
Reviewed-by: Simon Horman <horms@kernel.org>
Technical Details
Message-ID:
<20261204202011.GH192805@horms.kernel.org>Path:
mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!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-377610-linux-kernel-netdev=dewy.ruReferences:
<179568863376.462699.9896914557163021386@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!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-377610-linux-kernel-netdev=dewy.ru From: horms@kernel.org (Simon Horman) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH ipsec v3] net: free the socket policies when sk_clone() fails Date: Fri, 4 Dec 2026 20:20:11 +0000 Organization: Usenet Network Message-ID: <20261204202011.GH192805@horms.kernel.org> References: <179568863376.462699.9896914557163021386@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: usenet.network; logging-data="2855809"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:pCxdkWWycAJVWJttRyFtWgyGO5Q= sha256:pcENhDRinkAxQx7u+qQwPN15gL67wv+EHtYa4Ra4axI= sha1:67nke4uN9y4wbt46q/BvPr6HbUk= sha256:B43EOzzGUaZGHN4tCTUg7yf+bgqAUWm74oW32FG20XY= 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 11C44117CD2; Fri, 4 Dec 2026 23:20:38 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.642 X-Spam-Status: No, score=-3.642 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.142, 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] 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 qrCaUyYuFn6v; Fri, 4 Dec 2026 23:20:31 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-377610-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id B873C117C79; Fri, 4 Dec 2026 23:20:21 +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 D24CF26660; Fri, 4 Dec 2026 20:20:18 +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=1796415618; b=n0ee5k5BPZQ40fSq/kxszBArY+vWz1/N7djQxqwb9hnaeFzMdJ4YqtNNbFlcaTVPtVdk Cec6uEnYr7FKSSgzvWs7i3xI1+6BlDx3ItWqYdUfkTQDTmNbv39ZGApWGatDfksOfSvyp DApdyuUwgFN2A6gUOIscyvXGgqS0oYOuC/q3AwzL7vH7DeF39lELuJXj8C57x5WTNYoq1 v6QkaM67UDlvuvdHZct4kKte5WmbjUezTad1uubiSiQ5i4NszbTeEG6URzlkhUNd5CbNS 8ThyqPsBUI/784XGc9MAbeIzfFfM1Mu+MK5EBC+jJGptgdbJMxM8oSfPWaWGn2s+4lw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796415618; h=X-Original-To:Received:Received:DKIM-Signature: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; bh=qruuQn6uo2pXvQ+DR4RZESU/obVgiHNYEFeLcw5Jix0=; b=nip2wuhdxze2RIy9PISAeNRvnDstaCM1vZBBWs8cKimFnnzo7r+0mkWbq3+5VOYC0UCC vHpGmvjOrU7IC2JL94uX8a8NpIbWZIb8Y6a9oD9+IpZKlc8o6AhpIQGEMEpu7f5SDvJaa zsWUxLXWzqKLApu5z6B5oFyr/cctdha7zcDXo2AbnbGHbP0nJOjhK6vjvvy4MoFUsW88L a40bxC/ERvwN3GKZ1jBBUid9r/z0QAzUkIB96fVdqQuVyRD/smPftdfRG0iFFK219xVlv ZXbySgc9qkQuoUeJIw1KHth60iPJDemfIaSRxKDIbLMTx01VYvfqXEmCB6sGgYz3zMg== 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=OkwQOwjz; 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 26CFF606A335; Fri, 4 Dec 2026 20:20:18 +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=OkwQOwjz 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=1796415617; b=PeMzQ8ISx8Gmr8M9hDJTwF1UZGy9qNFZqUZ3DO5FLxvOATLvrMsRAYVBLuldZTvvgQDO VSW/BLrq5IucnII02Ws16hNQ9QUrb2NSbM94Zq8srTklUKBZ6MV4QUczIGxrNfFaaM78z Fw6AS1zIiFD11RR4tlAhnqbtlFWZ8bT8eZMAzVbeVFyHsPrLvFpsQUAZw91lyLOnsEs6S ijh8ZV+rvsMSpkQXL4JZg+614WGwJHPjG+v1TwQNM3iidbpb1IH8Jdbz+Kgw3TAJs/3gf dRbTcDqYypOzvEWZYHxKig219KVf4SBz+z5dHh4DSEqGuHhk5iLk8FTYnPKEpC7rceA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796415617; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=qruuQn6uo2pXvQ+DR4RZESU/obVgiHNYEFeLcw5Jix0=; b=Y1a0pOeUrCkk6IyIYLFvqzgBfKzlSOllj92ikosh6yvRa37P46xLrXrsH7BN4+BBR5TO lot5T93y4xlUHAy4BwFXyqKsD6Sf/tH/m27mmHhZsjio6OOJX9lqAX9cUQw9TOLBpa0xO 3Tf7JkNpOfPzgSkSebSfi45C9jc3hI4ri+Ha0Q5/a2TnHKtfYD42/sRjmsYH9RWtqswRN Wq/QOrvBcDdqUI8k8LYD6SI58cBnCJX+Lb0smyTFzKsd3oP6EPv2H3USmhxHcFSnkEyfG EYbGT5DDbcGxuTrVh4aWO1IR2909XM+C6KCGRrwElVcDaH/LrjxKMS4GylTn5K10Ecw== 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=OkwQOwjz; 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 432A6606A322; Fri, 4 Dec 2026 20:20:17 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CA791F00936; Fri, 4 Dec 2026 20:20:14 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796415617; bh=qruuQn6uo2pXvQ+DR4RZESU/obVgiHNYEFeLcw5Jix0=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=OkwQOwjzY45erPyajgWbosxBRD1uMyTIM+iGSJDEUt1/UvGdfFofmqIXys4+g4oB2 Z/Yf/7z7Ruz0NsCOR/3yUI83u7n24jHf4aOzImWUGnYnyVd4/2xVN6f1Uc3nOWt9dN CxXs8GeaFhpMjNtyy8Nlw/UuIwaFYGn+Mxmc3EuiMyiIC/ZAEl2VlmqM5/WTMt17a1 1zW3ND+ES72ThbPIRWvUECe1i8WHtAPHgbHJXu8Cdo81aHxaE4vELXMI+cTSnxG6s3 PCZAOloF6ZuH3a4AOHEc/fzesz29aSXmFyLDOHaUiBAS3gSaKzNkF+O2+S/PmMbYvV ON/9Et3fqaF+A== 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>, Kuniyuki Iwashima <kuniyu@google.com>, Josef Bacik <josef@toxicpanda.com>, Alexei Starovoitov <ast@kernel.org>, Stanislav Fomichev <sdf@fomichev.me>, 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: <179568863376.462699.9896914557163021386@gmail.com>