16a1f539883327300329b88ebb51801525e49147
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / hostapd / 0003-EAP-pwd-fixes.patch
1 This patch combines the following upstream security fixes:
2
3 28a069a545b0 EAP-pwd peer: Fix asymmetric fragmentation behavior
4 3035cc2894e0 EAP-pwd server: Fix Total-Length parsing for fragment reassembly
5 477c74395acd EAP-pwd peer: Fix Total-Length parsing for fragment reassembly
6 e28a58be2618 EAP-pwd server: Fix payload length validation for Commit and Confirm
7 dd2f043c9c43 EAP-pwd peer: Fix payload length validation for Commit and Confirm
8
9 Details at 
10 http://w1.fi/security/2015-4/eap-pwd-missing-payload-length-validation.txt
11
12 Signed-off-by: Baruch Siach <baruch@tkos.co.il>
13 ---
14 diff --git a/src/eap_peer/eap_pwd.c b/src/eap_peer/eap_pwd.c
15 index f2b092669a42..e58b13a42f73 100644
16 --- a/src/eap_peer/eap_pwd.c
17 +++ b/src/eap_peer/eap_pwd.c
18 @@ -355,6 +355,23 @@ eap_pwd_perform_commit_exchange(struct eap_sm *sm, struct eap_pwd_data *data,
19         BIGNUM *mask = NULL, *x = NULL, *y = NULL, *cofactor = NULL;
20         u16 offset;
21         u8 *ptr, *scalar = NULL, *element = NULL;
22 +       size_t prime_len, order_len;
23 +
24 +       if (data->state != PWD_Commit_Req) {
25 +               ret->ignore = TRUE;
26 +               goto fin;
27 +       }
28 +
29 +       prime_len = BN_num_bytes(data->grp->prime);
30 +       order_len = BN_num_bytes(data->grp->order);
31 +
32 +       if (payload_len != 2 * prime_len + order_len) {
33 +               wpa_printf(MSG_INFO,
34 +                          "EAP-pwd: Unexpected Commit payload length %u (expected %u)",
35 +                          (unsigned int) payload_len,
36 +                          (unsigned int) (2 * prime_len + order_len));
37 +               goto fin;
38 +       }
39  
40         if (((data->private_value = BN_new()) == NULL) ||
41             ((data->my_element = EC_POINT_new(data->grp->group)) == NULL) ||
42 @@ -554,6 +571,18 @@ eap_pwd_perform_confirm_exchange(struct eap_sm *sm, struct eap_pwd_data *data,
43         u8 conf[SHA256_MAC_LEN], *cruft = NULL, *ptr;
44         int offset;
45  
46 +       if (data->state != PWD_Confirm_Req) {
47 +               ret->ignore = TRUE;
48 +               goto fin;
49 +       }
50 +
51 +       if (payload_len != SHA256_MAC_LEN) {
52 +               wpa_printf(MSG_INFO,
53 +                          "EAP-pwd: Unexpected Confirm payload length %u (expected %u)",
54 +                          (unsigned int) payload_len, SHA256_MAC_LEN);
55 +               goto fin;
56 +       }
57 +
58         /*
59          * first build up the ciphersuite which is group | random_function |
60          *      prf
61 @@ -837,11 +866,23 @@ eap_pwd_process(struct eap_sm *sm, void *priv, struct eap_method_ret *ret,
62          * if it's the first fragment there'll be a length field
63          */
64         if (EAP_PWD_GET_LENGTH_BIT(lm_exch)) {
65 +               if (len < 2) {
66 +                       wpa_printf(MSG_DEBUG,
67 +                                  "EAP-pwd: Frame too short to contain Total-Length field");
68 +                       ret->ignore = TRUE;
69 +                       return NULL;
70 +               }
71                 tot_len = WPA_GET_BE16(pos);
72                 wpa_printf(MSG_DEBUG, "EAP-pwd: Incoming fragments whose "
73                            "total length = %d", tot_len);
74                 if (tot_len > 15000)
75                         return NULL;
76 +               if (data->inbuf) {
77 +                       wpa_printf(MSG_DEBUG,
78 +                                  "EAP-pwd: Unexpected new fragment start when previous fragment is still in use");
79 +                       ret->ignore = TRUE;
80 +                       return NULL;
81 +               }
82                 data->inbuf = wpabuf_alloc(tot_len);
83                 if (data->inbuf == NULL) {
84                         wpa_printf(MSG_INFO, "Out of memory to buffer "
85 @@ -927,6 +968,7 @@ eap_pwd_process(struct eap_sm *sm, void *priv, struct eap_method_ret *ret,
86         /*
87          * we have output! Do we need to fragment it?
88          */
89 +       lm_exch = EAP_PWD_GET_EXCHANGE(lm_exch);
90         len = wpabuf_len(data->outbuf);
91         if ((len + EAP_PWD_HDR_SIZE) > data->mtu) {
92                 resp = eap_msg_alloc(EAP_VENDOR_IETF, EAP_TYPE_PWD, data->mtu,
93 diff --git a/src/eap_server/eap_server_pwd.c b/src/eap_server/eap_server_pwd.c
94 index 66bd5d2e9179..2bfc3c27647d 100644
95 --- a/src/eap_server/eap_server_pwd.c
96 +++ b/src/eap_server/eap_server_pwd.c
97 @@ -656,9 +656,21 @@ eap_pwd_process_commit_resp(struct eap_sm *sm, struct eap_pwd_data *data,
98         BIGNUM *x = NULL, *y = NULL, *cofactor = NULL;
99         EC_POINT *K = NULL, *point = NULL;
100         int res = 0;
101 +       size_t prime_len, order_len;
102  
103         wpa_printf(MSG_DEBUG, "EAP-pwd: Received commit response");
104  
105 +       prime_len = BN_num_bytes(data->grp->prime);
106 +       order_len = BN_num_bytes(data->grp->order);
107 +
108 +       if (payload_len != 2 * prime_len + order_len) {
109 +               wpa_printf(MSG_INFO,
110 +                          "EAP-pwd: Unexpected Commit payload length %u (expected %u)",
111 +                          (unsigned int) payload_len,
112 +                          (unsigned int) (2 * prime_len + order_len));
113 +               goto fin;
114 +       }
115 +
116         if (((data->peer_scalar = BN_new()) == NULL) ||
117             ((data->k = BN_new()) == NULL) ||
118             ((cofactor = BN_new()) == NULL) ||
119 @@ -774,6 +786,13 @@ eap_pwd_process_confirm_resp(struct eap_sm *sm, struct eap_pwd_data *data,
120         u8 conf[SHA256_MAC_LEN], *cruft = NULL, *ptr;
121         int offset;
122  
123 +       if (payload_len != SHA256_MAC_LEN) {
124 +               wpa_printf(MSG_INFO,
125 +                          "EAP-pwd: Unexpected Confirm payload length %u (expected %u)",
126 +                          (unsigned int) payload_len, SHA256_MAC_LEN);
127 +               goto fin;
128 +       }
129 +
130         /* build up the ciphersuite: group | random_function | prf */
131         grp = htons(data->group_num);
132         ptr = (u8 *) &cs;
133 @@ -923,11 +942,21 @@ static void eap_pwd_process(struct eap_sm *sm, void *priv,
134          * the first fragment has a total length
135          */
136         if (EAP_PWD_GET_LENGTH_BIT(lm_exch)) {
137 +               if (len < 2) {
138 +                       wpa_printf(MSG_DEBUG,
139 +                                  "EAP-pwd: Frame too short to contain Total-Length field");
140 +                       return;
141 +               }
142                 tot_len = WPA_GET_BE16(pos);
143                 wpa_printf(MSG_DEBUG, "EAP-pwd: Incoming fragments, total "
144                            "length = %d", tot_len);
145                 if (tot_len > 15000)
146                         return;
147 +               if (data->inbuf) {
148 +                       wpa_printf(MSG_DEBUG,
149 +                                  "EAP-pwd: Unexpected new fragment start when previous fragment is still in use");
150 +                       return;
151 +               }
152                 data->inbuf = wpabuf_alloc(tot_len);
153                 if (data->inbuf == NULL) {
154                         wpa_printf(MSG_INFO, "EAP-pwd: Out of memory to "