NFC: Fix payload length validation in NDEF record parser
authorJouni Malinen <j@w1.fi>
Tue, 7 Jul 2015 18:57:28 +0000 (21:57 +0300)
committerJouni Malinen <j@w1.fi>
Wed, 8 Jul 2015 13:52:25 +0000 (16:52 +0300)
commitdf9079e72760ceb7ebe7fb11538200c516bdd886
tree43cc8b1900ba8dfd53edc0a19aab49a6cb2b4fd7
parentb843a8b8a6150d1364efb7d9c05bec913b65c3bd
NFC: Fix payload length validation in NDEF record parser

It was possible for the 32-bit record->total_length value to end up
wrapping around due to integer overflow if the longer form of payload
length field is used and record->payload_length gets a value close to
2^32. This could result in ndef_parse_record() accepting a too large
payload length value and the record type filter reading up to about 20
bytes beyond the end of the buffer and potentially killing the process.
This could also result in an attempt to allocate close to 2^32 bytes of
heap memory and if that were to succeed, a buffer read overflow of the
same length which would most likely result in the process termination.
In case of record->total_length ending up getting the value 0, there
would be no buffer read overflow, but record parsing would result in an
infinite loop in ndef_parse_records().

Any of these error cases could potentially be used for denial of service
attacks over NFC by using a malformed NDEF record on an NFC Tag or
sending them during NFC connection handover if the application providing
the NDEF message to hostapd/wpa_supplicant did no validation of the
received records. While such validation is likely done in the NFC stack
that needs to parse the NFC messages before further processing,
hostapd/wpa_supplicant better be prepared for any data being included
here.

Fix this by validating record->payload_length value in a way that
detects integer overflow. (CID 122668)

Signed-off-by: Jouni Malinen <j@w1.fi>
src/wps/ndef.c