Skip to contentSkip to conversation

NFC: digital: Bounds check NFC-A cascade depth in SDD response handler

PATCH In review Greg Kroah-Hartman 3 participants 4 messages Apr 9 – Apr 12

Subsystems (3)
lore
Share & tools
lore
#1 lore raw

PATCH 2/2 NFC: digital: Bounds check Felica response before sensf_res memcpy

In reply to Greg Kroah-Hartman

A malicious NFC peer can send a SENSF_RES that is longer than the NFC_SENSF_RES_MAXSIZE (18 byte) sensf_res field in the onstack struct nfc_target. digital_in_recv_sensf_res() validates that the response is at least DIGITAL_SENSF_RES_MIN_LENGTH bytes but applies no upper bound before memcpy(target.sensf_res, sensf_res, resp->len) is called, allowing a stack buffer overflow with attacker-controlled length and content.

Commit e329e71013c9 ("NFC: nci: Bounds check struct nfc_target arrays") fixed identical missing checks for the same target->sensf_res field on the NCI path; the Digital Protocol path was never patched.

Fix this all up by just rejecting responses that exceed NFC_SENSF_RES_MAXSIZE.

Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Simon Horman <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Kees Cook <[email protected]>
Cc Thierry Escande <[email protected]>
Cc Samuel Ortiz <[email protected]>
Fixes 8c0695e4998d ("NFC Digital: Add NFC-F technology support")
Cc stable <[email protected]>
Assisted-by gregkh_clanker_t1000
---
 net/nfc/digital_technology.c | 5 +++++
 1 file changed, 5 insertions(+)
net/nfc/digital_technology.c +5 -0
index ae63c5eb06fa..e18bdb231352 100644
@@ -774,6 +774,11 @@ static void digital_in_recv_sensf_res(struct nfc_digital_dev *ddev, void *arg,
 
 	skb_pull(resp, 1);
 
+	if (resp->len > NFC_SENSF_RES_MAXSIZE) {
+		rc = -EPROTO;
+		goto exit;
+	}
+
 	memset(&target, 0, sizeof(struct nfc_target));
 
 	sensf_res = (struct digital_sensf_res *)resp->data;
Signature · 1 line
2.53.0
#0 lore raw

PATCH 1/2 NFC: digital: Bounds check NFC-A cascade depth in SDD response handler

The NFC-A anti-collision cascade in digital_in_recv_sdd_res() appends 3 or 4 bytes to target->nfcid1 on each round, but the number of cascade rounds is controlled entirely by the peer device. The peer sets the cascade tag in the SDD_RES (deciding 3 vs 4 bytes) and the cascade-incomplete bit in the SEL_RES (deciding whether another round follows).

ISO 14443-3 limits NFC-A to three cascade levels and target->nfcid1 is sized accordingly (NFC_NFCID1_MAXSIZE = 10), but nothing in the driver actually enforces this. This means a malicious peer can keep the cascade running, writing past the heap-allocated nfc_target with each round.

Fix this by rejecting the response when the accumulated UID would exceed the buffer.

Commit e329e71013c9 ("NFC: nci: Bounds check struct nfc_target arrays") fixed similar missing checks against the same field on the NCI path.

Cc "David S. Miller" <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Jakub Kicinski <[email protected]>
Cc Paolo Abeni <[email protected]>
Cc Simon Horman <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc Kees Cook <[email protected]>
Cc Thierry Escande <[email protected]>
Cc Samuel Ortiz <[email protected]>
Fixes 2c66daecc409 ("NFC Digital: Add NFC-A technology support")
Cc stable <[email protected]>
Assisted-by gregkh_clanker_t1000
---
 net/nfc/digital_technology.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/nfc/digital_technology.c +6 -0
index 63f1b721c71d..ae63c5eb06fa 100644
@@ -424,6 +424,12 @@ static void digital_in_recv_sdd_res(struct nfc_digital_dev *ddev, void *arg,
 		size = 4;
 	}
 
+	if (target->nfcid1_len + size > NFC_NFCID1_MAXSIZE) {
+		PROTOCOL_ERR("4.7.2.1");
+		rc = -EPROTO;
+		goto exit;
+	}
+
 	memcpy(target->nfcid1 + target->nfcid1_len, sdd_res->nfcid1 + offset,
 	       size);
 	target->nfcid1_len += size;
Signature · 1 line
2.53.0
maintainer
#2 lore raw

Re: [PATCH net 2/2] NFC: digital: Bounds check Felica response before sensf_res memcpy

In reply to Greg Kroah-Hartman
Quoted 8 lines · On Thu, 9 Apr 2026 17:18:15 +0200 Greg Kroah-Hartman wrote:

A malicious NFC peer can send a SENSF_RES that is longer than the NFC_SENSF_RES_MAXSIZE (18 byte) sensf_res field in the onstack struct nfc_target. digital_in_recv_sensf_res() validates that the response is at least DIGITAL_SENSF_RES_MIN_LENGTH bytes but applies no upper bound before memcpy(target.sensf_res, sensf_res, resp->len) is called, allowing a stack buffer overflow with attacker-controlled length and content.

Quoted 6 lines

Commit e329e71013c9 ("NFC: nci: Bounds check struct nfc_target arrays") fixed identical missing checks for the same target->sensf_res field on the NCI path; the Digital Protocol path was never patched.

Fix this all up by just rejecting responses that exceed NFC_SENSF_RES_MAXSIZE.

This driver's local definition of the sensf_res struct seems to be larger than NFC_SENSF_RES_MAXSIZE. Something is off here.

#3 lore raw
In reply to Greg Kroah-Hartman
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Thu, 9 Apr 2026 17:18:14 +0200 you wrote:

The NFC-A anti-collision cascade in digital_in_recv_sdd_res() appends 3 or 4 bytes to target->nfcid1 on each round, but the number of cascade rounds is controlled entirely by the peer device. The peer sets the cascade tag in the SDD_RES (deciding 3 vs 4 bytes) and the cascade-incomplete bit in the SEL_RES (deciding whether another round follows).

[...]

Here is the summary with links:
- [net,1/2] NFC: digital: Bounds check NFC-A cascade depth in SDD response handler

    https://git.kernel.org/netdev/net/c/46ce8be2ced3

- [net,2/2] NFC: digital: Bounds check Felica response before sensf_res memcpy (no matching commit)

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html