91627fb7b7f6bf43b085290cbd135bba18325295
[openwrt/staging/pepe2k.git] /
1 From dd2f043c9c43d156494e33d7ce22db96e6ef42c7 Mon Sep 17 00:00:00 2001
2 From: Jouni Malinen <j@w1.fi>
3 Date: Fri, 1 May 2015 16:37:45 +0300
4 Subject: [PATCH 1/5] EAP-pwd peer: Fix payload length validation for Commit
5 and Confirm
6
7 The length of the received Commit and Confirm message payloads was not
8 checked before reading them. This could result in a buffer read
9 overflow when processing an invalid message.
10
11 Fix this by verifying that the payload is of expected length before
12 processing it. In addition, enforce correct state transition sequence to
13 make sure there is no unexpected behavior if receiving a Commit/Confirm
14 message before the previous exchanges have been completed.
15
16 Thanks to Kostya Kortchinsky of Google security team for discovering and
17 reporting this issue.
18
19 Signed-off-by: Jouni Malinen <j@w1.fi>
20 ---
21 src/eap_peer/eap_pwd.c | 29 +++++++++++++++++++++++++++++
22 1 file changed, 29 insertions(+)
23
24 diff --git a/src/eap_peer/eap_pwd.c b/src/eap_peer/eap_pwd.c
25 index f2b0926..a629437 100644
26 --- a/src/eap_peer/eap_pwd.c
27 +++ b/src/eap_peer/eap_pwd.c
28 @@ -355,6 +355,23 @@ eap_pwd_perform_commit_exchange(struct eap_sm *sm, struct eap_pwd_data *data,
29 BIGNUM *mask = NULL, *x = NULL, *y = NULL, *cofactor = NULL;
30 u16 offset;
31 u8 *ptr, *scalar = NULL, *element = NULL;
32 + size_t prime_len, order_len;
33 +
34 + if (data->state != PWD_Commit_Req) {
35 + ret->ignore = TRUE;
36 + goto fin;
37 + }
38 +
39 + prime_len = BN_num_bytes(data->grp->prime);
40 + order_len = BN_num_bytes(data->grp->order);
41 +
42 + if (payload_len != 2 * prime_len + order_len) {
43 + wpa_printf(MSG_INFO,
44 + "EAP-pwd: Unexpected Commit payload length %u (expected %u)",
45 + (unsigned int) payload_len,
46 + (unsigned int) (2 * prime_len + order_len));
47 + goto fin;
48 + }
49
50 if (((data->private_value = BN_new()) == NULL) ||
51 ((data->my_element = EC_POINT_new(data->grp->group)) == NULL) ||
52 @@ -554,6 +571,18 @@ eap_pwd_perform_confirm_exchange(struct eap_sm *sm, struct eap_pwd_data *data,
53 u8 conf[SHA256_MAC_LEN], *cruft = NULL, *ptr;
54 int offset;
55
56 + if (data->state != PWD_Confirm_Req) {
57 + ret->ignore = TRUE;
58 + goto fin;
59 + }
60 +
61 + if (payload_len != SHA256_MAC_LEN) {
62 + wpa_printf(MSG_INFO,
63 + "EAP-pwd: Unexpected Confirm payload length %u (expected %u)",
64 + (unsigned int) payload_len, SHA256_MAC_LEN);
65 + goto fin;
66 + }
67 +
68 /*
69 * first build up the ciphersuite which is group | random_function |
70 * prf
71 --
72 1.9.1
73