From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A149469847 for ; Tue, 4 Aug 2026 10:14:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785838460; cv=none; b=SbznQmysvWx+/HC3ckUovB2SBUE5YDiGMGb6kUpWk1Od3L1s73E3CM4/bp8AXDp7aOgcHxFTOmALEmDJWvn/9xZCP0z6aShWH6+LcHHUMUyu7/smvVvMbW6tvUP3FL8zuoj7YWt6Z+KpcM4xXMOu2niE8Prh3+72EzfpLm/9SS8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785838460; c=relaxed/simple; bh=KpZBFyVOZN6T3WZQDyMUDJB9FDOnzr878tykr+VvuoI=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=WqWB3HCoIAdiT3qFna7yJ53gNvZ5DSheJDyBDCXKYKRftSpK4mzSZ6qSUq0Tuzg5OCLH3omdUVFTg/N3cYrZsGSioF90ljXCHt24ycLg6v483A1robPs5zo3pPGq2+p0BuaKZDA4787P1m5+Wd1gzZROP4X55POWX651VHphsJo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com; spf=pass smtp.mailfrom=cloudflare.com; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b=OGKfKHHE; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="OGKfKHHE" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-c1c52d920b8so626747466b.2 for ; Tue, 04 Aug 2026 03:14:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google09082023; t=1785838457; x=1786443257; darn=vger.kernel.org; h=content-type:mime-version:message-id:date:user-agent:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to:content-type; bh=KpZBFyVOZN6T3WZQDyMUDJB9FDOnzr878tykr+VvuoI=; b=OGKfKHHEdDEA5FO3z+wPhfjCAedsWiy5Wxs2Mx1qJwJJX2Pkd4G2zkyuBk3/wyRjT0 D9qkdWUjgiD3t9y8f+V8+g1XLbFMZMEQ1VjpEZ4u9y+aGOtndcVzF5ggMPkb8QsoLb3x DRZKvntEFoSeNowKsDzphPp7fDnRhV6KdFqJFbysaRamlylqxc+QJqrmfriio0zqD/Jd mGl8y5AFMyXNSzqD6e9Kw1wmgvv24ynoc1YrLuWTiglcxDXxhE0SDcuPOQuwC1FdtWMl yjLHOWUyhHA/UGTTSoecQutyMEfIrS+birxZexLPxNnJrxdBF5y3mLd62yPaVv3nuf1h e8Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785838457; x=1786443257; h=content-type:mime-version:message-id:date:user-agent:references :in-reply-to:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to:content-type; bh=KpZBFyVOZN6T3WZQDyMUDJB9FDOnzr878tykr+VvuoI=; b=q7crU25RtPneGzzcAcMt1153zxlsGnVeZhLG64tt2tkJrEDAEJqP3rnJ7Pmybp1v0/ Yz78TuLIkMw3c0j2lQ5B5TpnQa3mljawEP0WN05m0wknOG+cWApJrZp+gq6ENhiAbvla J/u4fAI4i/VyzTAmu+lDJkKlEApx+8bqeRr3EYat0cZ6CBUWe9vNeOrl1x5YjnLrdPLA db+A518nW5vMxuFIStRiFTh5Om8bqrUrOjCmv0PoGWfuV4fB/vblln3rZejDlwWQ7iK4 n4h2kq+R3bNurVp6rWM8gKYHO6no2Upe9l8zNr1GOlVxedB6fIs4HU6EMyZidlUkEOeo EIKw== X-Forwarded-Encrypted: i=1; AHgh+Rq3lbmt1OPUhQAUkl8kEAYAeJj4tib0ZxmMtMO8kLBxtRxeDRgD1KTdNh8KwuFiaw96K5hoEboG4oZG4z4=@vger.kernel.org X-Gm-Message-State: AOJu0YxskXBhOrMhWrzi1DKVL8yAOiN7MPiSKbkR+GhwlL9uADWiJZGn Vrdw20Tc76qDWyQN6ZicX7BX5tVth+fIYmN2ckfvJnX6sQULO5BMEWAlQduMHG3COgQ= X-Gm-Gg: AR+sD130B6C5dPdyfoiqKBSAWK8PjQipdHP5+rgvqvhtU1420X8s/HC0HOO0UzxuVmu 2EaHVBCSMCXV7l0n4wbQ49ieEuiI69rgalTUhqN9RtRNVaatKNYDCtgADJWyOS5zYdcvdGYhS4I b4087VtlvYNlTaDR6fGdgWd+VZE1Z2sSzzBOb2s17PiUcmCDoGwF5jQHGINkBS0np5EyLLdW0V9 wdq7SEaTCXSIFaka5dnPBGQX1LsmtT/HzuZm8oCfvH4tXOK0eLlzVlOy/vgRrgOrdt7Hbx41TKN jzdLgnkUuN2wqedY6/B50r3/jjFY4HEvY3P0uzKeaQeRZt021w4kDBac8y+s2aj9Afe10QRPH1A 16+9W+31xTZOo+OQTa2JYF6SSErymr0kz7iTkfqqL3k7nTHMe+TLH2LDC8W1MDsK/OplugOYBIa i97WS2lQ19XjbwGUZ1MYF1DCVYAW9hrkdxN/mh90s1G03eiwNCgFdrMgdJddDa5CI= X-Received: by 2002:a17:906:6a18:b0:c20:1c9d:8d4b with SMTP id a640c23a62f3a-c201c9d94e0mr545949266b.2.1785838456557; Tue, 04 Aug 2026 03:14:16 -0700 (PDT) Received: from cloudflare.com ([104.28.21.182]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c1fd4534fc4sm644439366b.51.2026.08.04.03.14.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Aug 2026 03:14:16 -0700 (PDT) From: Jakub Sitnicki To: Michal Luczaj Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , John Fastabend , Stanislav Fomichev , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Kuniyuki Iwashima , Willem de Bruijn , Jiayuan Chen , Joe Stringer , bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Sashiko Subject: Re: [PATCH bpf v2 2/2] bpf: Unconditionally take socket references in lookup helpers In-Reply-To: <20260803-sockmap-lookup-tcp-leak-v2-2-306e025bfe66@rbox.co> (Michal Luczaj's message of "Mon, 03 Aug 2026 11:00:43 +0200") References: <20260803-sockmap-lookup-tcp-leak-v2-0-306e025bfe66@rbox.co> <20260803-sockmap-lookup-tcp-leak-v2-2-306e025bfe66@rbox.co> User-Agent: mu4e 1.14.1; emacs 30.2 Date: Tue, 04 Aug 2026 12:14:14 +0200 Message-ID: <875x1qyyyx.fsf@cloudflare.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On Mon, Aug 03, 2026 at 11:00 AM +02, Michal Luczaj wrote: > Lookup helpers gate whether to acquire a socket reference on > sk_is_refcounted(), a check re-evaluated at release. An established socket > refcounted at acquire time can gain SOCK_RCU_FREE via > connect(AF_UNSPEC)+listen() before release runs; the release-side re-check > then reads sk_is_refcounted() == false and skips the put. The reference > leaks. > > Make acquire and release unconditional and symmetric: always take a > reference, always put it. Adapt sk_select_reuseport(). > > Fixes: 6acc9b432e67 ("bpf: Add helper to retrieve socket in BPF") > Fixes: 64d85290d79c ("bpf: Allow bpf_map_lookup_elem for SOCKMAP and SOCKHASH") > Reported-by: Sashiko > Closes: https://lore.kernel.org/bpf/20260701235552.2B0AA1F00A3F@smtp.kernel.org/ > Signed-off-by: Michal Luczaj > Reviewed-by: Emil Tsalapatis > --- > TC bpf_sk_assign() has the same issue; it takes a reference only when > sk_is_refcounted() is true at assign time, but sock_pfree() (the skb > destructor it installs) re-checks sk_is_refcounted() independently at > release time. The same connect(AF_UNSPEC)+listen() transition leaks the > socket here too. I'd welcome suggestions on the right way to handle this. Can we make this scenario unsupported? listen() could return EBUSY if called on a socket that is refcounted. WDYT?