Article View: linux.kernel.netdev
Article #13133[PATCH v2] nfc: pn533: bounds-check the ATR_RES response before parsing it
From: hyunjungg
Date: Mon, 09 Nov 2026 11:00
Date: Mon, 09 Nov 2026 11:00
82 lines
13660 bytes
13660 bytes
From: Hyunjung Ko <hj351016@gmail.com>
pn533_poll_dep_complete(), pn533_in_dep_link_up_complete() and
pn533_activate_target_nfcdep() cast resp->data to the fixed ATR_RES
header (struct pn533_cmd_jump_dep_response / pn533_cmd_activate_response)
and, on a successful response, read nfcid3t[] and compute the general-
bytes length as resp->len - sizeof(header). A short response leaves that
read past the end of the skb data, an out-of-bounds read; the copied
nfcid3t reaches userspace via nfc_targets_found() and netlink.
Only the success path needs the full fixed header: a no-peer/failure
reply is just the status byte, and the existing failure handling (turn
the radio off and re-arm polling, or print the error) must keep running
for it. So validate resp->len >= sizeof(*rsp) after the status check, on
the success path, in all three handlers, before nfcid3t and the general
bytes are read.
Found by code review; not reproduced.
Fixes: 361f3cb7f9cf ("NFC: DEP link hook implementation for pn533")
Fixes: 673088fb42d0 ("NFC: pn533: Send ATR_REQ directly for active device detection")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
Changes in v2 (thanks to the Sashiko AI review):
- move the length check to the SUCCESS path (after the status check), so
a no-peer/timeout reply (resp->len == 1) still takes the existing
"turn radio off, re-arm polling" / error path instead of returning
-EINVAL and stalling the poll loop
- also guard pn533_activate_target_nfcdep(), the third ATR_RES parser
- add Fixes: tags for the two commits that introduced the parsing
- drop the inaccurate claim that the other handlers already length-check
resp->len (only pn533_init_target_complete() does)
diff --git a/drivers/nfc/pn533/pn533.c b/drivers/nfc/pn533/pn533.c
index b0133e51dce9..9c65b52a8a14 100644
--- a/drivers/nfc/pn533/pn533.c
+++ b/drivers/nfc/pn533/pn533.c
@@ -1319,6 +1319,17 @@ static int pn533_poll_dep_complete(struct pn533 *dev, void *arg,
return 0;
}
+ /*
+ * A successful ATR_RES carries the full fixed header (nfcid3t[] and
+ * the rest); the general bytes start at offset sizeof(*rsp). Reject a
+ * short success reply before reading nfcid3t and computing the
+ * general-bytes length, to avoid an out-of-bounds read.
+ */
+ if (resp->len < sizeof(*rsp)) {
+ rc = -EINVAL;
+ goto error;
+ }
+
dev_dbg(dev->dev, "Creating new target");
nfc_target.supported_protocols = NFC_PROTO_NFC_DEP_MASK;
@@ -1799,6 +1810,11 @@ static int pn533_activate_target_nfcdep(struct pn533 *dev)
return -EIO;
}
+ if (resp->len < sizeof(*rsp)) {
+ dev_kfree_skb(resp);
+ return -EIO;
+ }
+
/* ATR_RES general bytes are located at offset 16 */
gt_len = resp->len - 16;
rc = nfc_set_remote_general_bytes(dev->nfc_dev, rsp->gt, gt_len);
@@ -1937,6 +1953,11 @@ static int pn533_in_dep_link_up_complete(struct pn533 *dev, void *arg,
goto error;
}
+ if (resp->len < sizeof(*rsp)) {
+ rc = -EINVAL;
+ goto error;
+ }
+
if (!dev->tgt_available_prots) {
struct nfc_target nfc_target;
--
2.43.0
Technical Details
Message-ID:
<20261109110016.1511307-1-hj351016@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359229-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359229-linux-kernel-netdev=dewy.ru
From: hj351016@gmail.com (hyunjungg)
Newsgroups: linux.kernel.netdev
Subject: [PATCH v2] nfc: pn533: bounds-check the ATR_RES response before parsing it
Date: Mon, 9 Nov 2026 20:00:16 +0900
Organization: Usenet Network
Message-ID: <20261109110016.1511307-1-hj351016@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="335056"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:rSQMRGnBLv+rNOCND+L+92vq+YU= sha256:2n5A2PzoutQW2d01ufSaLCEMxEsJWvcMTI1pHRBpPEI=
sha1:5fJWvmpNJR4U1YE8EQGg5F8WuTI= sha256:Cr0+wRxDYZy6sIm3reqdxFN6gPr7vhUgfphUgOKlM9s=
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 2C2AA1137A4; Mon, 9 Nov 2026 14:05:56 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
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=gmail.com
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 7WwXVg5b26FN;
Mon, 9 Nov 2026 14:05:53 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-359229-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id ADDCB113794; Mon, 9 Nov 2026 14:05:44 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id D6AEEE9848; Mon, 9 Nov 2026 11:00:54 +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=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1794222054;
b=KMYT9EBiuZza36wQJwYyFLHs1KO3d6sQYCXXzDEYMy5EkhxCIS5PI4MD5LWFNXGJY9jp
yGc2HgZHr4Vo9yhWxUiuQaR+WIhMkfjw67O6geMX180JstMLRCogWe5Q3rrRhHd2b3rIW
m/whXHOYteMCrTmKqytrHnTOxU3abdpmrSOmFlOKBL7dQ1558TmjF/IxhtRb5xukksHtY
lT16GSr/cw85NXt3ELoRxmgSzAUfcnrwab573jQj2lyoYGY212+b67tz9Zeyt/CbdNPEw
HhW1dRMMoTxC/R6z1AOsIe8/qoZ6P46POQVsvBWH5hRJNlAZr7fynVeFXIgJOBMGvAA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794222054;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:Date:Message-ID:
X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=4iXeY4iqUL9ww0pQAAvwhem0iOVjitiOYOwOdTHElEs=;
b=p+7lTGX5bRwvVNivl0lQwyTt1i1rgh1MdZUNxKAL6AiUqLstGo6/6BRsxx/YjVFjOza6
Mzuv/eXO+xOTB2hRIUMVXXxlknpr1L8sBpAwBg5Wpf39jfEZBRzoAx1eSwtNpz9Y/Kd0H
24F3oq9Eb6sFe1lK0r1OD2c4Pl0TVzD/UXgFYDtzc012JRfLpW7C/pGYigLHNZaHoDZqd
9cjlBMYad394Juun0MQzVy4tLhQYs7iabWfanKslR7cDomkXN3FXLURH5dOi7+ygd1kSe
pnTIYVwH0ByjLamMGWU/zziIOfyLtKHdmcURyYn0sJfMq/KoDfDScpP0of1nPNNtlfA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="dgb/Ob6Q";
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
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 651FB606A33D;
Mon, 9 Nov 2026 11:00:54 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dgb/Ob6Q
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.41
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794222053;
b=1mfEDGocj8r2D/3nQ75n7+2sWp3ROKg4vEB5veuTSy14Mw9dAmt6vpDsR7Gqg1IY9QIx
2O800BFJ1n57XrkL6PgBGqdM21P6uDKgE14D9+/FTgjuHguviviHDGKPrePy6f7JI898X
+GWElxmRGO/3gK2Prnxb5MWOA4IgS++PsUXxchil7V0FHuUjcuamKQZYWE/VEYxOe9U8N
zArKSWTzitYHMBOiG0vKXyNM/d9rDbCOg/UGkI33bzzmyCoPleNL0Uw+f+URPlmSAMpQb
7KuixdOSjdSc2ENYD9cqfJNg2ujCnEfdin4GWozKid9tnfCHNU7VNOs4P/CSmqPryRw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794222053;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version:
Content-Transfer-Encoding;
bh=4iXeY4iqUL9ww0pQAAvwhem0iOVjitiOYOwOdTHElEs=;
b=y0A3pF+nc+8nXV+kRWSlRVoWzb9kNEAm39/NQkqfx8N/Uts7c7OnAX6kwDYrNbSTTD6S
iOiXqxkQgMlTFa6MxYqvqqQzEMzXJMAlVJL3OhvrGrKAuFxLikdTGb203etekCuqiOCjF
Q8LUaPAtut894UUmIrjFUnsLGBjW7IVEIpGpkURhztN6tlPwQ7gSFTdoRTBea8kKQLCyu
uZhZ8WAv0AHqoRBXkSpwr2fwwDaDcR3vJzW03fw7aPnf/X/f8DZbGEzWC4HP4sNhzISF/
p9vGk2deeQb/U9s+PsA0RGR4i5lER90ighrtPK+GHcu1BeFIbCMbQOKrbODXWMcplzw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="dgb/Ob6Q";
arc=none smtp.remote-ip=74.125.82.41
X-Received: from mail-dl1-f41.google.com (mail-dl1-f41.google.com [74.125.82.41])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CBFD606A333
for <netdev@vger.kernel.org>; Mon, 9 Nov 2026 11:00:53 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3CBFD606A333
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dl1-f41.google.com with SMTP id a92af1059eb24-1931ff67a29so1897281c88.1
for <netdev@vger.kernel.org>; Mon, 09 Nov 2026 03:00:53 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1794222052; x=1794826852; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
bh=4iXeY4iqUL9ww0pQAAvwhem0iOVjitiOYOwOdTHElEs=;
b=dgb/Ob6QI01rMx87etoiMX2YGgi3uwE/Sja9pTJwEvfOdLa2+5qs2+VS6YOXYKcz0o
+MYkHXzbIujBKtLr+3+/93zEKoJg4unV/zBPOa8JTwqEAaP+yZL/T0E3hNKjKTG3BPPr
CmFFzSFLrx62/7MGwPsbC1zVXA2mBlEbRBsAjYQV80MumER68suOgFPiQ1It04NzVpu8
/Dto9EuhNnMIm+uR+juvruLO2NZMd/M0uttdxPkDAoQVVesrYjah6ILq3Vwu28JYsj80
gGYqrgt1eeZK54+oMZBd3gYfSnTnv96ZQcDaAt6PYwA3wywyYtkRX8q7zQ7SF7ZKBQmq
q9PQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1794222052; x=1794826852;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=4iXeY4iqUL9ww0pQAAvwhem0iOVjitiOYOwOdTHElEs=;
b=slaZzygBa+8OURhthKqCRPHu7QcB/g4pea1+wLcsIin1vNWGRe8GxAvcdXeNWQQlLs
jzh6u1VH00D7seuU/gPs+2mkVMf4F3RJqz8T6sPdNkv0e+jW/Uveuw06bzIJcUt05tMg
FXTRNNmbwywyYwSn7T9jIYZTwtLUih7cycHLTfYs1Fv6UavqYsdVBOTP19R5tefjAuAV
iXtoMpkfXxeJKkfLehf33u7P3kulMMIGExbBG2Zq68RoFegfacs/APONNxMoCVR4ve2q
7fMdHOwScSn3narKf5uFlx5ziehay0ZltE+0s+m5XG8HvSypPBPHl8SkSCh+ugERm1V8
XEAQ==
X-Forwarded-Encrypted: i=1; AL+hErE4v5aBR5Upxg/DajTdhuJBcIChNOk/A2917ZCCm5bsF2EzBvgJhhcpk+1aLOxmAFVirwUO7B0=@vger.kernel.org
X-Gm-Message-State: APuU4Z8NXfqDmTD4vjGWr7L8gf6pIYhbU/+qwAlndcvcih8xO/nqnvHs
vB+I2cCVIH5JGOyrPCb87CD5bE/N0X6i1qgW2Z0oB3oNSrfbrOGC5aXq
X-Gm-Gg: AYBFou1NO5VH4FnSLWJBX1+yHYcORECm++jAXfuKdcnqHCHxlqslSGrPdkcvt6a5BRx
DRisdjB16fMyQfr1vFCkH8lXZhLvQtPwwFC1QVhUp+REvfYzPvF0h73pBmLAPxMo7Uh6LbUYh4I
6pGKETZwabBCB1n1asIhycztCYUibFeO+DLuC+c0zo/kPA6eCrYZQOPPCoidqOqWuqBKW9cVYF/
v+sj5MdRlcUfavCy6Mo7NMCiP6e8YKvyXnxkowMa2hrzxHQE754KLdsY68PTa6cV+f1JjjDdfZt
corl+1+DZyQvwnli5X+LTlSiUgeZOMPJ9YHLOvVdA9Ykyx7gp6HgOuCPMqYk1xBNp5oLju38+uD
wRSmIt8cTHVmnGRmfOjZG8XvKaGfCPMM4cscSc5SJ7+jgpRl3Pb3os/nPpADDpUqDUfiaOgS+7L
gfzZ3TdNh8U5exlpS+xQECWqPdIEGQMJhiDHK+do+X+yIXRJHADmrXGbRsdKntBrJbXvCVIok6Q
YxNgqJp6arBoyboTsV/0Ttbhs0qUIX2mnx0WBdTmPwNGGA6MuhaJ95tVEx/YUSQd6ai5Agvnyx9
hpRSbWKYeSygEwr4TXhaZYMRNuF5awfxrdKK6NkQ6RBsdps/
X-Received: by 2002:a05:701b:2092:20b0:151:5d01:9316 with SMTP id a92af1059eb24-1b39fedc89fmr6555851c88.23.1794222052154;
Mon, 09 Nov 2026 03:00:52 -0800 (PST)
X-Received: from hj.. ([163.239.22.29])
by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b375604109sm15407609c88.10.2026.11.09.03.00.49
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Mon, 09 Nov 2026 03:00:51 -0800 (PST)
X-Cc: oe-linux-nfc@lists.linux.dev,
netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
stable@vger.kernel.org,
Hyunjung Ko <hj351016@gmail.com>
X-Mailer: git-send-email 2.43.0
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