All of lore.kernel.org
 help / color / mirror / Atom feed
From: syzbot <syzbot@syzkaller.appspotmail.com>
To: syzbot@lists.linux.dev
Cc: syzbot <syzbot+ci3c472c63e196fe9e@syzkaller.appspotmail.com>,
	qwe.aldo@gmail.com
Subject: Forwarded: [PATCH] nfc: llcp: clear stale device pointers on socket close
Date: Sun, 27 Sep 2026 18:46:49 -0700	[thread overview]
Message-ID: <6ab9c709.e548f532.1ca396.0042.GAE@google.com> (raw)
In-Reply-To: <20260928014639.2230819-1-qwe.aldo@gmail.com>

For archival purposes, forwarding an incoming command email to
syzbot@lists.linux.dev.

***

Subject: [PATCH] nfc: llcp: clear stale device pointers on socket close
Author: qwe.aldo@gmail.com

#syz test

nfc_llcp_socket_release() and nfc_llcp_recv_dm() can move a socket
to LLCP_CLOSED without clearing llcp_sock->dev.  A bound socket
never owned a device reference (bind puts its temporary ref), and
a connected socket reference is already released here.  A later
reconnect attempt would then put a device reference the socket does
not own.

Clear the pointer when a socket becomes closed so that the reconnect
cleanup only puts references it actually holds.

Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
---
 net/nfc/llcp_core.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c
index cac1b5487..f2530bebe 100644
--- a/net/nfc/llcp_core.c
+++ b/net/nfc/llcp_core.c
@@ -81,8 +81,14 @@ static void nfc_llcp_socket_release(struct nfc_llcp_local *local, bool device,
 
 		nfc_llcp_socket_purge(llcp_sock);
 
-		if (sk->sk_state == LLCP_CONNECTED)
+		if (sk->sk_state == LLCP_CONNECTED) {
 			nfc_put_device(llcp_sock->dev);
+			llcp_sock->dev = NULL;
+		} else if (sk->sk_state == LLCP_BOUND ||
+			   sk->sk_state == LLCP_LISTEN) {
+			/* bind() already dropped its temporary device reference. */
+			llcp_sock->dev = NULL;
+		}
 
 		if (sk->sk_state == LLCP_LISTEN) {
 			struct nfc_llcp_sock *lsk, *n;
@@ -1276,6 +1282,10 @@ static void nfc_llcp_recv_dm(struct nfc_llcp_local *local,
 
 	sk = &llcp_sock->sk;
 
+	/* Bound and listening sockets do not own a device reference. */
+	if (sk->sk_state == LLCP_BOUND || sk->sk_state == LLCP_LISTEN)
+		llcp_sock->dev = NULL;
+
 	sk->sk_err = ENXIO;
 	sk->sk_state = LLCP_CLOSED;
 	sk->sk_state_change(sk);
-- 
2.43.0


       reply	other threads:[~2026-09-28  1:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260928014639.2230819-1-qwe.aldo@gmail.com>
2026-09-28  1:46 ` syzbot [this message]
2026-09-28  3:36   ` [syzbot ci] Re: nfc: llcp: prevent resource leak on repeated connect after DM syzbot ci

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6ab9c709.e548f532.1ca396.0042.GAE@google.com \
    --to=syzbot@syzkaller.appspotmail.com \
    --cc=qwe.aldo@gmail.com \
    --cc=syzbot+ci3c472c63e196fe9e@syzkaller.appspotmail.com \
    --cc=syzbot@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.