Skip to content

Commit 20f1f64

Browse files
author
Mika Leppänen
committed
Added ignoring of retry messages from RADIUS server when waiting EAP-TLS
Retry messages were not ignored correcly and caused memory corruption.
1 parent 8a8b407 commit 20f1f64

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111

1212
### Bug fixes
13-
*
13+
* Added ignoring of retry messages from RADIUS server when waiting EAP-TLS
1414

1515

1616
## Release v13.0.0 (15-04-2021)

source/Security/protocols/radius_sec_prot/radius_client_sec_prot.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ typedef enum {
7171
#define RADIUS_ACCESS_ACCEPT 2
7272
#define RADIUS_ACCESS_REJECT 3
7373
#define RADIUS_ACCESS_CHALLENGE 11
74+
#define RADIUS_MESSAGE_NONE 0
7475

7576
#define MS_MPPE_RECV_KEY_SALT_LEN 2
7677
#define MS_MPPE_RECV_KEY_BLOCK_LEN 16
@@ -239,14 +240,15 @@ static int8_t radius_client_sec_prot_init(sec_prot_t *prot)
239240
data->send_radius_msg = NULL;
240241
data->identity_len = 0;
241242
data->identity = NULL;
242-
data->radius_code = 0;
243+
data->radius_code = RADIUS_MESSAGE_NONE;
243244
data->radius_identifier = 0;
244245
memset(data->request_authenticator, 0, 16);
245246
data->state_len = 0;
246247
data->state = NULL;
247248
memset(data->remote_eui_64_hash, 0, 8);
248249
data->remote_eui_64_hash_set = false;
249250
data->new_pmk_set = false;
251+
data->radius_id_range_set = false;
250252

251253
if (!shared_data) {
252254
shared_data = ns_dyn_mem_alloc(sizeof(radius_client_sec_prot_shared_t));
@@ -379,6 +381,10 @@ static int8_t radius_client_sec_prot_receive(sec_prot_t *prot, void *pdu, uint16
379381
uint8_t *radius_msg_ptr = pdu;
380382

381383
uint8_t code = *radius_msg_ptr++;
384+
if (code != RADIUS_ACCESS_ACCEPT && code != RADIUS_ACCESS_REJECT && code != RADIUS_ACCESS_CHALLENGE) {
385+
return -1;
386+
}
387+
382388
uint8_t identifier = *radius_msg_ptr++;
383389
/* If identifier does not match to sent identifier, silently ignore message,
384390
already checked on socket if before routing the request to receive, so
@@ -430,6 +436,7 @@ static int8_t radius_client_sec_prot_receive(sec_prot_t *prot, void *pdu, uint16
430436
// Message does not have radius EAP-TLS specific fields
431437
data->radius_code = code;
432438
prot->state_machine(prot);
439+
data->radius_code = RADIUS_MESSAGE_NONE;
433440

434441
return 0;
435442
}
@@ -519,6 +526,7 @@ static int8_t radius_client_sec_prot_receive(sec_prot_t *prot, void *pdu, uint16
519526
data->radius_code = code;
520527
data->recv_eap_msg_len += data->radius_eap_tls_header_size;
521528
prot->state_machine(prot);
529+
data->radius_code = RADIUS_MESSAGE_NONE;
522530

523531
return 0;
524532
}
@@ -1127,6 +1135,16 @@ static void radius_client_sec_prot_state_machine(sec_prot_t *prot)
11271135
return;
11281136
}
11291137

1138+
if (data->radius_code != RADIUS_MESSAGE_NONE) {
1139+
// Received retry for already handled message from RADIUS server, ignore
1140+
if (data->recv_eap_msg) {
1141+
ns_dyn_mem_free(data->recv_eap_msg);
1142+
}
1143+
data->recv_eap_msg = NULL;
1144+
data->recv_eap_msg_len = 0;
1145+
return;
1146+
}
1147+
11301148
tr_info("Radius: send access request, eui-64: %s", trace_array(sec_prot_remote_eui_64_addr_get(prot), 8));
11311149

11321150
radius_client_sec_prot_allocate_and_create_radius_message(prot);

0 commit comments

Comments
 (0)