system/bt
Revisão | 4a71fca191b41e5931b35e1b9c3a4b74ab170322 (tree) |
---|---|
Hora | 2018-12-06 17:19:33 |
Autor | Jakub Pawlowski <jpawlowski@goog...> |
Commiter | JP Sugarbroad |
Fix buffer overflow in btif_dm_data_copy
When we use a union, we should always define variables as the union type,
not as one of the field subtypes. If the latter is cast to the union type,
buffer overflow can happen.
Bug: 110166268
Test: compilation
Change-Id: I473c03b099ad5a326e7a3739f65efd33cf4775bd
Merged-In: I473c03b099ad5a326e7a3739f65efd33cf4775bd
(cherry picked from commit d1179759041eb66baf1b5cd398d69ce58849d848)
@@ -398,7 +398,7 @@ void smp_send_keypress_notification(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) | ||
398 | 398 | *******************************************************************************/ |
399 | 399 | void smp_send_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) |
400 | 400 | { |
401 | - tBTM_LE_LENC_KEYS le_key; | |
401 | + tBTM_LE_KEY_VALUE key; | |
402 | 402 | |
403 | 403 | SMP_TRACE_DEBUG("%s p_cb->loc_enc_size = %d", __func__, p_cb->loc_enc_size); |
404 | 404 | smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ENC, FALSE); |
@@ -407,14 +407,13 @@ void smp_send_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) | ||
407 | 407 | smp_send_cmd(SMP_OPCODE_MASTER_ID, p_cb); |
408 | 408 | |
409 | 409 | /* save the DIV and key size information when acting as slave device */ |
410 | - memcpy(le_key.ltk, p_cb->ltk, BT_OCTET16_LEN); | |
411 | - le_key.div = p_cb->div; | |
412 | - le_key.key_size = p_cb->loc_enc_size; | |
413 | - le_key.sec_level = p_cb->sec_level; | |
410 | + memcpy(key.lenc_key.ltk, p_cb->ltk, BT_OCTET16_LEN); | |
411 | + key.lenc_key.div = p_cb->div; | |
412 | + key.lenc_key.key_size = p_cb->loc_enc_size; | |
413 | + key.lenc_key.sec_level = p_cb->sec_level; | |
414 | 414 | |
415 | 415 | if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) |
416 | - btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LENC, | |
417 | - (tBTM_LE_KEY_VALUE *)&le_key, TRUE); | |
416 | + btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LENC, &key, TRUE); | |
418 | 417 | |
419 | 418 | SMP_TRACE_WARNING ("%s", __func__); |
420 | 419 |
@@ -448,17 +447,17 @@ void smp_send_id_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) | ||
448 | 447 | *******************************************************************************/ |
449 | 448 | void smp_send_csrk_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) |
450 | 449 | { |
451 | - tBTM_LE_LCSRK_KEYS key; | |
450 | + tBTM_LE_KEY_VALUE key; | |
452 | 451 | SMP_TRACE_DEBUG("%s", __func__); |
453 | 452 | smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_CSRK, FALSE); |
454 | 453 | |
455 | 454 | if (smp_send_cmd(SMP_OPCODE_SIGN_INFO, p_cb)) |
456 | 455 | { |
457 | - key.div = p_cb->div; | |
458 | - key.sec_level = p_cb->sec_level; | |
459 | - key.counter = 0; /* initialize the local counter */ | |
460 | - memcpy (key.csrk, p_cb->csrk, BT_OCTET16_LEN); | |
461 | - btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LCSRK, (tBTM_LE_KEY_VALUE *)&key, TRUE); | |
456 | + key.lcsrk_key.div = p_cb->div; | |
457 | + key.lcsrk_key.sec_level = p_cb->sec_level; | |
458 | + key.lcsrk_key.counter = 0; /* initialize the local counter */ | |
459 | + memcpy (key.lcsrk_key.csrk, p_cb->csrk, BT_OCTET16_LEN); | |
460 | + btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LCSRK, &key, TRUE); | |
462 | 461 | } |
463 | 462 | |
464 | 463 | smp_key_distribution_by_transport(p_cb, NULL); |
@@ -1035,7 +1034,7 @@ void smp_proc_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) | ||
1035 | 1034 | void smp_proc_master_id(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) |
1036 | 1035 | { |
1037 | 1036 | UINT8 *p = (UINT8 *)p_data; |
1038 | - tBTM_LE_PENC_KEYS le_key; | |
1037 | + tBTM_LE_KEY_VALUE le_key; | |
1039 | 1038 | |
1040 | 1039 | SMP_TRACE_DEBUG("%s", __func__); |
1041 | 1040 |
@@ -1048,18 +1047,16 @@ void smp_proc_master_id(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) | ||
1048 | 1047 | |
1049 | 1048 | smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ENC, TRUE); |
1050 | 1049 | |
1051 | - STREAM_TO_UINT16(le_key.ediv, p); | |
1052 | - STREAM_TO_ARRAY(le_key.rand, p, BT_OCTET8_LEN ); | |
1050 | + STREAM_TO_UINT16(le_key.penc_key.ediv, p); | |
1051 | + STREAM_TO_ARRAY(le_key.penc_key.rand, p, BT_OCTET8_LEN ); | |
1053 | 1052 | |
1054 | 1053 | /* store the encryption keys from peer device */ |
1055 | - memcpy(le_key.ltk, p_cb->ltk, BT_OCTET16_LEN); | |
1056 | - le_key.sec_level = p_cb->sec_level; | |
1057 | - le_key.key_size = p_cb->loc_enc_size; | |
1054 | + memcpy(le_key.penc_key.ltk, p_cb->ltk, BT_OCTET16_LEN); | |
1055 | + le_key.penc_key.sec_level = p_cb->sec_level; | |
1056 | + le_key.penc_key.key_size = p_cb->loc_enc_size; | |
1058 | 1057 | |
1059 | 1058 | if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) |
1060 | - btm_sec_save_le_key(p_cb->pairing_bda, | |
1061 | - BTM_LE_KEY_PENC, | |
1062 | - (tBTM_LE_KEY_VALUE *)&le_key, TRUE); | |
1059 | + btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PENC, &le_key, TRUE); | |
1063 | 1060 | |
1064 | 1061 | smp_key_distribution(p_cb, NULL); |
1065 | 1062 | } |
@@ -1092,24 +1089,23 @@ void smp_proc_id_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) | ||
1092 | 1089 | void smp_proc_id_addr(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) |
1093 | 1090 | { |
1094 | 1091 | UINT8 *p = (UINT8 *)p_data; |
1095 | - tBTM_LE_PID_KEYS pid_key; | |
1092 | + tBTM_LE_KEY_VALUE pid_key; | |
1096 | 1093 | |
1097 | 1094 | SMP_TRACE_DEBUG("%s", __func__); |
1098 | 1095 | smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ID, TRUE); |
1099 | 1096 | |
1100 | - STREAM_TO_UINT8(pid_key.addr_type, p); | |
1101 | - STREAM_TO_BDADDR(pid_key.static_addr, p); | |
1102 | - memcpy(pid_key.irk, p_cb->tk, BT_OCTET16_LEN); | |
1097 | + STREAM_TO_UINT8(pid_key.pid_key.addr_type, p); | |
1098 | + STREAM_TO_BDADDR(pid_key.pid_key.static_addr, p); | |
1099 | + memcpy(pid_key.pid_key.irk, p_cb->tk, BT_OCTET16_LEN); | |
1103 | 1100 | |
1104 | 1101 | /* to use as BD_ADDR for lk derived from ltk */ |
1105 | 1102 | p_cb->id_addr_rcvd = TRUE; |
1106 | - p_cb->id_addr_type = pid_key.addr_type; | |
1107 | - memcpy(p_cb->id_addr, pid_key.static_addr, BD_ADDR_LEN); | |
1103 | + p_cb->id_addr_type = pid_key.pid_key.addr_type; | |
1104 | + memcpy(p_cb->id_addr, pid_key.pid_key.static_addr, BD_ADDR_LEN); | |
1108 | 1105 | |
1109 | 1106 | /* store the ID key from peer device */ |
1110 | 1107 | if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) |
1111 | - btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PID, | |
1112 | - (tBTM_LE_KEY_VALUE *)&pid_key, TRUE); | |
1108 | + btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PID, &pid_key, TRUE); | |
1113 | 1109 | smp_key_distribution_by_transport(p_cb, NULL); |
1114 | 1110 | } |
1115 | 1111 |
@@ -1119,20 +1115,18 @@ void smp_proc_id_addr(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) | ||
1119 | 1115 | *******************************************************************************/ |
1120 | 1116 | void smp_proc_srk_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) |
1121 | 1117 | { |
1122 | - tBTM_LE_PCSRK_KEYS le_key; | |
1118 | + tBTM_LE_KEY_VALUE le_key; | |
1123 | 1119 | |
1124 | 1120 | SMP_TRACE_DEBUG("%s", __func__); |
1125 | 1121 | smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_CSRK, TRUE); |
1126 | 1122 | |
1127 | 1123 | /* save CSRK to security record */ |
1128 | - le_key.sec_level = p_cb->sec_level; | |
1129 | - memcpy (le_key.csrk, p_data, BT_OCTET16_LEN); /* get peer CSRK */ | |
1130 | - le_key.counter = 0; /* initialize the peer counter */ | |
1124 | + le_key.pcsrk_key.sec_level = p_cb->sec_level; | |
1125 | + memcpy (le_key.pcsrk_key.csrk, p_data, BT_OCTET16_LEN); /* get peer CSRK */ | |
1126 | + le_key.pcsrk_key.counter = 0; /* initialize the peer counter */ | |
1131 | 1127 | |
1132 | 1128 | if ((p_cb->peer_auth_req & SMP_AUTH_BOND) && (p_cb->loc_auth_req & SMP_AUTH_BOND)) |
1133 | - btm_sec_save_le_key(p_cb->pairing_bda, | |
1134 | - BTM_LE_KEY_PCSRK, | |
1135 | - (tBTM_LE_KEY_VALUE *)&le_key, TRUE); | |
1129 | + btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PCSRK, &le_key, TRUE); | |
1136 | 1130 | smp_key_distribution_by_transport(p_cb, NULL); |
1137 | 1131 | } |
1138 | 1132 |
@@ -1459,23 +1459,23 @@ BOOLEAN smp_check_commitment(tSMP_CB *p_cb) | ||
1459 | 1459 | *******************************************************************************/ |
1460 | 1460 | void smp_save_secure_connections_long_term_key(tSMP_CB *p_cb) |
1461 | 1461 | { |
1462 | - tBTM_LE_LENC_KEYS lle_key; | |
1463 | - tBTM_LE_PENC_KEYS ple_key; | |
1462 | + tBTM_LE_KEY_VALUE lle_key; | |
1463 | + tBTM_LE_KEY_VALUE ple_key; | |
1464 | 1464 | |
1465 | 1465 | SMP_TRACE_DEBUG("%s-Save LTK as local LTK key", __func__); |
1466 | - memcpy(lle_key.ltk, p_cb->ltk, BT_OCTET16_LEN); | |
1467 | - lle_key.div = 0; | |
1468 | - lle_key.key_size = p_cb->loc_enc_size; | |
1469 | - lle_key.sec_level = p_cb->sec_level; | |
1470 | - btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LENC, (tBTM_LE_KEY_VALUE *)&lle_key, TRUE); | |
1466 | + memcpy(lle_key.lenc_key.ltk, p_cb->ltk, BT_OCTET16_LEN); | |
1467 | + lle_key.lenc_key.div = 0; | |
1468 | + lle_key.lenc_key.key_size = p_cb->loc_enc_size; | |
1469 | + lle_key.lenc_key.sec_level = p_cb->sec_level; | |
1470 | + btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_LENC, &lle_key, TRUE); | |
1471 | 1471 | |
1472 | 1472 | SMP_TRACE_DEBUG("%s-Save LTK as peer LTK key", __func__); |
1473 | - ple_key.ediv = 0; | |
1474 | - memset(ple_key.rand, 0, BT_OCTET8_LEN); | |
1475 | - memcpy(ple_key.ltk, p_cb->ltk, BT_OCTET16_LEN); | |
1476 | - ple_key.sec_level = p_cb->sec_level; | |
1477 | - ple_key.key_size = p_cb->loc_enc_size; | |
1478 | - btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PENC, (tBTM_LE_KEY_VALUE *)&ple_key, TRUE); | |
1473 | + ple_key.penc_key.ediv = 0; | |
1474 | + memset(ple_key.penc_key.rand, 0, BT_OCTET8_LEN); | |
1475 | + memcpy(ple_key.penc_key.ltk, p_cb->ltk, BT_OCTET16_LEN); | |
1476 | + ple_key.penc_key.sec_level = p_cb->sec_level; | |
1477 | + ple_key.penc_key.key_size = p_cb->loc_enc_size; | |
1478 | + btm_sec_save_le_key(p_cb->pairing_bda, BTM_LE_KEY_PENC, &ple_key, TRUE); | |
1479 | 1479 | } |
1480 | 1480 | |
1481 | 1481 | /******************************************************************************* |