]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
nfc: llcp: add missing return after LLCP_CLOSED checks
authorJunxi Qian <qjx1298677004@gmail.com>
Wed, 8 Apr 2026 08:10:06 +0000 (16:10 +0800)
committerJakub Kicinski <kuba@kernel.org>
Sun, 12 Apr 2026 18:12:44 +0000 (11:12 -0700)
In nfc_llcp_recv_hdlc() and nfc_llcp_recv_disc(), when the socket
state is LLCP_CLOSED, the code correctly calls release_sock() and
nfc_llcp_sock_put() but fails to return. Execution falls through to
the remainder of the function, which calls release_sock() and
nfc_llcp_sock_put() again. This results in a double release_sock()
and a refcount underflow via double nfc_llcp_sock_put(), leading to
a use-after-free.

Add the missing return statements after the LLCP_CLOSED branches
in both functions to prevent the fall-through.

Fixes: d646960f7986 ("NFC: Initial LLCP support")
Signed-off-by: Junxi Qian <qjx1298677004@gmail.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20260408081006.3723-1-qjx1298677004@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/nfc/llcp_core.c

index 366d7566308c9f2c5a4aa716a25833b5d66df061..db5bc6a878ddb064a71418a3745cb906dcf7a624 100644 (file)
@@ -1091,6 +1091,7 @@ static void nfc_llcp_recv_hdlc(struct nfc_llcp_local *local,
        if (sk->sk_state == LLCP_CLOSED) {
                release_sock(sk);
                nfc_llcp_sock_put(llcp_sock);
+               return;
        }
 
        /* Pass the payload upstream */
@@ -1182,6 +1183,7 @@ static void nfc_llcp_recv_disc(struct nfc_llcp_local *local,
        if (sk->sk_state == LLCP_CLOSED) {
                release_sock(sk);
                nfc_llcp_sock_put(llcp_sock);
+               return;
        }
 
        if (sk->sk_state == LLCP_CONNECTED) {