Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.225 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796127836; b=41G6O/iwJp0OlAwiVAsMmxf3GwQTfq4dPOvin7xE/Jf3BJVv38mJIrYAVVfzY79fDPfC v3e69G2KMdbhRGhNIKqNaYFno9dGEOGL9o62KNvLSPHwRWVuouhkFB/xGyIpr3AIZxKFi pGd6uGG0/FtRQVdAAwvfsZUxO77N5koes6mHEtclu5ogX+4ABF6hiXfFl352oSfaiH31C aXvQYv/RAV6QbXpjzGHIrx7oqDE+aofXCc8yyFNgkD20xZfEM8V/3noaMTQ/yplID4kuW JdUhO1Dc1e2f7lUBTyXLY3AxWoQRsCTUkUSiHcGkK8Ficu3oqi8jbeW+RMjKWwx74Nw== 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=EQVH8maeXfrOanLEqVm11NtQ4XBfa35BL1+JcEXVv/0he2Iz7fta4UoLql14Vf7zhCUP A3pBHDO40mCVp9KzCHPim+S1dMjdVDzdQNw3rQYoH1rEtAP4M6nTE/AAQ03zg984jARhW 5+DciVR9RSf90uoFw+XT8iQzOhvwNH4Bk/UINYpXffs6lvBIBECTYUXvA5oT0aBQ3tuTh DaqRwA24UUuZDxkNZKMKf9A8ANExyIfxOMhOvCh5obm3n/nuSaJwxtzjQzFvgjMb/LDup raJAgWoYoha97Ke2eYL9GihLXw+2rcZVuUEsu6zi0aHqamSrxpcrB8KKdo8v05N4GeA== 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.225 Received: from mta1.migadu.com (out-225.mta1.migadu.com [95.215.58.225]) (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 32C7D606A334 for ; Tue, 1 Dec 2026 12:23:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 32C7D606A334 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev 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-Envelope-To: linux-kselftest@vger.kernel.org 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: linux-kselftest@vger.kernel.org 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 From: Jiayuan Chen To: bpf@vger.kernel.org Cc: Jiayuan Chen , John Fastabend , Jakub Sitnicki , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Kuniyuki Iwashima , Willem de Bruijn , Neal Cardwell , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , Shuah Khan , Sechang Lim , Mattia Meleleo , Michal Luczaj , Zijian Zhang , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org 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 Message-ID: <20261201122055.269577-7-jiayuan.chen@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261201122055.269577-1-jiayuan.chen@linux.dev> References: <20261201122055.269577-1-jiayuan.chen@linux.dev> X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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