Article View: linux.kernel.netdev
Article #26766[PATCH net v2 2/3] nfc: nfcsim: stop link and works before unregistering digital device
From: Bin Luo via B4 Relay
Date: Fri, 04 Dec 2026 06:06
Date: Fri, 04 Dec 2026 06:06
73 lines
13286 bytes
13286 bytes
From: "Bin Luo (University of Electronic Science and Technology of China)" <luob87709@gmail.com>
Commit 5e7b30d24a5b ("nfc: nfcsim: fix use after free during module
unload") partially addressed a use-after-free in
digital_send_cmd_complete() by returning early in nfcsim_recv_wq() when
!dev->up, but it did not close the race completely: nfcsim_device_free()
still calls nfc_digital_unregister_device() before setting
dev->up = false, shutting down link_in, and stopping recv_work.
While nfc_digital_unregister_device() drains and frees every pending
struct digital_cmd from ddev->cmd_queue, dev->up is still true and
nfcsim_recv_wq() can wake up on an incoming frame from the peer device
(or timeout) and invoke dev->cb() -> digital_send_cmd_complete() on the
freed struct digital_cmd:
BUG: KASAN: slab-use-after-free in digital_send_cmd_complete+0x76/0xa0
Write of size 8 at addr ffff888007d9bb20 by task kworker/3:4/66
Workqueue: events nfcsim_recv_wq [nfcsim]
Call Trace:
digital_send_cmd_complete+0x76/0xa0
nfcsim_recv_wq+0x30a/0x6c0 [nfcsim]
Freed by task 64:
kfree+0x308/0x530
nfc_digital_unregister_device+0x1e9/0x2e0
nfcsim_device_free+0x2d/0x1c0 [nfcsim]
Mark dev->up = false, shut down dev->link_in, and permanently stop
send_work and recv_work with disable_delayed_work_sync() and
disable_work_sync() before calling nfc_digital_unregister_device().
Triggered in QEMU KVM testing without kernel delay injection while
unloading nfcsim during active LLCP traffic, and verified fixed across
200 nfcsim load/unload cycles with KASAN, LOCKDEP, and DEBUG_OBJECTS
enabled.
Fixes: 5e7b30d24a5b ("nfc: nfcsim: fix use after free during module unload")
Fixes: 204bddcb508f ("NFC: nfcsim: Make use of the Digital layer")
Cc: stable@vger.kernel.org
Signed-off-by: Bin Luo (University of Electronic Science and Technology of China) <luob87709@gmail.com>
---
Changes in v2:
- Resend cleanly via b4 web relay (v1 patch was line-wrapped by Gmail)
and include all three NFC teardown fixes as a threaded series.
drivers/nfc/nfcsim.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/nfc/nfcsim.c b/drivers/nfc/nfcsim.c
index f8e5c4d..f3ddae6 100644
--- a/drivers/nfc/nfcsim.c
+++ b/drivers/nfc/nfcsim.c
@@ -411,14 +411,14 @@ static struct nfcsim *nfcsim_device_new(struct nfcsim_link *link_in,
static void nfcsim_device_free(struct nfcsim *dev)
{
- nfc_digital_unregister_device(dev->nfc_digital_dev);
-
dev->up = false;
nfcsim_link_shutdown(dev->link_in);
- cancel_delayed_work_sync(&dev->send_work);
- cancel_work_sync(&dev->recv_work);
+ disable_delayed_work_sync(&dev->send_work);
+ disable_work_sync(&dev->recv_work);
+
+ nfc_digital_unregister_device(dev->nfc_digital_dev);
nfc_digital_free_device(dev->nfc_digital_dev);
--
2.43.0
Technical Details
Message-ID:
<20261204060656.503-3-luob87709@gmail.com>Path:
mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ro.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377098-linux-kernel-netdev=dewy.ruReferences:
<20261204060656.503-1-luob87709@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-fra.pugleaf.net!feed-eu-txt.newsdeef.eu!feed-eu-ro.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377098-linux-kernel-netdev=dewy.ru From: devnull+luob87709.gmail.com@kernel.org (Bin Luo via B4 Relay) Newsgroups: linux.kernel.netdev Subject: [PATCH net v2 2/3] nfc: nfcsim: stop link and works before unregistering digital device Date: Fri, 04 Dec 2026 14:06:58 +0800 Organization: Usenet Network Message-ID: <20261204060656.503-3-luob87709@gmail.com> References: <20261204060656.503-1-luob87709@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="2689035"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:LE+4+B7WCd+BBFlm9mXUmQp+2fA= sha256:9tiHrykUrsPEoEZwQrXhlu1amHg1xo+9quljSA6AwJg= sha1:FfzY0IszLSfV0TYfgEU2ghwiwk0= sha256:6nzmDABzFDF+qgvfaGKbNWcu99zQMyvesjoL5vpCiDU= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id C4207117B04; Fri, 4 Dec 2026 09:08:15 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.49 X-Spam-Status: No, score=-3.49 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_REPLYTO_END_DIGIT=0.25, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id G0gZYvTtjlx4; Fri, 4 Dec 2026 09:08:12 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-377098-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 3891D117AF9; Fri, 4 Dec 2026 09:08:03 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 3BA4729EA3; Fri, 4 Dec 2026 06:07:56 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796364427; b=5WGV6NCy6uEd+Xp+kl7NBTAanYhmcSyubq7/j7Zk52W8+0GNAY7Q8bAbanipY14RyPVP AmFhjyaSLG7i2/sMuqz1Wi8ofReOas8e/W8SFWFWiksYBvGs/WVzF8jVbrjtybbmvSKk5 GY4KcWD75MW6pHQ2oWCgl+EIE5qRzAlbrXKUdtuC6+L6IXoMK8wtNBVN8Co5+KmN3pRVi HyhzZAHNy2hd9kvC7Ij7yPfWuc0rqzQYGeB72tfPHc6NedFBXfvUlE79lV/DnJCCYBrGS o9ueRVFTbFCpHmzsqmVHJkj2uu6XH4yyr2CvRTukT9MyHRG3w0MsbXbz3kclQDNGTVw== X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796364427; h=X-Original-To:Received:Received:DKIM-Signature:Received:From:To:Cc: Subject:Date:Message-ID:In-Reply-To:References:Content-Type: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=peZPgFClekv0hStyFFOKQXstNw64/ZdHvw4jNHdo+KY=; b=FzeAITOKq5eiSx0ERBlVNrarZL2oPcxjq71zAQHE3VlvzoUGGzvPS2bBnJcoh3FyPk1s t5JQKoqIemF+pC7UYEZilRM7mk45opUu5TzAQeL9jlcKhy3NYmWoeCX3+dREezK85RbsP WA3trQZJ63OFF2ZhWLzTxT7D4Sdq6vWHlkIfG3/M5M2FsgNMf0KFMJ7Q1DeU9BEsrUC5z xsYt5nQWGTJ8ixo4MlGOt246KIJk0oSVGry/olBEtXKgciwa44PXaNOd2Ors4L1Or65nL t57Wi/z52/FVolMQxLJxB1id2GebyX8kE6uSXfAy3b5ONwwTF+Eax/TjomeaFHYa/7A== X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HcvwAwUN; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ADB54606C544; Fri, 4 Dec 2026 06:07:07 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HcvwAwUN X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796364420; b=TY2UW3gWrBjC0XOgjVsWyKw1wqFboc9lP08KNLivHmFZATrc9vhz5cpZMQuqYNcatfYV 3IUNQ4p4FSrNbtBfFg+J/51AnttFC0zJT1H7p58rUctBeys9qkhS5yIXLDM+hrWYKXXgj CCzY1TJwBZCV8P6/4XJOwgSmekpmgPQ4fBjS8lChFnSkDN5ZwddaPXS61PtIO5NlyzAg1 XoCThFmIvFe+8Qk04lVzwmK5VmHvPAlSJoT+b+GUEahqXSrdW2RgU+6mnJvdVfIfXuRuT jdYk1VIlIvt9152Vs3ZAiBV6kRdlMtSC5EQqHZzhBgxoo8cbTx6t54rMfRrZ044ZSkg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796364420; h=Received:DKIM-Signature:Received:From:To:Cc:Subject:Date:Message-ID: In-Reply-To:References:Content-Type:MIME-Version:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=peZPgFClekv0hStyFFOKQXstNw64/ZdHvw4jNHdo+KY=; b=NGGsYqS1ckQoVjxdOruk3o2i73F9aNGq/mddEShNOcQNLg6je8VxCokGRJTK42fUUYKE hvyPHraWYH9Gv/TmFmxLa1cUgBZaWmdWeRHnPqk3nTysPvLykJrFquM3IbyC7tTASz/rL dP6gAqy5ERg3KKd4YhsZZpCnGF+GRx1ZKyr1xQaSOKYkHHOkFvWyL4OYenMowuuVuULat tx+FvbbeEKuVrMX8RVlorkrs6BNmzQRABg2OYT/wA3vkSuePHAb0+X4mPGSfn6N1dUpNu fO/kojl31Uslbysz/Zq5XFUasvDNlRyAUo4gwWyRjsEMEoQEG9wooX4jSta0HBUFbjA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HcvwAwUN; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDBF860A3838; Fri, 4 Dec 2026 06:07:00 +0000 (UTC) X-Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 X-ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796364420; b=ABIpdfyITRjjLzXuEwWkFbaEXE3M7WJVZXTENxgxSl6yf8t5j+wGJ0wvdQShYhJfsKdu /7EhIKNyMfkkHXrxuLtrmQlnPT3MNvbCv15tzMsqzV9Oulnl8wY+6+28MjWCuyqBBDkpS P/vqIxzcrkmargiUrBN7MPz1lvxy+m5o91QmR188tANM/l2eMG9XpwzP6lKTMCtt+5Zxd H63UElXHsC88R3E6rB0eg8tx0Y8tGuP+MjIrODZgdIIdVYkTgHwLAYf1HGQBxn8mliHAQ lMJ0OIaVk5nCNvgOlGicvXUcwIRtlpltNTy0RUBIcImEdMgTlTDKxyo5292uVThE8FQ== X-ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796364420; h=DKIM-Signature:Received:From:To:Cc:Subject:Date:Message-ID: In-Reply-To:References:Content-Type:MIME-Version:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=peZPgFClekv0hStyFFOKQXstNw64/ZdHvw4jNHdo+KY=; b=ttvdXClG9QWvcuXl3ze8cTzBkNm65i1ZVFuWdFfu81RFEY6mBlkoyahwLQ8nRonYnTuI 52I2XgAUIFNDK6125vPLyAMMzwXVTtvIDMHT8D4tJSpeJLeK0wGehDCi5fF+ZtJFcjsIf WnpS9Oj8TyJP859pScVCdjD7kFsEGWDX/B5itHBZnQtZjEv3clOfQt9Kn1LTPePtD9b8x v618KiHr8Zrkfb7E4MzaVKIbEmxi2LVXqanGQwLfWNs69RuIKdNYhUuJpDwZN7cc/ZDcu Sks8MFuLg6RkWCGcN8zqw3KpOq6MGV5+t3W7LDFZwSUY4n4jLY3kgqjx/2blZYblnGQ== X-ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 X-Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id C15971F000CE; Fri, 4 Dec 2026 06:06:59 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796364420; bh=peZPgFClekv0hStyFFOKQXstNw64/ZdHvw4jNHdo+KY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:Reply-To; b=HcvwAwUNCZH9evVAbWBfYqKznUIMqJe/8xe8SMMSgvg7WxdMjZyDmqpcnDBJvEplJ XLj6yK+f50FNMVO6VLml6XwV+qp8iflxUGD4jRyt5gl+hp+gK8/gYIiSiPmdfBRwVr MmUwCSkUG3nP9BsU6p0m2/qFVaLjRdkKwD0owKZDySzwe0b1davhH2361S3h1RK3cV +jDkNNrwVMdZd8x6sbbX/T4xynZcWc5ifHhrEjflsWKnQxV13ESn1BEAI5crQoA91E R2gBX3hCwUrSryA2ZBhyLGPqsj3TkXvKeA0Qw0jKWihrvxz1BqBgGoLe8yENSelzQB cSW9x2bwpIscA== X-Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 55DD64D94A; Fri, 4 Dec 2026 06:06:59 +0000 (UTC) X-Cc: Krzysztof Kozlowski <krzk@kernel.org>, oe-linux-nfc@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org X-In-Reply-To: <20261204060656.503-1-luob87709@gmail.com> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796364416; l=2790; i=luob87709@gmail.com; h=from:subject:message-id; bh=Nvh095yTS5jtH39nCutKNVXPtpUvKE5zwSj5pGTE3dA=; b=z1C6DBUxsKVqyFtBRKE/x6iei3OBLZ7/KS35sh7Q0zPovwlP9EZ1kCuLSM45Pil/Gint1OmZD oNhxtFldaeWARSVaPGwI/bnBY0CVKmSKMSarwYD4XtPAdGAHpVOw0W3 X-Developer-Key: i=luob87709@gmail.com; a=ed25519; pk=qac/JyfPpjPD91IsbcZY5AvHG2LdM5meIPeVzh4kuN0= X-Endpoint-Received: by B4 Relay for luob87709@gmail.com/default with auth_id=1739 X-Original-From: "Bin Luo (University of Electronic Science and Technology of China)" <luob87709@gmail.com> X-Reply-To: luob87709@gmail.com