From nobody Thu Apr 2 12:41:28 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 7E3E3366DA1; Thu, 5 Mar 2026 23:32:27 +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=1772753548; cv=none; b=qycNqE9yx6o1yVvX93ef2CndYFTSqTiY2doRJVfvPYc56Zsad5D6g7M6D6dGNunkA+Mb63Q3zqcOaqNAVTgeY3l0owJWyVP4c+RG9Ik3WxJTZPk6i3DILuLzplU2p6SuXkfM1hfAp1I3NqQ3Mg0U3fdta0GgcvAdK7RrRi6Cpvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772753548; c=relaxed/simple; bh=oNnL6PgF9i8BYLmz2dLn/HEJ+dwNCEs6Wzi0I8A2pHc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=J26TRuM/UljIu9UbQe2DwztkTLiMLyx9bYl0PkTd80L3liZHLw5Qx8Z1MhMRgQxOnaN7KqO5wakbeQ1SX8Ak38oBGrKxJZesW2X5fSq4KEDQrw5mGCYIncqmaMDzEFz8a2HY/GYRJAzvQYRlFCeZIDTqzPUVUPYGG0qscWKwOAc= 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=S++1oYfX; 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="S++1oYfX" Received: from mailtransmit02.runbox ([10.9.9.162] 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 1vyIB4-00130B-Uy; Fri, 06 Mar 2026 00:32:22 +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=KABCYR0VsFTXAqyXXhibjrexgB3N0ErIAHc1B1FNe3A=; b=S++1oYfXbyWS8Se+zDTggLJ7B1 0PtFtJ5xZIKHqqjwxPBxKrxTf/uW6/DI9JOb2IpkrEosZVGngQLoHkV3opIuPyYVi0/l13hHx/smh tZod1zSOj9kR9R+TZlo77KvkoW+StF9dMiWbsYG2Ph/2PixYtDTONl8zSjIS/Gn7VY+1pxQ3fUfkQ hjr3xPBbjq4V2Am7mNhKMQnizmnVRVpL3hkZSsKswxPvsnH9fY2rB7btl6PZitlCbxwLuIo7gB5cL yoCVDP6N9IPI3EX8T6uE/rNucfs/jN1aYYR+ULgxbbHvT2an9lglEfyHv06MvWwCDZ5SmCo/QFCq8 UFM835ew==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1vyIAu-0004DA-EG; Fri, 06 Mar 2026 00:32:12 +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 1vyIAK-00141B-Fy; Fri, 06 Mar 2026 00:31:36 +0100 From: Michal Luczaj Date: Fri, 06 Mar 2026 00:30:57 +0100 Subject: [PATCH bpf v3 3/5] bpf, sockmap: Fix af_unix iter deadlock 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-3-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 bpf_iter_unix_seq_show() may deadlock when lock_sock_fast() takes the fast path and the iter prog attempts to update a sockmap. Which ends up spinning at sock_map_update_elem()'s bh_lock_sock(): WARNING: possible recursive locking detected test_progs/1393 is trying to acquire lock: ffff88811ec25f58 (slock-AF_UNIX){+...}-{3:3}, at: sock_map_update_elem+0xdb= /0x1f0 but task is already holding lock: ffff88811ec25f58 (slock-AF_UNIX){+...}-{3:3}, at: __lock_sock_fast+0x37/0xe0 other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(slock-AF_UNIX); lock(slock-AF_UNIX); *** DEADLOCK *** May be due to missing lock nesting notation 4 locks held by test_progs/1393: #0: ffff88814b59c790 (&p->lock){+.+.}-{4:4}, at: bpf_seq_read+0x59/0x10d0 #1: ffff88811ec25fd8 (sk_lock-AF_UNIX){+.+.}-{0:0}, at: bpf_seq_read+0x42c= /0x10d0 #2: ffff88811ec25f58 (slock-AF_UNIX){+...}-{3:3}, at: __lock_sock_fast+0x3= 7/0xe0 #3: ffffffff85a6a7c0 (rcu_read_lock){....}-{1:3}, at: bpf_iter_run_prog+0x= 51d/0xb00 Call Trace: dump_stack_lvl+0x5d/0x80 print_deadlock_bug.cold+0xc0/0xce __lock_acquire+0x130f/0x2590 lock_acquire+0x14e/0x2b0 _raw_spin_lock+0x30/0x40 sock_map_update_elem+0xdb/0x1f0 bpf_prog_2d0075e5d9b721cd_dump_unix+0x55/0x4f4 bpf_iter_run_prog+0x5b9/0xb00 bpf_iter_unix_seq_show+0x1f7/0x2e0 bpf_seq_read+0x42c/0x10d0 vfs_read+0x171/0xb20 ksys_read+0xff/0x200 do_syscall_64+0x6b/0x3a0 entry_SYSCALL_64_after_hwframe+0x76/0x7e Suggested-by: Kuniyuki Iwashima Suggested-by: Martin KaFai Lau Fixes: 2c860a43dd77 ("bpf: af_unix: Implement BPF iterator for UNIX domain = socket.") Signed-off-by: Michal Luczaj Reviewed-by: Jiayuan Chen Reviewed-by: Kuniyuki Iwashima --- net/unix/af_unix.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 3756a93dc63a..3d2cfb4ecbcd 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -3729,15 +3729,14 @@ static int bpf_iter_unix_seq_show(struct seq_file *= seq, void *v) struct bpf_prog *prog; struct sock *sk =3D v; uid_t uid; - bool slow; int ret; =20 if (v =3D=3D SEQ_START_TOKEN) return 0; =20 - slow =3D lock_sock_fast(sk); + lock_sock(sk); =20 - if (unlikely(sk_unhashed(sk))) { + if (unlikely(sock_flag(sk, SOCK_DEAD))) { ret =3D SEQ_SKIP; goto unlock; } @@ -3747,7 +3746,7 @@ static int bpf_iter_unix_seq_show(struct seq_file *se= q, void *v) prog =3D bpf_iter_get_info(&meta, false); ret =3D unix_prog_seq_show(prog, &meta, v, uid); unlock: - unlock_sock_fast(sk, slow); + release_sock(sk); return ret; } =20 --=20 2.52.0