🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21596

Re: [PATCH net v2] nfc: llcp: fix socket list self-loop on connect of a linked socket

#21596
From: netdev-bot+sashiko
Date: Tue, 24 Nov 2026 08:26
186 lines
14693 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 (1) · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] Incomplete fix: the same sk_node double-link, and the same
  endless loop over local->sockets, can still be reached through…
- [Low] The new check in llcp_sock_connect()
  (net/nfc/llcp_sock.c:722-725) returns -EISCONN for any hashed socket,…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is the same
  shared-sk_node bug class, in the same function, and it is still…

--

nfc: llcp: fix socket list self-loop on connect of a linked socket

This patch makes llcp_sock_connect() reject a socket whose sk_node is
still linked, so that the node is never on both local->sockets and
local->connecting_sockets. Before this, nfc_llcp_recv_cc() could link the
node back into local->sockets and make it point to itself.

Link: https://lore.kernel.org/all/20261009092338.3146149-1-bsdhenrymartin@gmail.com/

> diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c
> index 1e5ee4bcde684..01b311d5adda1 100644
> --- a/net/nfc/llcp_sock.c
> +++ b/net/nfc/llcp_sock.c
> @@ -714,6 +714,15 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr_unsized *_addr
>  		ret = -EINPROGRESS;
>  		goto error;
>  	}
> +	/* A socket that is still linked in local->sockets must not be linked
> +	 * into local->connecting_sockets as well: both lists use sk_node, and
> +	 * the CC handler links the node back into local->sockets, which turns
> +	 * the stale entry into a self-loop.
> +	 */
> +	if (sk_hashed(sk)) {
> +		ret = -EISCONN;
> +		goto error;
> +	}

[Severity: High]
The commit message lists "sockets that a peer moved to LLCP_CLOSED with
DISC or DM" as one of the problem states. Can those sockets still get
their sk_node linked twice through llcp_sock_bind()?

nfc_llcp_recv_disc() moves a connected socket to LLCP_CLOSED but leaves
it linked in local->sockets:

net/nfc/llcp_core.c:nfc_llcp_recv_disc() {
    ...
	if (sk->sk_state == LLCP_CONNECTED) {
		nfc_put_device(local->dev);
		sk->sk_state = LLCP_CLOSED;
		sk->sk_state_change(sk);
	}
    ...
}

For any reason other than LLCP_DM_NOBOUND or LLCP_DM_REJ,
nfc_llcp_recv_dm() looks the socket up on local->sockets through
nfc_llcp_sock_get(). Since connecting is false in that case, the socket
stays linked:

net/nfc/llcp_core.c:nfc_llcp_recv_dm() {
    ...
	if (connecting)
		nfc_llcp_sock_unlink(&local->connecting_sockets, sk);

	sk->sk_err = ENXIO;
	sk->sk_state = LLCP_CLOSED;
    ...
}

That applies to connected sockets, accepted children, and bound or
listening sockets whose ssap/dsap match the DM.

llcp_sock_bind() only checks the state:

	if (sk->sk_state != LLCP_CLOSED) {
		ret = -EBADFD;
		goto error;
	}

nfc_llcp_sock_from_sn() skips CLOSED sockets. With a non-WKS service
name, nfc_llcp_get_sdp_ssap() therefore returns LLCP_SDP_UNBOUND, and
bind() reaches:

	nfc_llcp_sock_link(&local->sockets, sk);

nfc_llcp_sock_link()->sk_add_node()->hlist_add_head() runs on a node that
is already in the list. If the node was first, it now points to itself.
Otherwise the list gets a cycle.

Wouldn't every later sk_for_each() over local->sockets, such as
nfc_llcp_sock_get() in the RX worker or nfc_llcp_sock_from_sn(), then
spin forever with the read lock held? sk_add_node() also takes an extra
sock_hold() that is never released.

Should llcp_sock_bind() get the same sk_hashed() check? Alternatively,
the DISC and DM handlers could unlink the socket from local->sockets.

[Severity: Low]
This returns -EISCONN for any hashed socket, not just LLCP_CONNECTED
ones. That includes LLCP_BOUND and LLCP_LISTEN sockets, and sockets a
peer left in LLCP_CLOSED with DISC or DM. Is -EISCONN the intended errno
in those cases?

In the usual non-blocking connect pattern, a repeated connect() that
returns EISCONN means the socket is connected. After a CC and then a
default-reason DM, connect() would no longer report the pending ENXIO in
sk_err. The application would be told the socket is connected after the
link has gone away.

TCP's __inet_stream_connect() also returns -EISCONN for some
non-connected states, so this may be deliberate. Still, the other
wrong-state checks in this file (llcp_sock_bind(), llcp_sock_listen(),
llcp_sock_accept()) return -EBADFD. The commit message also doesn't
mention this change to the errno userspace sees.

[Severity: High]
This is a pre-existing issue and was not introduced by this patch. It is
the same shared sk_node problem in the same function, further down in
the sock_unlink error path of llcp_sock_connect(). Can that path unlink
the socket from the wrong list and drop the nfc_dev reference twice?

sock_wait_state() releases the socket lock while it sleeps:

		release_sock(sk);
		timeo = schedule_timeout(timeo);
		lock_sock(sk);

While the lock is released, the RX worker can handle a CC.
nfc_llcp_recv_cc() then moves sk to local->sockets and sets
LLCP_CONNECTED:

	nfc_llcp_sock_unlink(&local->connecting_sockets, sk);
	nfc_llcp_sock_link(&local->sockets, sk);

Before the waiter takes the lock again, the worker can also handle a
DISC or a default-reason DM for the same socket. nfc_llcp_recv_agf()
handles aggregated sub-PDUs one after another in a single worker run, so
one AGF frame carrying CC plus DISC would be enough.

After a DM, sock_wait_state() returns -ENXIO. After a DISC, sk_err is not
set, so the waiter sleeps until a signal arrives and returns -ERESTARTSYS
or -EINTR. In both cases connect() then runs:

	if (ret && ret != -EINPROGRESS)
		goto sock_unlink;
	...
sock_unlink:
	nfc_llcp_sock_unlink(&local->connecting_sockets, sk);

This takes connecting_sockets.lock, but sk_del_node_init() removes the
node from local->sockets. Isn't local->sockets then being modified
without local->sockets.lock, racing with its other writers and readers?

In the DISC case, nfc_llcp_recv_disc() has already called
nfc_put_device(local->dev) for the connected state. The error path then
falls through to:

put_dev:
	nfc_put_device(dev);

Could this underflow the nfc_dev refcount and eventually free the
nfc_dev while it is still in use?

The same path also frees service_name, puts the ssap, and clears
llcp_sock->local and llcp_sock->dev on a socket the peer had already
connected.

Should this error path use sk_state, checked under lock_sock(), to decide
which list to unlink from and whether to drop the device reference?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120075908.4064155-1-bsdhenrymartin%40gmail.com
Technical Details
Message-ID: <179550879966.3135.13090779183406614087@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370097-linux-kernel-netdev=dewy.ru
References: <20261120075908.4064155-1-bsdhenrymartin@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-370097-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] nfc: llcp: fix socket list self-loop on connect of a linked socket
Date: Tue, 24 Nov 2026 08:26:39 +0000
Organization: Usenet Network
Message-ID: <179550879966.3135.13090779183406614087@kernel.org>
References: <20261120075908.4064155-1-bsdhenrymartin@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network; logging-data="4087993"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:H4uVOD7B7E+U0PDkVT5IOAg8zzQ= sha256:1yRekubqU8vUONsuRaEtgOpiC0onRLFPY3kglHDWRx4= sha1:2p4Gb4cZsT4ge/vdQOebFkbnQOY= sha256:KA7WW2jjqSEgKWiiubFfwI0JlettpaBeQPMm8vbJCkU=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id BD4DC125DDC; Tue, 24 Nov 2026 11:26:59 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.501
X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0ffjmJz80CXG; Tue, 24 Nov 2026 11:26:55 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-370097-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 60912125DD6; Tue, 24 Nov 2026 11:26:46 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 931AF605C20; Tue, 24 Nov 2026 08:26:45 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795508802; b=n8h+MOiFcr32kZNUEwHpGQLWZxu8mVhFPEXk1KqVJZMbRa4wTlw8vq8udJtVZum2tD+b j1sGl/KfyCCcOAziWvV0Md2V94/ssTu99ylf+meo74GEswPSKK4NxgcbgyNHuIb6+FU1J nwbAgJ3VgkQufKT/D3m+6Ee+5R4mCsT8L1jiQPPJKIPIMtHV+2lk3Ri1Y8+lrdXmB061G yuk5g3VbnzE5p+wgORwf/ywLVhRkamrD+vPL80sxL5fgiX1u8PFijp+pysplRyVrwrx3C McLG7Ix9zrDZz4IuAyGoI1dks3AiJv2B6dJ7BltoEE2qA+/6drTE96Jt2BiHa5UQIKw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795508802; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=NIXNWsD1GnWzukxgS94b8Vtpt/UkvIRehEZsYKJ0bvU=; b=4vp6I3+7NRQc19N6nvj4y+rrQ08GhqX7vzMOKxZxxaaG4v01oLxXL6XD3HXUQd48aEjH Op58JOttRUQxZuD2ZH3wPVWmhpVlgDFEkYA4TOHHhHmK4bySY4iyb4TzeKPhgpBzbEgW7 tv3/dYm5ie1t3bEQlhCJ81aW1aA4ATDGbqn5LCT5EUI5eTl9Rtk1/IYORIFnUX2nD3y7R ZhP1CmH7ffxJ1ZPyCy1Y8LDRAI//EoSBXQO5NnUALIQBRbTf6uwFbseJDKXiSWf48hQdH yn6l01b4enKMJiC/r2SsGX84Iglto9vn1br59c62qpdLscEklILOHnSXqE541F7eVIA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jHXdmBoI; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E9C37606A330; Tue, 24 Nov 2026 08:26:41 +0000 (UTC)
X-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=jHXdmBoI
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795508801; b=wnAf/5Mwm32hNJh7xtAwFHAmsUHMYNex7iKf3KtX/luc8jSHTVr8+hOriGA83Gf14p3c wq+LpQrUxzaqfu9vuoNON58o5mEPn4kq35hQUL0ULJXPrvd222Vv4bUnp99AN42cwXoYr Z+xYN63gmoABLwbHNxwryfRBm1DiZLfJ9hbw6XF2vVkNyDk384eDwX09vlPgsUdSONlyo 2+uqTOPFwzoIOXUOqvuIBBw3BSRtvsGD1MckASFN49CJNk1FBwr1XmZdQHVNub9LlXM62 AMWLHLwphQT8qcMAyfaimVW3+5rIngC7iOJWRwtvJ0mLYqmg1iRofbotOcLw2SYJDuA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795508801; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=NIXNWsD1GnWzukxgS94b8Vtpt/UkvIRehEZsYKJ0bvU=; b=5QAUXXYdlxQdVk2MDQgB2q9kYZL1tqAq9sBca2LONWtBk9w9fZUZLmsSk4tDVIpHqNJe OQknG1MwNFV9RpPsmz5uY9DU8dMV/RU7PJQuPBkgU6wEAzIRHhrN90OxRR7SrcrDn6v1Q eoZCI7oTgFd5jj3NjLgOL8CCZb5gIJpMJyMKBKTNzKAkx8H+816Uyxj9YlBGqaWhumNBs TucAMkaIq7nQvahRwL9Cwk5/ButBHN/lqH3WjXsX+bDEl1txWItv41h3NbIxCq4GbMOFj I0tWLThndvhyTTOWtwoIdNoi/N86dDxOoYG71TlR1D28tUJy3qm2CbaLsfUuhF321JQ==
X-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=jHXdmBoI; arc=none smtp.remote-ip=100.103.45.18
X-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 11AB9606A31E; Tue, 24 Nov 2026 08:26:40 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DB271F000CA; Tue, 24 Nov 2026 08:26:40 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795508800; bh=NIXNWsD1GnWzukxgS94b8Vtpt/UkvIRehEZsYKJ0bvU=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=jHXdmBoImH/yMdINR1oUHELG1cJAB/1ooV1BS/9WCvhE4UnXHXEh0zy1Af2meyXq7 2l+/KCeFO3QGiEiLJXBJUov5UOvZOgmaPKoSoxHYo9jV8029eB8AxEp/AvMW35d4Hp bMcOQjO96knFIN2Zy9pOrCYR6PSZQMitHW3R9kVUqe4GgFN5Fu1bJ2luzHS96vgwEX xQL1cy55b3TDgaBmH2jR5LgSjIe6yuQB8cO3qcxSjY3DlIXoZ0RtZyuXlbPh+LixTG 6HmWFVZ8oMRxSm4TkAuNMqsQ/Y4KIcBENh1TX/y1EdFfT+noW+S1ZYHbDU/IUSjzKJ NTvlyI2cgm+ZQ==
X-Cc: david@ixit.cz, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, oe-linux-nfc@lists.linux.dev, netdev@vger.kernel.org, stable@vger.kernel.org
X-In-Reply-To: <20261120075908.4064155-1-bsdhenrymartin@gmail.com>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list