5dca20b2771b855ac724ce0b0bf4bee2e377f7bf
[openwrt/staging/pepe2k.git] /
1 From e28a58be26184c2a23f80b410e0997ef1bd5d578 Mon Sep 17 00:00:00 2001
2 From: Jouni Malinen <j@w1.fi>
3 Date: Fri, 1 May 2015 16:40:44 +0300
4 Subject: [PATCH 2/5] EAP-pwd server: 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_server/eap_server_pwd.c | 19 +++++++++++++++++++
22 1 file changed, 19 insertions(+)
23
24 diff --git a/src/eap_server/eap_server_pwd.c b/src/eap_server/eap_server_pwd.c
25 index 66bd5d2..3189105 100644
26 --- a/src/eap_server/eap_server_pwd.c
27 +++ b/src/eap_server/eap_server_pwd.c
28 @@ -656,9 +656,21 @@ eap_pwd_process_commit_resp(struct eap_sm *sm, struct eap_pwd_data *data,
29 BIGNUM *x = NULL, *y = NULL, *cofactor = NULL;
30 EC_POINT *K = NULL, *point = NULL;
31 int res = 0;
32 + size_t prime_len, order_len;
33
34 wpa_printf(MSG_DEBUG, "EAP-pwd: Received commit response");
35
36 + prime_len = BN_num_bytes(data->grp->prime);
37 + order_len = BN_num_bytes(data->grp->order);
38 +
39 + if (payload_len != 2 * prime_len + order_len) {
40 + wpa_printf(MSG_INFO,
41 + "EAP-pwd: Unexpected Commit payload length %u (expected %u)",
42 + (unsigned int) payload_len,
43 + (unsigned int) (2 * prime_len + order_len));
44 + goto fin;
45 + }
46 +
47 if (((data->peer_scalar = BN_new()) == NULL) ||
48 ((data->k = BN_new()) == NULL) ||
49 ((cofactor = BN_new()) == NULL) ||
50 @@ -774,6 +786,13 @@ eap_pwd_process_confirm_resp(struct eap_sm *sm, struct eap_pwd_data *data,
51 u8 conf[SHA256_MAC_LEN], *cruft = NULL, *ptr;
52 int offset;
53
54 + if (payload_len != SHA256_MAC_LEN) {
55 + wpa_printf(MSG_INFO,
56 + "EAP-pwd: Unexpected Confirm payload length %u (expected %u)",
57 + (unsigned int) payload_len, SHA256_MAC_LEN);
58 + goto fin;
59 + }
60 +
61 /* build up the ciphersuite: group | random_function | prf */
62 grp = htons(data->group_num);
63 ptr = (u8 *) &cs;
64 --
65 1.9.1
66