Skip to contentSkip to conversation

NFC: pn533: potential buffer overflow in pn533_target_found_type_a()

PATCH New Dan Carpenter 1 participant 1 message Mar 28, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFC: pn533: potential buffer overflow in pn533_target_found_type_a()

Smatch doesn't trust information that comes from skb->data. It complains that "nfc_tgt->nfcid1_len" is a u8 so it could be up to 255 bytes, but the destination buffer is only 10 bytes large.

Fixes c3b1e1e8a76f ("NFC: Export NFCID1 from pn533")
---
 drivers/nfc/pn533/pn533.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/nfc/pn533/pn533.c +2 -0
index a0cc1cc45292..9f9bbf912687 100644
@@ -724,6 +724,8 @@ static int pn533_target_found_type_a(struct nfc_target *nfc_tgt, u8 *tgt_data,
 	nfc_tgt->sens_res = be16_to_cpu(tgt_type_a->sens_res);
 	nfc_tgt->sel_res = tgt_type_a->sel_res;
 	nfc_tgt->nfcid1_len = tgt_type_a->nfcid_len;
+	if (nfc_tgt->nfcid1_len > sizeof(nfc_tgt->nfcid1))
+		return -EINVAL;
 	memcpy(nfc_tgt->nfcid1, tgt_type_a->nfcid_data, nfc_tgt->nfcid1_len);
 
 	return 0;
Signature · 1 line
2.17.1