diff options
author | Jouni Malinen <j@w1.fi> | 2015-07-07 21:57:28 +0300 |
---|---|---|
committer | Abhisek Devkota <ciwrl@cyanogenmod.com> | 2015-11-11 08:37:48 -0800 |
commit | 572fb31cb85dc82286e26e7ceb2bca117a4bf6f4 (patch) | |
tree | 89f1d02a07bffdc2347e683abb8606e15df25d0e /src | |
parent | 245c47a8dba8132ec1900bce8a0355ee8c4b36ee (diff) | |
download | android_external_wpa_supplicant_8-572fb31cb85dc82286e26e7ceb2bca117a4bf6f4.tar.gz android_external_wpa_supplicant_8-572fb31cb85dc82286e26e7ceb2bca117a4bf6f4.tar.bz2 android_external_wpa_supplicant_8-572fb31cb85dc82286e26e7ceb2bca117a4bf6f4.zip |
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)
CYNGNOS-1299
Change-Id: Ib8596c753a67b94f55bfae0a714208e775a08218
Signed-off-by: Jouni Malinen <j@w1.fi>
(cherry picked from commit 9ec7ddc175aaf5941b161ecff6c86ad94356b47c)
Diffstat (limited to 'src')
-rw-r--r-- | src/wps/ndef.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/wps/ndef.c b/src/wps/ndef.c index d45dfc8e..ab71e192 100644 --- a/src/wps/ndef.c +++ b/src/wps/ndef.c @@ -48,6 +48,8 @@ static int ndef_parse_record(const u8 *data, u32 size, if (size < 6) return -1; record->payload_length = ntohl(*(u32 *)pos); + if (record->payload_length > size - 6) + return -1; pos += sizeof(u32); } @@ -68,7 +70,8 @@ static int ndef_parse_record(const u8 *data, u32 size, pos += record->payload_length; record->total_length = pos - data; - if (record->total_length > size) + if (record->total_length > size || + record->total_length < record->payload_length) return -1; return 0; } |