dd3462465ea4ff460c5be5a10379da9b72973007
[openwrt/svn-archive/archive.git] /
1 From df9079e72760ceb7ebe7fb11538200c516bdd886 Mon Sep 17 00:00:00 2001
2 From: Jouni Malinen <j@w1.fi>
3 Date: Tue, 7 Jul 2015 21:57:28 +0300
4 Subject: [PATCH] NFC: Fix payload length validation in NDEF record parser
5
6 It was possible for the 32-bit record->total_length value to end up
7 wrapping around due to integer overflow if the longer form of payload
8 length field is used and record->payload_length gets a value close to
9 2^32. This could result in ndef_parse_record() accepting a too large
10 payload length value and the record type filter reading up to about 20
11 bytes beyond the end of the buffer and potentially killing the process.
12 This could also result in an attempt to allocate close to 2^32 bytes of
13 heap memory and if that were to succeed, a buffer read overflow of the
14 same length which would most likely result in the process termination.
15 In case of record->total_length ending up getting the value 0, there
16 would be no buffer read overflow, but record parsing would result in an
17 infinite loop in ndef_parse_records().
18
19 Any of these error cases could potentially be used for denial of service
20 attacks over NFC by using a malformed NDEF record on an NFC Tag or
21 sending them during NFC connection handover if the application providing
22 the NDEF message to hostapd/wpa_supplicant did no validation of the
23 received records. While such validation is likely done in the NFC stack
24 that needs to parse the NFC messages before further processing,
25 hostapd/wpa_supplicant better be prepared for any data being included
26 here.
27
28 Fix this by validating record->payload_length value in a way that
29 detects integer overflow. (CID 122668)
30
31 Signed-off-by: Jouni Malinen <j@w1.fi>
32 ---
33 src/wps/ndef.c | 5 ++++-
34 1 file changed, 4 insertions(+), 1 deletion(-)
35
36 diff --git a/src/wps/ndef.c b/src/wps/ndef.c
37 index 5604b0a..50d018f 100644
38 --- a/src/wps/ndef.c
39 +++ b/src/wps/ndef.c
40 @@ -48,6 +48,8 @@ static int ndef_parse_record(const u8 *data, u32 size,
41 if (size < 6)
42 return -1;
43 record->payload_length = ntohl(*(u32 *)pos);
44 + if (record->payload_length > size - 6)
45 + return -1;
46 pos += sizeof(u32);
47 }
48
49 @@ -68,7 +70,8 @@ static int ndef_parse_record(const u8 *data, u32 size,
50 pos += record->payload_length;
51
52 record->total_length = pos - data;
53 - if (record->total_length > size)
54 + if (record->total_length > size ||
55 + record->total_length < record->payload_length)
56 return -1;
57 return 0;
58 }
59 --
60 1.9.1
61