From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796412459; b=Da4jkJ7PQjr+sn+S+chQnLBr14CkAfucrszZb/dr00sLvZK3nYaB+wuzalceqnMNAahb zCWzfh18VZKvZrS+9WC8O+DG0kdH7QCMIDUxWQ00DsH/AQ33FlaxDKEU/bEs+Vm0Y/Aoy ZJ0qr4PmyuZfIqfr3F02wvvX34ZDzPPKRyNANm6LDHtnZnQasoJK4bczkqlSyiE63GpU3 941N3qUZNFdtqOO9VjkX9WnYFbSmeSYn0Y2TpqWnjSEwo8lQMUVlQDhqwn5f8Z6B4SWMA SHZ0rqwOzFc5YVCUh6+2AflbMyIBRyVpwh3PMhxOFi4HuJu1C2GY9Yv6NdwyBqx6wGA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796412459; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=G5Dr77alHupzr5LGit7sNmbcBnMJlw3SdHcMNEsktBs=; b=vF8+ieiLSRvKgVfZXo/HrT5+JK4wDXr+5CjZs3nWeukAGG75JQT8enM96ZU/9FWNFPfH 10m0L5KkOGB7cBwR+iup15A1m9k0V2uLExXEDnLDWPpDnfulp9GTx7OQt6ZPCn8HKfYsv EZKCiAnxSSf/QO7ZtWO20boL1BI6ItQUB/SFGazeWn11XIcorMlg4aXZF7odRi4BHr2jS xyekAhL2mTXZyFaW0MYUMHdCfGv1X+UWZG9VP1/XVycaVzkTOzNWgd5kYTj8DvLUDaF7G uLaU7Y+uslpwZ61RWT5vqQAA5Fq9MaH7ft8yCBBi5ENXnPDA1GmCSzIXMHoL3Nirp6g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ekRyBidC; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7AB92606A322; Fri, 4 Dec 2026 19:27:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=ekRyBidC Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A1801F00936; Fri, 4 Dec 2026 19:27:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796412459; bh=G5Dr77alHupzr5LGit7sNmbcBnMJlw3SdHcMNEsktBs=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=ekRyBidC1GCyktlrWMaK+Dkb0geSNopxbmGMRxd9Euq4w6aPSZXEHXo4rRJIyy7we GvFmwdlbu8DVkKVCEXmcdDqVExI20eky6UKJfdS30oe7kSg2Jqv2dxtf0OHUH4dS6Z QtcaUnxLSksO90VGVnAMB2LVqFhExHcsZW+P/vEXENbpIFbXBjlRlqQfCZiBjGGC4L O1bgVoUDMdpCH8H+ZFUbS+irMKZ1JMb2m+Q1XRXCSeXHaivsRi6oD3bvO7xhLyU74B emlc91hWKi3MCeVW3LqtvRd9Zsffc1X1ugJEhiHBFliy0Gd2G5GDzSEt9BUSSrK7Nk lJXvItWUHGxTQ== Date: Fri, 4 Dec 2026 19:27:34 +0000 From: Simon Horman To: Henry Martin Cc: david@ixit.cz, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, oe-linux-nfc@lists.linux.dev, netdev@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH nfc v3] nfc: llcp: reject bind and connect while the socket is still linked Message-ID: <20261204192734.GC192805@horms.kernel.org> References: <20261125080706.648722-1-bsdhenrymartin@gmail.com> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261125080706.648722-1-bsdhenrymartin@gmail.com> On Wed, Nov 25, 2026 at 04:07:06PM +0800, Henry Martin wrote: > llcp_sock_connect() only rejects LLCP_CONNECTED and LLCP_CONNECTING, so a > socket that is still linked in local->sockets can be linked a second time > into local->connecting_sockets. That covers bound and listening sockets, > and sockets that a peer moved to LLCP_CLOSED with DISC or DM. > > Both lists use sk->sk_node. When the peer answers with CC, > nfc_llcp_recv_cc() removes the node from the connecting list and links it > back into local->sockets, where the stale bind-time entry makes the node > point to itself. Every later sk_for_each() over local->sockets then spins > forever with the read lock held, which pins the CPU and stalls RCU, and > the socket is never freed. > > The same stale-link case reaches llcp_sock_bind(): nfc_llcp_recv_disc() > and the non-connecting branch of nfc_llcp_recv_dm() move a socket to > LLCP_CLOSED without unlinking it, and bind() only checked sk_state, so > it would link sk_node into local->sockets a second time. > > Reject connect() and bind() while sk_node is still linked. A socket > has to be closed before it can be connected or bound again. > > Reproduced on v7.4-rc3 as uid 1000: a soft lockup / RCU stall in > nfc_llcp_sock_from_sn() while walking local->sockets. > > This issue was discovered by Tencent CodeBuddy Security. > > Link: https://lore.kernel.org/all/20261009092338.3146149-1-bsdhenrymartin@gmail.com/ > Fixes: a69f32af86e3 ("NFC: Socket linked list") > Cc: stable@vger.kernel.org > Signed-off-by: Henry Martin > --- > v2 -> v3: apply the same sk_hashed() guard to llcp_sock_bind(): a socket > that a peer moved to LLCP_CLOSED with DISC or DM stays linked > in local->sockets, and bind() only checked sk_state, so it > could link sk_node a second time (reported by sashiko's > review of v2). > v1 -> v2: reject any socket that is still hashed (sk_hashed) instead of only > LLCP_BOUND, covering bind()+listen()+connect() and sockets left > linked after DISC/DM. Reviewed-by: Simon Horman