From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 AFB5D26F288; Thu, 12 Mar 2026 20:26:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773347202; cv=none; b=fYgVVOYk/y3kLWo+RSfu6t5oM4czL7YA5GprOJAgiS1DWx8f3bNuT58acUhCPuPxYp1QXknjYxIkscE9ODCqNiykSw+u41lOHxCnbQt1UkzqC6Ql3MIKf9hP2nlWJriZ/CQhyX9nsd+7KAma1eRB+ugOR+gffwT+XRfxF9LOf24= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773347202; c=relaxed/simple; bh=8EymlOYxP8uar9+21ZvA8YOXfAsP9qDEag5d16ik+tE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EEBA53kb+dXlx5U0/VSN+gFqE91Vubv9tuqjVCfptFGyv3EPAa7uYSdkVXn2Dl5TnmWL9/lZcHMEHRYfbuw0yLuFBz8MGk1N9EXnTheKJNWE9/tRHJawD80tfkfY9Hw06DDEr/Tb+ViblU479nN/yvNcLvEGSpvHxBYWwh97vzs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=yXeaPhh6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="yXeaPhh6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01B56C4CEF7; Thu, 12 Mar 2026 20:26:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1773347202; bh=8EymlOYxP8uar9+21ZvA8YOXfAsP9qDEag5d16ik+tE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yXeaPhh6lxEE//mh1qKChhAdlJYbP2VJAJPzLwFl2a8Nm/cY2ElkzGc9bIW853UAa GnXtyamKPpthSX3f5dlpa+TMeLPx8grVcxKQK2GiC8DYQcNZSD2NN4uuu1JKAsDjB0 rUnqOP72iXplZuDSl+WCFPf8EYf1fNatIdIZrPu4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Joe Damato , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.12 232/265] nfc: rawsock: cancel tx_work before socket teardown Date: Thu, 12 Mar 2026 21:10:19 +0100 Message-ID: <20260312201026.710400351@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260312201018.128816016@linuxfoundation.org> References: <20260312201018.128816016@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jakub Kicinski [ Upstream commit d793458c45df2aed498d7f74145eab7ee22d25aa ] In rawsock_release(), cancel any pending tx_work and purge the write queue before orphaning the socket. rawsock_tx_work runs on the system workqueue and calls nfc_data_exchange which dereferences the NCI device. Without synchronization, tx_work can race with socket and device teardown when a process is killed (e.g. by SIGKILL), leading to use-after-free or leaked references. Set SEND_SHUTDOWN first so that if tx_work is already running it will see the flag and skip transmitting, then use cancel_work_sync to wait for any in-progress execution to finish, and finally purge any remaining queued skbs. Fixes: 23b7869c0fd0 ("NFC: add the NFC socket raw protocol") Reviewed-by: Joe Damato Link: https://patch.msgid.link/20260303162346.2071888-6-kuba@kernel.org Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/nfc/rawsock.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/net/nfc/rawsock.c b/net/nfc/rawsock.c index 5125392bb68eb..028b4daafaf83 100644 --- a/net/nfc/rawsock.c +++ b/net/nfc/rawsock.c @@ -67,6 +67,17 @@ static int rawsock_release(struct socket *sock) if (sock->type == SOCK_RAW) nfc_sock_unlink(&raw_sk_list, sk); + if (sk->sk_state == TCP_ESTABLISHED) { + /* Prevent rawsock_tx_work from starting new transmits and + * wait for any in-progress work to finish. This must happen + * before the socket is orphaned to avoid a race where + * rawsock_tx_work runs after the NCI device has been freed. + */ + sk->sk_shutdown |= SEND_SHUTDOWN; + cancel_work_sync(&nfc_rawsock(sk)->tx_work); + rawsock_write_queue_purge(sk); + } + sock_orphan(sk); sock_put(sk); -- 2.51.0