From: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
To: horms@kernel.org, david@ixit.cz, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com
Cc: oe-linux-nfc@lists.linux.dev, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
syzbot+ci3c472c63e196fe9e@syzkaller.appspotmail.com,
sashiko-bot@kernel.org, Aldo Ariel Panzardo <qwe.aldo@gmail.com>
Subject: Re: [PATCH net v2] nfc: llcp: prevent resource leak on repeated connect after DM
Date: Thu, 1 Oct 2026 10:28:53 -0300 [thread overview]
Message-ID: <20261001132853.1468565-1-qwe.aldo@gmail.com> (raw)
In-Reply-To: <179058922656.3145.17540746696102333949@kernel.org>
Thanks for the detailed review. v3 addresses the device reference
issues; the remaining points are either pre-existing or need a
follow-up. Responding to each finding below.
> [Critical] Can this release resources that a blocking connect() on the
> same socket still owns? (Thread A in sock_wait_state, Thread B wins
> lock_sock and runs cleanup, Thread A unwinds with stale local/dev)
This is a real concern but pre-existing: the socket lock is dropped
inside sock_wait_state() and a second connect() on the same fd from
another thread can race regardless of this patch. The cleanup does
not make the window wider -- without it, Thread B's connect() would
overwrite the fields without releasing anything (the original leak).
A proper fix for concurrent connect() on the same socket would need
serialization beyond the socket lock, which is a separate change.
> [Critical] Does a CLOSED socket with non-NULL llcp_sock->dev always
> own a reference? bind() keeps dev without a reference;
> socket_release() drops the connected ref without clearing dev.
This is what syzbot confirmed and v3 fixes. v3 clears llcp_sock->dev
in nfc_llcp_socket_release() after the connected put, and for
bound/listening sockets that never owned a device reference. It also
clears dev in nfc_llcp_recv_dm() for bound/listening sockets before
setting LLCP_CLOSED. After v3, the cleanup's if (llcp_sock->dev)
guard only fires when the socket genuinely owns the reference (the
rejected async connect case).
The syzbot reproducer for the v2 double-put passes cleanly with v3
applied (tested with KASAN, 0 reports).
> [High] Is the socket always off local->sockets at this point?
> Cleanup sets local = NULL without unlinking; socket stays hashed.
Valid concern. The cleanup should unlink the socket from whichever
list it is on before clearing ->local. This is not addressed in v3
and needs a follow-up patch. I will send one.
> [High] Can the same leak happen through bind()?
Yes. bind() also accepts CLOSED sockets and overwrites the fields.
The cleanup helper should be called from bind() as well. Not
addressed in v3; will include in the follow-up.
> [High, pre-existing] Stale sk_err = ENXIO from recv_dm not cleared
> on retry; if recv_cc() races in, connect() unwinds and leaves dev
> NULL, then destruct dereferences NULL.
Pre-existing and not introduced by this patch. Clearing sk_err in
the LLCP_CLOSED cleanup is the right thing to do. Will include in
the follow-up.
Summary of what is addressed and what remains:
v3 fixes:
- Device reference underflow (syzbot confirmed, KASAN verified)
Follow-up needed:
- Unlink socket from local->sockets/connecting_sockets in cleanup
- Call cleanup from bind() as well
- Clear stale sk_err on reconnect
I will send the follow-up as a separate patch once v3 is reviewed.
thanks,
Aldo
prev parent reply other threads:[~2026-10-01 13:29 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 18:48 Aldo Ariel Panzardo
2026-09-27 22:32 ` [syzbot ci] " syzbot ci
2026-09-28 3:57 ` [PATCH net v3] " Aldo Ariel Panzardo
2026-10-01 11:59 ` Simon Horman
2026-09-28 9:53 ` [PATCH net v2] " netdev-bot+sashiko
2026-10-01 13:28 ` Aldo Ariel Panzardo [this message]
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=20261001132853.1468565-1-qwe.aldo@gmail.com \
--to=qwe.aldo@gmail.com \
--cc=davem@davemloft.net \
--cc=david@ixit.cz \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oe-linux-nfc@lists.linux.dev \
--cc=pabeni@redhat.com \
--cc=sashiko-bot@kernel.org \
--cc=stable@vger.kernel.org \
--cc=syzbot+ci3c472c63e196fe9e@syzkaller.appspotmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®