nfc: pn533: fix OOB read in pn533_acr122_is_rx_frame_valid()
PATCH v2 1/1 nfc: pn533: fix OOB read in pn533_acr122_is_rx_frame_valid()
frame->ccid.datalen is read directly from the USB response frame and used, unchecked, as an index into frame->data[]. A malicious or malfunctioning device can set this field to an arbitrary value, causing the driver to read far outside the received buffer.
Bound ccid.datalen against the maximum possible ACR122 frame size before using it. This replaces the existing datalen == 0 check, since datalen < 2 already covers that case and additionally rejects datalen == 1, which would still underflow the "datalen - 2" offset used below.
---
Changes in v2:
- Replace the existing "if (!frame->ccid.datalen)" check instead of adding the new bounds check alongside it, since the new check already subsumes it (per Johan Hovold).
--- drivers/nfc/pn533/usb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nfc/pn533/usb.c +3 -1
@@ -319,7 +319,9 @@ static bool pn533_acr122_is_rx_frame_valid(void *_frame, struct pn533 *dev)if (frame->ccid.type !=0x83 )return false; -if (!frame->ccid.datalen) +if (frame->ccid.datalen <2 || + frame->ccid.datalen >PN533_ACR122_FRAME_MAX_PAYLOAD_LEN + +PN533_ACR122_RX_FRAME_TAIL_LEN )return false;if (frame->data[frame->ccid.datalen -2 ] ==0x63 )
Signature · 1 line
2.43.0
David Heidelberg
maintainerQuoted 11 lines · Deepanshu Kartikey
frame->ccid.datalenis read directly from the USB response frame and used, unchecked, as an index into frame->data[]. A malicious or malfunctioning device can set this field to an arbitrary value, causing the driver to read far outside the received buffer.Bound ccid.datalen against the maximum possible ACR122 frame size before using it. This replaces the existing datalen == 0 check, since datalen < 2 already covers that case and additionally rejects datalen == 1, which would still underflow the "datalen - 2" offset used below.
Quoted 5 lines
Fixes 9815c7cf22da ("NFC: pn533: Separate physical layer from the core implementation")Reported-by [email protected]Tested-by [email protected]Assisted-by Claude (Anthropic)
Hello Deepanshu,
thank you for the patch, could you please correct the Assisted-by tag?
See: https://docs.kernel.org/process/coding-assistants.html
Thanks
David
Quoted 11 lines
Signed-off-by Deepanshu Kartikey <[email protected]>---
Changes in v2:
- Replace the existing "if (!frame->ccid.datalen)" check instead of adding the new bounds check alongside it, since the new check already subsumes it (per Johan Hovold).--- drivers/nfc/pn533/usb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 19 lines · David Heidelberg
Quoted 11 lines · Deepanshu Kartikey
frame->ccid.datalenis read directly from the USB response frame and used, unchecked, as an index into frame->data[]. A malicious or malfunctioning device can set this field to an arbitrary value, causing the driver to read far outside the received buffer.Bound ccid.datalen against the maximum possible ACR122 frame size before using it. This replaces the existing datalen == 0 check, since datalen < 2 already covers that case and additionally rejects datalen == 1, which would still underflow the "datalen - 2" offset used below.
Quoted 5 lines
Fixes 9815c7cf22da ("NFC: pn533: Separate physical layer from the core implementation")Reported-by [email protected]Tested-by [email protected]Assisted-by Claude (Anthropic)
Quoted 9 lines
Hello Deepanshu,
thank you for the patch, could you please correct the Assisted-by tag?
See: https://docs.kernel.org/process/coding-assistants.html
Thanks
David
Sure, I will send patch v3 shortly.
Thanks