Article View: linux.kernel.netdev
Article #25227[PATCH bpf v2 06/10] bpf, sockmap: Fix psock refcnt taken in sk_psock_backlog()
From: Jiayuan Chen
Date: Tue, 01 Dec 2026 12:18
Date: Tue, 01 Dec 2026 12:18
35 lines
10588 bytes
10588 bytes
sk_psock_backlog() runs for a given psock, but takes the reference with
sk_psock_get(psock->sk), which returns the psock that sk_user_data points
to now. That is the same psock only while psock->sk->psock == psock.
If sk is removed from the map and added back while the backlog runs, the
old psock is dropped and sk_user_data points to the new one. The backlog
of the old psock then takes a reference on the new psock and puts the old
one, whose refcnt is already 0. The old one hits a refcount underflow and
the new one leaks a reference. The SK_PSOCK_TX_ENABLED check before it
does not close this window.
Take the reference on the psock itself.
Fixes: 8259eb0e06d8 ("bpf, sockmap: Avoid using sk_socket after free when sending")
Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
---
net/core/skmsg.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/skmsg.c b/net/core/skmsg.c
index dcae3cd968edc..da9b60f34e2df 100644
--- a/net/core/skmsg.c
+++ b/net/core/skmsg.c
@@ -707,7 +707,7 @@ static void sk_psock_backlog(struct work_struct *work)
* before sk_socket freed. If refcnt increment fails, it indicates
* sock_map_close() completed with sk_socket potentially already freed.
*/
- if (!sk_psock_get(psock->sk))
+ if (!refcount_inc_not_zero(&psock->refcnt))
return;
mutex_lock(&psock->work_mutex);
while ((skb = skb_peek(&psock->ingress_skb))) {
--
2.43.0
Technical Details
Message-ID:
<20261201122055.269577-7-jiayuan.chen@linux.dev>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-375015-linux-kernel-netdev=dewy.ruReferences:
<20261201122055.269577-1-jiayuan.chen@linux.dev>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-375015-linux-kernel-netdev=dewy.ru From: jiayuan.chen@linux.dev (Jiayuan Chen) Newsgroups: linux.kernel.netdev Subject: [PATCH bpf v2 06/10] bpf, sockmap: Fix psock refcnt taken in sk_psock_backlog() Date: Tue, 1 Dec 2026 20:18:54 +0800 Organization: Usenet Network Message-ID: <20261201122055.269577-7-jiayuan.chen@linux.dev> References: <20261201122055.269577-1-jiayuan.chen@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1707917"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:mpx1D7KBhdbIcLJimqKdBMuCHA4= sha256:jkqC9a5yOENDmFAI67XhBhncA2gI1cmHPNls4KfSCCE= sha1:Yb7Iqg4ZQhh0RszJUXyhJrbDwxU= sha256:ClNXr9Pvqd68aoo3n5FZyzpEvxVpzTOM6/u+k+n6zPs= 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 A14ED117370; Tue, 1 Dec 2026 15:24:14 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.05 X-Spam-Status: No, score=-2.05 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.249, HK_RANDOM_FROM=1, 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 (1024-bit key) header.d=linux.dev 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 bjOwaG5ftaya; Tue, 1 Dec 2026 15:24:12 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-375015-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id D464811736A; Tue, 1 Dec 2026 15:24:01 +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 5C24E27722; Tue, 1 Dec 2026 12:24:00 +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=1796127837; b=DoCsz4DTrekDWcOYLINF9Ejp16Rbv7DIkfSE48PGfk+nj2GXVSOZV0REb0XRsdszu+r6 3gbWYPtX3O54TjzpZRRfSlLUunNdUtiiUTJjwkNc3ZwFx3SES6n9GR61ZCc0ddUpqdwrV xNZCMDmt/yn52TWjFWHstO3cu3CINhsE85V/AefPD3KjSa1pO3bEKbsIRCFS9Jb3IGpFo 78Ppu83FHUAHX7ufWv3PfuD+hXC+ifyDJ6JDAz9CAcAOUeblpXpTMZPgER8Q6n85y73sn EVXmsRtSjwCnWt0gUlne1yw+ozCituvV2/Zm7RT1M+ZtX0NqDs+Hq6047APpZ3EYsSQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796127837; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow: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; bh=+WjgXs/z/froa4HQN2e1o5ivQ7cFAVGLI4tDzABOvUI=; b=tvsAjNQV6nfg+w8WgHUKkgvA/vqisZQXZQPaZa3zB3Uf3eLUJKLBfUSojb2dU4iQra1L ySJvzwhrNnsLUAhAbdoL/51wdj7LFPqdEBrNxENC2sYYMS11VMpKv0ZqhAZUluvYoRhjX nVhtnPVnKhqY2rS8DEVwyYN7uui4zzNTOfhj3Uet5Fg+5zaxW/gfhWDun88C3OHUxdZaG 3ZvRaH9TxXUipcoDCs37voyaQZJLqWyCVCotgXXq40P+5WTY9v0+IS9VxNy2zqY3SyfMT rrG9GfTxaPZ+ZF9xdhnWk4UC1lwQvhMz1+64aB5sAW78fkhXHMcK3qgoXYsJ7oGffqQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=rOBQoYX3; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; 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 9FB8D606A682; Tue, 1 Dec 2026 12:23:57 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=rOBQoYX3 X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.223 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796127836; b=qaJ8fERsiY5YsB5Tq1Vo4H5Wkkoa4L0cxI8eEWL+f7RTTGQxu98VQOToHFdwTht6nQKD GS0oP28k5eYgx2C6mBjagxLZUr6CdM623Q0Bo00uiCvhFRdz38QzoMyE78WryBcUqlZWu 4rgqGsTmEBTh9TkVyYvqJ/jVjKnGYpftVWkDyAWgVmzP4xx67TUAI2CWVCrGwERE6xPXh JTYHMsbnB4vJMqZ+zFaqg3m5Tyn34y9soa+qBrvBQniMHvyet6bFbBToveDgsPtstZjhV 0u01x8QVbaQnoGlIhOoCDTtKnx8heZ/YQyclwVyOguWTJT5SP6XY367P/75m2T+5GrA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796127836; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=+WjgXs/z/froa4HQN2e1o5ivQ7cFAVGLI4tDzABOvUI=; b=yLwatx6XWVPZSAqMF4mE8K8gcB2TFfjEf5inPHfqywt3yXf2h1LZBTZZncC/9Wg6pGDU LeVy44AxiOKb2H9BdzrTPixo2+YAGaHyww8LlasRSItDLHzapFywQjmcL3we9T2XmA1gv k0UZXNPPl24ClWnyEIuTV4p2j9uFCDtfcWm5P2t9Enazz6CME4F3Yvqiz4AJujddn4uGx wZZ+TRTaPrvvCrSkHYjS3GWrC8c0UiIe59TgPNKxnel+vElxFEpErLoPh7y86EEYptTll fizqNihNyLD/11Q/Iup0QEf8fROn7ZVcDIx1T7/eSBaa5Do8L99lNUJY3z9XGWsy37g== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=rOBQoYX3; arc=none smtp.remote-ip=95.215.58.223 X-Received: from mta1.migadu.com (out-223.mta1.migadu.com [95.215.58.223]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28DE9606A333 for <netdev@vger.kernel.org>; Tue, 1 Dec 2026 12:23:55 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 28DE9606A333 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=15dAEBMpdisRme/UozWWdgmYnRz03Ng9XlVjSemjwh8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796127834; v=1; x=1796732634; b=rOBQoYX3eklCoIkiVPL8ZqlyBmIm5wpL3gQjsSDD3s5oWALwquLfHfAL1wX5zfGiATuDYXE1 G5K+4MOrN9/b83XiujmhS14nLjrPV+jSrdfA5jP0b+/zHEYqyHfNRBPRouMXDPceeTuG9jbWy/p F4oRyxVDywm6ElOYdxQ9qa4c= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id 56eeeecfe92a90dd; Tue, 01 Dec 2026 12:23:54 +0000 X-Mizu-Trace-ID: 56eeeecfe92a90dd X-Migadu-Flow: FLOW_OUT X-Cc: Jiayuan Chen <jiayuan.chen@linux.dev>, John Fastabend <john.fastabend@gmail.com>, Jakub Sitnicki <jakub@cloudflare.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@kernel.org>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>, Kuniyuki Iwashima <kuniyu@google.com>, Willem de Bruijn <willemb@google.com>, Neal Cardwell <ncardwell@google.com>, Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Andrii Nakryiko <andrii@kernel.org>, Eduard Zingerman <eddyz87@gmail.com>, Kumar Kartikeya Dwivedi <memxor@gmail.com>, Martin KaFai Lau <martin.lau@linux.dev>, Song Liu <song@kernel.org>, Yonghong Song <yonghong.song@linux.dev>, Jiri Olsa <jolsa@kernel.org>, Emil Tsalapatis <emil@etsalapatis.com>, Ihor Solodrai <ihor.solodrai@linux.dev>, Shuah Khan <shuah@kernel.org>, Sechang Lim <rhkrqnwk98@gmail.com>, Mattia Meleleo <mattia.meleleo@coralogix.com>, Michal Luczaj <mhal@rbox.co>, Zijian Zhang <zijianzhang@bytedance.com>, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org X-Mailer: git-send-email 2.43.0 X-In-Reply-To: <20261201122055.269577-1-jiayuan.chen@linux.dev> 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