Article View: linux.kernel.netdev
Article #24179[PATCH net v4 0/2] nfc: st21nfca: fix SE APDU request race condition
From: Joas Antonio dos Santos via B4 R...
Date: Sun, 29 Nov 2026 16:25
Date: Sun, 29 Nov 2026 16:25
70 lines
13445 bytes
13445 bytes
The BWI timeout work and the EVT_TRANSMIT_DATA handler can both
complete the same SE APDU request. The callback frees its context, so
the second completion is a use-after-free followed by a double free.
1/2: Add a spinlock around bwi_active, cb and cb_context in the
paths that use them.
2/2: Use the lock to complete a request only once and to reject
overlapping requests.
The series is build-tested only (W=1, arm64); I do not have the
hardware.
Not addressed here, all older than this series and pointed out by the
Sashiko reviews of v2 and v3:
- st21nfca_se_deinit() can leave bwi_timer armed when info is freed
(it runs before nfc_hci_unregister_device() and only deletes the
timer when bwi_active is set), and it drops a pending request
without completing it. The remove ordering needs its own patch.
- EVT_TRANSMIT_DATA carries no request id, so a response that arrives
after its request timed out can still be taken for the answer to the
next request.
- When nfc_hci_send_event() fails in st21nfca_hci_se_io() the request
stays pending until the BWI timeout completes it with -ETIME.
- drivers/nfc/st-nci/se.c has the same double completion. I will send
a separate patch for it once the approach here is agreed on.
---
Changes in v4:
- 1/2: st21nfca_se_deinit() takes se_lock around its read and clear of
bwi_active (Simon Horman). The teardown ordering itself is still left
for a follow-up.
- Link to v3: https://lore.kernel.org/r/20261112-st21nfca-v2-v3-0-c81702269e01@gmail.com
Changes in v3:
- 2/2: free cb_context when a request is rejected with -EBUSY; it was
leaked (Sashiko).
- 2/2: still send EVT_SE_END_OF_APDU_TRANSFER for a response that
arrives after the timeout, as before the series; only the callback is
skipped (Sashiko).
- 1/2: comment on what se_lock protects (checkpatch), commit message
no longer claims every access is serialized.
- Rebased on v7.4-rc3+, target tree added to the subject.
- Link to v2: https://lore.kernel.org/r/20261110-st21nfca-v2-v2-0-cf9102b314cb@gmail.com
Changes in v2:
- Use a spinlock instead of plain bwi_active flag checks (Simon Horman).
- Split into two patches: locking, then the completion fix.
- Set bwi_active before mod_timer().
- Copy cb/cb_context under the lock, call it after unlocking.
- Reject overlapping se_io requests with -EBUSY.
- Drop the Assisted-by trailer.
- Link to v1: https://lore.kernel.org/r/179332800288.52644.8728400883396719965@gmail.com
---
Joas Antonio dos Santos (2):
nfc: st21nfca: add spinlock to serialize SE APDU request state
nfc: st21nfca: prevent double completion of SE APDU request
drivers/nfc/st21nfca/se.c | 48 ++++++++++++++++++++++++++++++++++++-----
drivers/nfc/st21nfca/st21nfca.h | 2 ++
2 files changed, 45 insertions(+), 5 deletions(-)
---
base-commit: 9d66f26fefacebfeed15de31c1123451a17ff119
change-id: 20261108-st21nfca-v2-f4c5f861e416
Best regards,
--
Joas Antonio dos Santos <joasantonio108@gmail.com>
Technical Details
Message-ID:
<20261129-st21nfca-v2-v4-0-7d18b104ad46@gmail.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373568-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373568-linux-kernel-netdev=dewy.ru From: devnull+joasantonio108.gmail.com@kernel.org (Joas Antonio dos Santos via B4 Relay) Newsgroups: linux.kernel.netdev Subject: [PATCH net v4 0/2] nfc: st21nfca: fix SE APDU request race condition Date: Sun, 29 Nov 2026 16:25:35 +0000 Organization: Usenet Network Message-ID: <20261129-st21nfca-v2-v4-0-7d18b104ad46@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="1209664"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:PLhqNwC7i3eFjBmQR+aMOp5eBuU= sha256:USSP9A+gAZQ1CFZbvbZOZkD5BtAdq+cGNKNBg8IqmZE= sha1:dITWSnqNjLErK1F0SZf4CojALgI= sha256:DFJ3vqEaNHOkNNzEw5eZtfO79iIIQJqy+N+JfL3L01s= 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 DDEFC125F98; Sun, 29 Nov 2026 19:26:08 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.251 X-Spam-Status: No, score=-3.251 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.001, 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 Dhi_hFipAoPw; Sun, 29 Nov 2026 19:26:05 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-373568-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 31265125F9A; Sun, 29 Nov 2026 19:25:56 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 6DCBC600F03; Sun, 29 Nov 2026 16:25:55 +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=1795969554; b=LA7bGYMV/liywMab1O29wWTJs+bYr03n0jylBs2nX4S3QcEJsi2kA7nygvaWHDHQguwC 4Ut3mEL1eAx1V+7oztvL0JjyG6THl//aTt6XvLeCGUnWbPPImLWW8how6o+DIQY0KH7LD 64Bh0W6nKnpFbdmqjGrJxvDLEsb/dpsXZdd/ajnICgt26Zg+E86b4NF23oBSjglYPC7hX jSwoiAmTdLNbXXeVhOi1F0IqITJ4JTQIkAHQ/AVO/ITDyfPwoBe9P33J9ew++WqVymmAV OXVeFe5INY6wM/W58r0+O8KJX52CNADkDyALobo0bbLsu/ilEgxcgMM8UhkHAREB8tw== X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795969554; h=X-Original-To:Received:Received:DKIM-Signature:Received:From:Subject: Date:Message-Id:X-Mailing-List:List-Id:List-Post:List-Help: List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Type:Content-Transfer-Encoding:X-B4-Tracking:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To; bh=BsSqFHZDjr//Xtzkgz3/EZbuJNrKugyQ1cVjtR7tl6E=; b=JvYbaaWtgJ5djs0iVXnJ48/9V3kxUz00mKHNfDnGB383I9uwTplOuPR+Q1BhlbhngYgL RrBy2n+tg+gaGMEqngsJKSoMByAegxNgYx5hjSbB8DvZQGrayTKwStXbtRz96m4v/oWka JuciGvUivi0bFNTBAtFpOoHwqGXh/d5nT8cfUAgaYHMJcEHqkzenH0mtMovIWUUIIEp2q FVinwx/b8q6IsUUGetdBv3+bLeZk5xiArP8jJc21PxAZXAhYUvP4B7Wi3c/YfdhtSGLFr oalqA5jIXHP+xTeUz23QlSSerA1z994ILtcIhWMtGW/RPkIwUOtcDn1AXOPRjbJ7T0Q== 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=LpjWATIr; 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 9522D606A337; Sun, 29 Nov 2026 16:25:54 +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=LpjWATIr 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=1795969543; b=hQ7UDGL04oxXTY5+zg2PHHszQMhF64RvX+Fd2ybAy3MExBcJBRiqEp9bXqEONEC1YdIi rw7moz8U+JjFgXQD3sAtEwGp+GHd0VFe0AWDWheLkyZzTYocbbFNIR9yhMFiwZl2R/f0a zxrTfEIpdiGl3/XklAib0AlcwjZkLtgg7lMyjEe8YA2qNnjZu8IiFz3frR5BDKzwf58bE FMgmfh9GcR6hTMbgDQrIcip20Zf5dBbLEyxtZjxgS1Ze3TozepA21RPN9M+hErGLnv+db 7KV2FZali0j0m5rZXtfPLBh/0pxnWLFTBlCBM73xjQ7KRgW6fiq6esRNTynoURyPdwQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795969543; h=Received:DKIM-Signature:Received:From:Subject:Date:Message-Id: MIME-Version:Content-Type:Content-Transfer-Encoding:X-B4-Tracking:To: Cc:X-Mailer:X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To; bh=BsSqFHZDjr//Xtzkgz3/EZbuJNrKugyQ1cVjtR7tl6E=; b=e3Bof4XFOCx1qoF7XQgIoN94h6Qkc3y+pYBdMB4GfrGOMOBoBOQZ7vIJ/SQpayTEom34 HhJD5wV6qCu4C2knnl3E1rRRqPTCAn2/GlimMoLqR/bRp9fdwWdgR3loqlX9dM4/qa4QK bP3YURgrOQOXseAawu8bJ2OrR1isoc/XdcVvAC0fxERPiFFXDyPOTiJma2xr3uBNbmy46 woEXqJDnA+dd6hBoh1IY5naNB6SrY8p14w9vnE/pD5LNCyLHC5084x5xwuIyITlLK2iu/ avRxIXRvg58mIXEfO3bt2WfooNanfyBEg+Z4wYpmFbgj6PFT8c3rtE8msSaoPUvrH3Q== 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=LpjWATIr; 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 AEB85606A323; Sun, 29 Nov 2026 16:25:43 +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=1795969543; b=Qj1ccDicZJUqBnFRAqkr86ROZlmKseKdx6f1eVRFrbjK3Ldk/beiMslcCHHW1UhaPS+n ODWc3jyUQqE7Y7KlhdBsGbz+ysBWRkDGeXTEFhBbK7bJchQYsW7sruBzEA8ORn+aK4DOh aQhJQxnJZgnQ6I4Wimj5C3l5D8RCCollqmUjiCgDEvQ2bH39B9JiEFNiygMJJc0zUjJ2T PEWHaOKfRNNHpiBgrKl4Cxk6THHQavZi5SxcGIhmKwk/PInUVMddjU5k9k0f+TsMHdsir nv6P3OUnCUiUZRQoUomA98LQ+R4Mnul6a5aZxdYeuHXT98YtYz8n3unwiIKmMXxHqIw== X-ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1795969543; h=DKIM-Signature:Received:From:Subject:Date:Message-Id:MIME-Version: Content-Type:Content-Transfer-Encoding:X-B4-Tracking:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To; bh=BsSqFHZDjr//Xtzkgz3/EZbuJNrKugyQ1cVjtR7tl6E=; b=CkmPIY6t6ao58yyh6uijdUuCl/or/f0Mh/RWNsU68JnKipErU9E1U10LAWOkNpm0RBcI Pz6a3Vk3+lF4CZjWbKIaV2pECy3ecepZ8cWaphMwqhnRXM4XEV7dJ+Fg4qMNh3wXmwJJa n1hQTd587tYtCwu7GGODlBe61kua5qwZEh6SUTg6bX/xzqgNrdHg25vA4jqNGhf3sd1sX B5gVo2AJRw610h57OMnrf2FYDiyYXpD2HBFU+WSEQW4Lk/NGRf414TOLKatwFe97FvkeF eZo5YufjiHY7p7SmHJXl0/ucGyTu8Mhsc0qhrsPPehAqE01+xyQSF3Ugd9Eg93CktuQ== 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 69D7D1F00923; Sun, 29 Nov 2026 16:25:36 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795969542; bh=BsSqFHZDjr//Xtzkgz3/EZbuJNrKugyQ1cVjtR7tl6E=; h=From:Subject:Date:To:Cc:Reply-To; b=LpjWATIrLZaqpaIR5SDtRach+5jwqMhifeecpjHOFP4YGPIkQ+dwc0qCCfkbblzEJ 9GMETCtimwC1Oh2tkxADudW2I4acyrZCXSCFVHMggmHZxQCPnPhGmRe9bQN6s3vEZ9 yGkCvI1ScXZAzdiNayW8Vo3gWGrQXA+2kKdoiPN/+JG92MksPhQd1mhx8aKuUB+QXK CFlXjTmHb3ERxGa8kqyBWqWMFGv/3pSaLCq9aYjEPurhBUEcNX01fF0Ljx0eZR2VX7 LWgoMX3fO4Qk9ldVUWcPH3ktOK3VOfCdLmWVGjItMa3oBjS76INS1cvBUgtQdIQnXv NA4mkaYgfnbPg== X-Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id BEA4F4E516; Sun, 29 Nov 2026 16:25:35 +0000 (UTC) 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-B4-Tracking: v=1; b=H4sIAP9RDGsC/22NQQrCMBBFryKzNpKZtjG68h7iIiSTNmBbSUpQS u9uyKqCMJv/P+/NColj4ATXwwqRc0hhnkpojwewg5l6FsGVDCRJIUot0kI4eWtEJuFb23mtkFt UUIhXZB/e1XaHiRd4lHIIaZnjp37IVKe/snJSkEP2znfGdfrWjyY8T3Yeqyc3Oxbpl20KazWeJ ZG6sMQ9u23bF0XWoUznAAAA X-Cc: oe-linux-nfc@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, horms@kernel.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1795969535; l=3074; i=joasantonio108@gmail.com; s=20261031; h=from:subject:message-id; bh=UHQEKDG+zDXlSglJZcRIuqsZukpW1gTKpNR53sSUBxk=; b=3LJSQlTVTyu7U4xVc462Xe8G2qGSexXZCgvEWvs9kOWWnyTeSRsOHjefvzdJ4gw/69CqPipx4 WQxW43rEH2iDVyIdYzkTjtfa6WSZc5e0hcoYa6z0bYz8waa0izH0L1Y X-Developer-Key: i=joasantonio108@gmail.com; a=ed25519; pk=ZxAznJT/FcPPdzLrDDFJQm4LLjjHVGBBqDSG3TXS23w= X-Endpoint-Received: by B4 Relay for joasantonio108@gmail.com/20261031 with auth_id=1371 X-Original-From: Joas Antonio dos Santos <joasantonio108@gmail.com> X-Reply-To: joasantonio108@gmail.com