From nobody Thu Apr 2 11:02:22 2026 Received: from mailtransmit04.runbox.com (mailtransmit04.runbox.com [185.226.149.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6430B36920C; Thu, 5 Mar 2026 23:32:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.226.149.37 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772753526; cv=none; b=qPBDvPz8plkhG/pA8PYgmeQH96Fjd2AgFa7ctGts52RQm+ek8GpzkoxNSsrQmEYLbUXBZ0cGva06aqKnfLec7ZI5V3QLhXObWAgWtFIvcZmC0xhUMY51EJ3SsbB+JsBf5Qc46Y8VY/RDbzpMrEiprnxAPjMoW2/+WSCIw6sZepk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772753526; c=relaxed/simple; bh=ZQr+WTwSnte7ugmiliHwL9asahOJBYvUnHt5xYlz2Is=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UTQuPKMCzYzDKovXlgfsBCYZ7vTiLjPfu3Qwn4UX8v1a9hGmbidIDQnZJ/P3G6YYz5PDvaKxjaiO6AxbVjoQl8RcBRGCwFDc+/qY28hiXzdQsjaJJCFipN5kiqRb5ucY79ay2VN11I3klhpII03HLMmUSstioBgY3U1MZ5Q3FhE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co; spf=pass smtp.mailfrom=rbox.co; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b=vRFIZhJJ; arc=none smtp.client-ip=185.226.149.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rbox.co Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rbox.co Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rbox.co header.i=@rbox.co header.b="vRFIZhJJ" Received: from mailtransmit03.runbox ([10.9.9.163] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1vyIAh-0012v4-04; Fri, 06 Mar 2026 00:31:59 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rbox.co; s=selector1; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From; bh=sSLGc2cwazj/BaeN56d1lulum1UQWYpoeFSBe7HE8yA=; b=vRFIZhJJcAGnOJWZcaWpLMUK3U s7g9UQCDGwOLLGkT1dnmH0FT7D7mFULlJ3yOf6Aa7NgkQWetTYzR+r3abBqx3lAJILtcQaaXg1u3z kYj0X9ooz8MLrgo29U9M3MsKVISHyjRYm9tJV5+YuAQVuGEHx9M/SCKuUq3jiVuLGfjKFI93ogi+6 7zjjjSavw8dZvTVvJduKT5NS8uqQ1cjZr6aENxdEDFP/zT56ZOEXmzaYfg/GFFLEXT1244EGOXoRU 3GfvUCLQSr9bR2vbvOGYoXb1mREQxvsXpfp3qRI3V8fVeZgpB1Cm19wl/ndCsOSU2TCbjaiAb14bp AyDWWEyw==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit03.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vyIAg-00024o-AK; Fri, 06 Mar 2026 00:31:58 +0100 Received: by submission02.runbox with esmtpsa [Authenticated ID (604044)] (TLS1.2:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) id 1vyIAJ-00141B-1j; Fri, 06 Mar 2026 00:31:35 +0100 From: Michal Luczaj Date: Fri, 06 Mar 2026 00:30:56 +0100 Subject: [PATCH bpf v3 2/5] bpf, sockmap: Use sock_map_sk_{acquire,release}() where open-coded Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260306-unix-proto-update-null-ptr-deref-v3-2-2f0c7410c523@rbox.co> References: <20260306-unix-proto-update-null-ptr-deref-v3-0-2f0c7410c523@rbox.co> In-Reply-To: <20260306-unix-proto-update-null-ptr-deref-v3-0-2f0c7410c523@rbox.co> To: John Fastabend , Jakub Sitnicki , Eric Dumazet , Kuniyuki Iwashima , Paolo Abeni , Willem de Bruijn , "David S. Miller" , Jakub Kicinski , Simon Horman , Yonghong Song , Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Cong Wang Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Michal Luczaj X-Mailer: b4 0.14.3 Instead of repeating the same (un)locking pattern, reuse sock_map_sk_{acquire,release}(). This centralizes the code and makes it easier to adapt sockmap to af_unix-specific locking. Signed-off-by: Michal Luczaj --- net/core/sock_map.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/net/core/sock_map.c b/net/core/sock_map.c index 02a68be3002a..7ba6a7f24ccd 100644 --- a/net/core/sock_map.c +++ b/net/core/sock_map.c @@ -353,11 +353,9 @@ static void sock_map_free(struct bpf_map *map) sk =3D xchg(psk, NULL); if (sk) { sock_hold(sk); - lock_sock(sk); - rcu_read_lock(); + sock_map_sk_acquire(sk); sock_map_unref(sk, psk); - rcu_read_unlock(); - release_sock(sk); + sock_map_sk_release(sk); sock_put(sk); } } @@ -1176,11 +1174,9 @@ static void sock_hash_free(struct bpf_map *map) */ hlist_for_each_entry_safe(elem, node, &unlink_list, node) { hlist_del(&elem->node); - lock_sock(elem->sk); - rcu_read_lock(); + sock_map_sk_acquire(elem->sk); sock_map_unref(elem->sk, elem); - rcu_read_unlock(); - release_sock(elem->sk); + sock_map_sk_release(elem->sk); sock_put(elem->sk); sock_hash_free_elem(htab, elem); } @@ -1676,8 +1672,7 @@ void sock_map_close(struct sock *sk, long timeout) void (*saved_close)(struct sock *sk, long timeout); struct sk_psock *psock; =20 - lock_sock(sk); - rcu_read_lock(); + sock_map_sk_acquire(sk); psock =3D sk_psock(sk); if (likely(psock)) { saved_close =3D psock->saved_close; @@ -1685,16 +1680,14 @@ void sock_map_close(struct sock *sk, long timeout) psock =3D sk_psock_get(sk); if (unlikely(!psock)) goto no_psock; - rcu_read_unlock(); sk_psock_stop(psock); - release_sock(sk); + sock_map_sk_release(sk); cancel_delayed_work_sync(&psock->work); sk_psock_put(sk, psock); } else { saved_close =3D READ_ONCE(sk->sk_prot)->close; no_psock: - rcu_read_unlock(); - release_sock(sk); + sock_map_sk_release(sk); } =20 /* Make sure we do not recurse. This is a bug. --=20 2.52.0