From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) (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 29B1A25F99B; Fri, 6 Mar 2026 06:15:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772777756; cv=none; b=ARxx3yu20flaqhYCC/t1WY23E9UIq0XL0kwwM+Q72U0bAN5/rmROHR2U4TsilA7/hy4wSLSS+v9TDx/3HQ/OjMVRwwl2hsx5vk39VRFmckve547BqdtKpnUb4849K8pFnj0ybQAAkcMpYQqNneN7WHH26rUfHvT3eTX3xG+8FXk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772777756; c=relaxed/simple; bh=hGtRcnWTy/PpFFzdK7d1MHZ61VyPgPTh0NNGxvvrpIw=; h=MIME-Version:Date:Content-Type:From:Message-ID:Subject:To:Cc: In-Reply-To:References; b=F71RHUXDRFI2iSd5UFMeNRU8usD+sPP2LhV9f0/gtqz457aSJthFeEKywGcm2GnIicYy859jtXQf8RUcm4+Y8j0ncLHwfoRzgy1wxL38FmpZJXDLnR0p3C0iQm84zJss2Cs1HSFfMEvsQdu503EoUEyVaVNUzaQVL0qT6Q8EjNU= 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=fAl+knHo; arc=none smtp.client-ip=95.215.58.172 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="fAl+knHo" Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1772777752; 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=vqXgGoazXTsI2u6OsAzXa6/DneMpo4x6tpW9FL9NTEU=; b=fAl+knHob6eDuMaiQ7kRog26/CIu2cadYe/IsQHXVwIXoDzk9ezDPQrCTZHKwnbPfuJO37 6QBhpUTUrc0qMzUEf0UtMRuIGZZ/0hxZuFPIo3yhHfZKuvd934sUgz4tQyR6I7vljMn9jh ODFAe6dFYYTHQn1gjJxWbG2TQfambIE= Date: Fri, 06 Mar 2026 06:15:45 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: "Jiayuan Chen" Message-ID: TLS-Required: No 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 In-Reply-To: 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-Migadu-Flow: FLOW_OUT March 6, 2026 at 14:04, "Jiayuan Chen" wrote: >=20 >=20On 3/6/26 7:30 AM, Michal Luczaj wrote: >=20 [...] >=20> 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; > > > if (v =3D=3D SEQ_START_TOKEN) > > return 0; > > > - slow =3D lock_sock_fast(sk); > > + lock_sock(sk); > > > - if (unlikely(sk_unhashed(sk))) { > > + if (unlikely(sock_flag(sk, SOCK_DEAD))) { > > ret =3D SEQ_SKIP; > > goto unlock; > > } > >=20 >=20Switching to lock_sock() fixes the deadlock, but it does not provide = mutual > exclusion with unix_release_sock(), which uses unix_state_lock() exclus= ively > and does not touch lock_sock() at all. So a dying socket can still reac= h the > BPF prog concurrently with unix_release_sock() running on another CPU. >=20 >=20Both SOCK_DEAD and the clearing of unix_peer(sk) happen under > unix_state_lock() in unix_release_sock(). Without taking unix_state_loc= k() > before the SOCK_DEAD check, there is a window: >=20 >=20iter unix_release_sock() > ---=C2=A0 lock_sock(sk) > SOCK_DEAD =3D=3D 0(check passes) > =C2=A0=C2=A0unix_state_lock(sk) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0unix_peer(sk) =3D NULL > =C2=A0=C2=A0sock_set_flag(sk, SOCK_DEAD) > =C2=A0=C2=A0unix_state_unlock(sk) > BPF prog runs > =E2=86=92 accesses unix_peer(sk) =3D=3D NULL =E2=86=92 crash Sorry for malformed message. Here is correct: iter unix_release_sock() --- lock_sock(sk) SOCK_DEAD =3D=3D 0 (check passes) unix_state_lock(sk) unix_peer(sk) =3D NULL sock_set_flag(sk, SOCK_DEAD) unix_state_unlock(sk) BPF prog runs =E2=86=92 accesses unix_peer(sk) =3D=3D NULL =E2=86=92 crash