From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) (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 A8DC5392C3D for ; Fri, 6 Mar 2026 14:33:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772807614; cv=none; b=m7kwzwWcANmux3Jw6nbtPLyK3oMH1K0tgYUADJxLe1zCH+sxzqIqaKr9+y7S25PQjkZXUboaiF4pPWeeGFi/zlAFv76KX941i5iQT1oDqtYhR1RhFsMObHm8FyEHrpQu5sAK+i2f83u0n8JuP21fn06yPgUJspVR7DcW4Mf81wU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772807614; c=relaxed/simple; bh=Ysl9chhusUB817jAQXGethrg3waZcOgyV/zi+p/14jc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=fE8lnJxx60VoE6VlSqZohN4alnCHgvHR7ik7Odm5u5+x5PFIG8ERivhuvRzaLNN5R5vGOXtDv1e5YitfSo3fE3SGNeBYQDNj1bt7BiERyp7QXiaQfRPkPgIBpbLoIl1WUuF6I7M0D7RsK8haudsH3lMA3w7Vlts2ZHr+KqBgi7M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=XG2clrQU; arc=none smtp.client-ip=91.218.175.178 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) header.d=linux.dev header.i=@linux.dev header.b="XG2clrQU" Message-ID: <80758367-e3fb-4f60-835e-57706c5a9589@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1772807610; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=URQHRYrZjIk3HFN36oTQy+hQ9dJ6v0hRv9nEIwzwOGU=; b=XG2clrQURzOHuuY20vaReoo2t3ZqglWQ3o9C3gKyS6r+8XJnSbjyDlPiTdfszjuo+RHSQb oJft+2fEBu1St16orCMYLfVrESm9o4ckti0QX2IHmrXlE3DzNwvZCUtB4ALTfvDMImrAzJ xMVV2RWpxr2Lb7LO2jBZrYl0RAcz7bM= Date: Fri, 6 Mar 2026 22:33:13 +0800 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH bpf v3 3/5] bpf, sockmap: Fix af_unix iter deadlock To: Michal Luczaj , 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 References: <20260306-unix-proto-update-null-ptr-deref-v3-0-2f0c7410c523@rbox.co> <20260306-unix-proto-update-null-ptr-deref-v3-3-2f0c7410c523@rbox.co> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Jiayuan Chen In-Reply-To: <20260306-unix-proto-update-null-ptr-deref-v3-3-2f0c7410c523@rbox.co> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 3/6/26 7:30 AM, Michal Luczaj wrote: > 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+0x37/0xe0 > #3: ffffffff85a6a7c0 (rcu_read_lock){....}-{1:3}, at: bpf_iter_run_prog+0x51d/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