• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/bt


Commit MetaInfo

Revisão4a71fca191b41e5931b35e1b9c3a4b74ab170322 (tree)
Hora2018-12-06 17:19:33
AutorJakub Pawlowski <jpawlowski@goog...>
CommiterJP Sugarbroad

Mensagem de Log

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)

Mudança Sumário

Diff

--- a/stack/smp/smp_act.c
+++ b/stack/smp/smp_act.c
@@ -398,7 +398,7 @@ void smp_send_keypress_notification(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
398398 *******************************************************************************/
399399 void smp_send_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
400400 {
401- tBTM_LE_LENC_KEYS le_key;
401+ tBTM_LE_KEY_VALUE key;
402402
403403 SMP_TRACE_DEBUG("%s p_cb->loc_enc_size = %d", __func__, p_cb->loc_enc_size);
404404 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)
407407 smp_send_cmd(SMP_OPCODE_MASTER_ID, p_cb);
408408
409409 /* 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;
414414
415415 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);
418417
419418 SMP_TRACE_WARNING ("%s", __func__);
420419
@@ -448,17 +447,17 @@ void smp_send_id_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
448447 *******************************************************************************/
449448 void smp_send_csrk_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
450449 {
451- tBTM_LE_LCSRK_KEYS key;
450+ tBTM_LE_KEY_VALUE key;
452451 SMP_TRACE_DEBUG("%s", __func__);
453452 smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_CSRK, FALSE);
454453
455454 if (smp_send_cmd(SMP_OPCODE_SIGN_INFO, p_cb))
456455 {
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);
462461 }
463462
464463 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)
10351034 void smp_proc_master_id(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
10361035 {
10371036 UINT8 *p = (UINT8 *)p_data;
1038- tBTM_LE_PENC_KEYS le_key;
1037+ tBTM_LE_KEY_VALUE le_key;
10391038
10401039 SMP_TRACE_DEBUG("%s", __func__);
10411040
@@ -1048,18 +1047,16 @@ void smp_proc_master_id(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
10481047
10491048 smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ENC, TRUE);
10501049
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 );
10531052
10541053 /* 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;
10581057
10591058 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);
10631060
10641061 smp_key_distribution(p_cb, NULL);
10651062 }
@@ -1092,24 +1089,23 @@ void smp_proc_id_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
10921089 void smp_proc_id_addr(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
10931090 {
10941091 UINT8 *p = (UINT8 *)p_data;
1095- tBTM_LE_PID_KEYS pid_key;
1092+ tBTM_LE_KEY_VALUE pid_key;
10961093
10971094 SMP_TRACE_DEBUG("%s", __func__);
10981095 smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ID, TRUE);
10991096
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);
11031100
11041101 /* to use as BD_ADDR for lk derived from ltk */
11051102 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);
11081105
11091106 /* store the ID key from peer device */
11101107 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);
11131109 smp_key_distribution_by_transport(p_cb, NULL);
11141110 }
11151111
@@ -1119,20 +1115,18 @@ void smp_proc_id_addr(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
11191115 *******************************************************************************/
11201116 void smp_proc_srk_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
11211117 {
1122- tBTM_LE_PCSRK_KEYS le_key;
1118+ tBTM_LE_KEY_VALUE le_key;
11231119
11241120 SMP_TRACE_DEBUG("%s", __func__);
11251121 smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_CSRK, TRUE);
11261122
11271123 /* 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 */
11311127
11321128 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);
11361130 smp_key_distribution_by_transport(p_cb, NULL);
11371131 }
11381132
--- a/stack/smp/smp_utils.c
+++ b/stack/smp/smp_utils.c
@@ -1459,23 +1459,23 @@ BOOLEAN smp_check_commitment(tSMP_CB *p_cb)
14591459 *******************************************************************************/
14601460 void smp_save_secure_connections_long_term_key(tSMP_CB *p_cb)
14611461 {
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;
14641464
14651465 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);
14711471
14721472 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);
14791479 }
14801480
14811481 /*******************************************************************************