From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 427FF3C09E1; Tue, 16 Jun 2026 18:04:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781633090; cv=none; b=ODD6Ddg6+oXojAVqaOvlCtLSZYoGPirRGeVx0NWDy+LvNIZ7DfkZBz2Pyg0NOiqcQlrxo5UdmeK8F/BxP4Ps+FfTZL+Ig06kGRJoN3orCWcldcSH/2nkY6H6ASFwnIg8ksQPkkg0zNbLcb9ABAJvRd9jyilVIDbZtkGMOGgA2Ac= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781633090; c=relaxed/simple; bh=irfSDn0OSezX9NNOuzhgMiTooyd+fsDn4MxvLBYCoz0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bhmKFOV9uwomwK9evAOAiCG9wuD1cvzDGd8OW03pGwWO5PNKoE3FuBjoXt+LsF1LH0Lhv5LquzoJjeEv6pg/Dnrgg6Tz/wB+hi5/fbG6C9kVDABtYgLNIwMCo/rSmxUivF14Av0Bmzs/W6xJmdHgfUIUIdFj4q4tfmm3Mr4+ERc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=DM9QhpzU; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="DM9QhpzU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09AE51F000E9; Tue, 16 Jun 2026 18:04:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781633088; bh=GEPcb2Atzt/vpoHuLEHY7QIJJJUVOgmZSFRrsy8YfjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DM9QhpzUn91xK5lZ5MY3265jsQ1yBanCyjvEtT5Lugy4Q2w/sS7ZrUh8t5RZtZ6nQ 63Hj6w3N6BoF2cLvZctVcoG38Gwx59cygBiT5Y2NgniS+UWKcl9nqYKvf3//vABlne XSWANBVu8cKUMPMnw6LPiI1eN54bXZbIxJByCpvo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Lee Jones , Simon Horman , David Heidelberg , Sasha Levin Subject: [PATCH 5.15 009/411] nfc: llcp: Fix use-after-free race in nfc_llcp_recv_cc() Date: Tue, 16 Jun 2026 20:24:07 +0530 Message-ID: <20260616145100.851905886@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616145100.376842714@linuxfoundation.org> References: <20260616145100.376842714@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lee Jones [ Upstream commit b493ea2765cc17cb8aa7e7544a4b6dcb05b6ed77 ] A race condition exists in the NFC LLCP connection state machine where the connection acceptance packet (CC) can be processed concurrently with socket release. This can lead to a use-after-free of the socket object. When nfc_llcp_recv_cc() moves the socket from the connecting_sockets list to the sockets list, it does so without holding the socket lock. If llcp_sock_release() is executing concurrently, it might have already unlinked the socket and dropped its references, which can result in nfc_llcp_recv_cc() linking a freed socket into the live list. Fix this by holding lock_sock() during the state transition and list movement in nfc_llcp_recv_cc(). After acquiring the lock, check if the socket is still hashed to ensure it hasn't already been unlinked and marked for destruction by the release path. This aligns the locking pattern with recv_hdlc() and recv_disc(). Fixes: a69f32af86e3 ("NFC: Socket linked list") Signed-off-by: Lee Jones Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260429134115.3558604-2-lee@kernel.org Signed-off-by: David Heidelberg Signed-off-by: Sasha Levin --- net/nfc/llcp_core.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c index e04634f22b49f4..c7de44637e0187 100644 --- a/net/nfc/llcp_core.c +++ b/net/nfc/llcp_core.c @@ -1225,6 +1225,15 @@ static void nfc_llcp_recv_cc(struct nfc_llcp_local *local, sk = &llcp_sock->sk; + lock_sock(sk); + + /* Check if socket was destroyed whilst waiting for the lock */ + if (!sk_hashed(sk)) { + release_sock(sk); + nfc_llcp_sock_put(llcp_sock); + return; + } + /* Unlink from connecting and link to the client array */ nfc_llcp_sock_unlink(&local->connecting_sockets, sk); nfc_llcp_sock_link(&local->sockets, sk); @@ -1236,6 +1245,8 @@ static void nfc_llcp_recv_cc(struct nfc_llcp_local *local, sk->sk_state = LLCP_CONNECTED; sk->sk_state_change(sk); + release_sock(sk); + nfc_llcp_sock_put(llcp_sock); } -- 2.53.0