* [PATCH net v2] nfc: nci: fix use of uninitialized memory in NFC-DEP general bytes
2026-06-28 21:16 [PATCH net] " Muhammad Bilal
@ 2026-06-28 21:45 ` Muhammad Bilal
0 siblings, 0 replies; 2+ messages in thread
From: Muhammad Bilal @ 2026-06-28 21:45 UTC (permalink / raw)
To: david
Cc: netdev, davem, edumazet, kuba, pabeni, horms, oe-linux-nfc,
linux-kernel, stable, Muhammad Bilal
nci_store_general_bytes_nfc_dep() derives the length of the NFC-DEP
general bytes by subtracting the fixed general-bytes offset from the ATR
length:
atr_res_len - NFC_ATR_RES_GT_OFFSET (poll, offset 15)
atr_req_len - NFC_ATR_REQ_GT_OFFSET (listen, offset 14)
It never checks that the ATR is at least that long. When a
RF_INTF_ACTIVATED_NTF reports an ATR shorter than the offset the
subtraction is negative; because min_t() casts its arguments to __u8 the
negative value becomes large and is then capped at
NFC_ATR_RES_GB_MAXSIZE / NFC_ATR_REQ_GB_MAXSIZE. remote_gb_len is thus
set to up to 47/48 even though only atr_res_len/atr_req_len bytes of the
on-stack atr_res/atr_req buffer were copied from the packet, and the
following memcpy() reads the uninitialized remainder into
ndev->remote_gb.
Zero remote_gb_len and skip storing the general bytes when the ATR is
shorter than the general-bytes offset, so that a stale remote_gb_len
from a previous activation does not survive into the new session.
Fixes: a99903ec4566 ("NFC: NCI: Handle Target mode activation")
Cc: stable@vger.kernel.org
Signed-off-by: Muhammad Bilal <meatuni001@gmail.com>
---
net/nfc/nci/ntf.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/net/nfc/nci/ntf.c b/net/nfc/nci/ntf.c
index 802928ca4d51e..b72545daa2051 100644
--- a/net/nfc/nci/ntf.c
+++ b/net/nfc/nci/ntf.c
@@ -654,8 +654,10 @@ static int nci_store_general_bytes_nfc_dep(struct nci_dev *ndev,
case NCI_NFC_A_PASSIVE_POLL_MODE:
case NCI_NFC_F_PASSIVE_POLL_MODE:
if (ntf->activation_params.poll_nfc_dep.atr_res_len <
- NFC_ATR_RES_GT_OFFSET)
+ NFC_ATR_RES_GT_OFFSET) {
+ ndev->remote_gb_len = 0;
break;
+ }
ndev->remote_gb_len = min_t(__u8,
(ntf->activation_params.poll_nfc_dep.atr_res_len
- NFC_ATR_RES_GT_OFFSET),
@@ -669,8 +671,10 @@ static int nci_store_general_bytes_nfc_dep(struct nci_dev *ndev,
case NCI_NFC_A_PASSIVE_LISTEN_MODE:
case NCI_NFC_F_PASSIVE_LISTEN_MODE:
if (ntf->activation_params.listen_nfc_dep.atr_req_len <
- NFC_ATR_REQ_GT_OFFSET)
+ NFC_ATR_REQ_GT_OFFSET) {
+ ndev->remote_gb_len = 0;
break;
+ }
ndev->remote_gb_len = min_t(__u8,
(ntf->activation_params.listen_nfc_dep.atr_req_len
- NFC_ATR_REQ_GT_OFFSET),
--
2.54.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH net v2] nfc: nci: fix use of uninitialized memory in NFC-DEP general bytes
@ 2026-06-28 21:49 Muhammad Bilal
0 siblings, 0 replies; 2+ messages in thread
From: Muhammad Bilal @ 2026-06-28 21:49 UTC (permalink / raw)
To: david
Cc: netdev, davem, edumazet, kuba, pabeni, horms, oe-linux-nfc,
linux-kernel, stable, Muhammad Bilal
nci_store_general_bytes_nfc_dep() derives the length of the NFC-DEP
general bytes by subtracting the fixed general-bytes offset from the ATR
length:
atr_res_len - NFC_ATR_RES_GT_OFFSET (poll, offset 15)
atr_req_len - NFC_ATR_REQ_GT_OFFSET (listen, offset 14)
It never checks that the ATR is at least that long. When a
RF_INTF_ACTIVATED_NTF reports an ATR shorter than the offset the
subtraction is negative; because min_t() casts its arguments to __u8 the
negative value becomes large and is then capped at
NFC_ATR_RES_GB_MAXSIZE / NFC_ATR_REQ_GB_MAXSIZE. remote_gb_len is thus
set to up to 47/48 even though only atr_res_len/atr_req_len bytes of the
on-stack atr_res/atr_req buffer were copied from the packet, and the
following memcpy() reads the uninitialized remainder into
ndev->remote_gb.
Zero remote_gb_len and skip storing the general bytes when the ATR is
shorter than the general-bytes offset, so that a stale remote_gb_len
from a previous activation does not survive into the new session.
Fixes: a99903ec4566 ("NFC: NCI: Handle Target mode activation")
Cc: stable@vger.kernel.org
Signed-off-by: Muhammad Bilal <meatuni001@gmail.com>
---
net/nfc/nci/ntf.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/net/nfc/nci/ntf.c b/net/nfc/nci/ntf.c
index 802928ca4d51e..b72545daa2051 100644
--- a/net/nfc/nci/ntf.c
+++ b/net/nfc/nci/ntf.c
@@ -654,8 +654,10 @@ static int nci_store_general_bytes_nfc_dep(struct nci_dev *ndev,
case NCI_NFC_A_PASSIVE_POLL_MODE:
case NCI_NFC_F_PASSIVE_POLL_MODE:
if (ntf->activation_params.poll_nfc_dep.atr_res_len <
- NFC_ATR_RES_GT_OFFSET)
+ NFC_ATR_RES_GT_OFFSET) {
+ ndev->remote_gb_len = 0;
break;
+ }
ndev->remote_gb_len = min_t(__u8,
(ntf->activation_params.poll_nfc_dep.atr_res_len
- NFC_ATR_RES_GT_OFFSET),
@@ -669,8 +671,10 @@ static int nci_store_general_bytes_nfc_dep(struct nci_dev *ndev,
case NCI_NFC_A_PASSIVE_LISTEN_MODE:
case NCI_NFC_F_PASSIVE_LISTEN_MODE:
if (ntf->activation_params.listen_nfc_dep.atr_req_len <
- NFC_ATR_REQ_GT_OFFSET)
+ NFC_ATR_REQ_GT_OFFSET) {
+ ndev->remote_gb_len = 0;
break;
+ }
ndev->remote_gb_len = min_t(__u8,
(ntf->activation_params.listen_nfc_dep.atr_req_len
- NFC_ATR_REQ_GT_OFFSET),
--
2.54.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-28 21:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-28 21:49 [PATCH net v2] nfc: nci: fix use of uninitialized memory in NFC-DEP general bytes Muhammad Bilal
-- strict thread matches above, loose matches on Subject: below --
2026-06-28 21:16 [PATCH net] " Muhammad Bilal
2026-06-28 21:45 ` [PATCH net v2] " Muhammad Bilal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox