From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CA791F00936; Fri, 4 Dec 2026 20:20:14 +0000 (UTC) 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== Date: Fri, 4 Dec 2026 20:20:11 +0000 From: Simon Horman To: Kyuwon Cho Cc: Steffen Klassert , Herbert Xu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Kuniyuki Iwashima , Josef Bacik , Alexei Starovoitov , Stanislav Fomichev , netdev@vger.kernel.org, ipsec@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH ipsec v3] net: free the socket policies when sk_clone() fails Message-ID: <20261204202011.GH192805@horms.kernel.org> References: <179568863376.462699.9896914557163021386@gmail.com> X-Mailing-List: linux-kernel@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=us-ascii Content-Disposition: inline In-Reply-To: <179568863376.462699.9896914557163021386@gmail.com> 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 > Signed-off-by: Kyuwon Cho > --- > 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