• 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

Revisiónb4e8a17daa72b241ae4ec746536dd489e9ade508 (tree)
Tiempo2019-11-26 16:04:41
AutorTed Wang <tedwang@goog...>
CommiterTed Wang

Log Message

Fix potential OOB write in btm_read_remote_ext_features_complete

Add event length check to avoid hci event sent from controller not
correct.
Add page number check to avoid page number is bigger than
HCI_EXT_FEATURES_PAGE_MAX.

Bug: 141552859
Bug: 144205318
Test: inject function
Merged-In: Iaca4db4ee9bf27362f62aba0da088727e98955d1
Change-Id: Iaca4db4ee9bf27362f62aba0da088727e98955d1

Cambiar Resumen

Diferencia incremental

--- a/stack/btm/btm_acl.cc
+++ b/stack/btm/btm_acl.cc
@@ -46,6 +46,7 @@
4646 #include "device/include/controller.h"
4747 #include "hcidefs.h"
4848 #include "hcimsgs.h"
49+#include "log/log.h"
4950 #include "l2c_int.h"
5051 #include "osi/include/osi.h"
5152
@@ -1062,7 +1063,7 @@ void btm_read_remote_features_complete(uint8_t* p) {
10621063 * Returns void
10631064 *
10641065 ******************************************************************************/
1065-void btm_read_remote_ext_features_complete(uint8_t* p) {
1066+void btm_read_remote_ext_features_complete(uint8_t* p, uint8_t evt_len) {
10661067 tACL_CONN* p_acl_cb;
10671068 uint8_t page_num, max_page;
10681069 uint16_t handle;
@@ -1070,6 +1071,14 @@ void btm_read_remote_ext_features_complete(uint8_t* p) {
10701071
10711072 BTM_TRACE_DEBUG("btm_read_remote_ext_features_complete");
10721073
1074+ if (evt_len < HCI_EXT_FEATURES_SUCCESS_EVT_LEN) {
1075+ android_errorWriteLog(0x534e4554, "141552859");
1076+ BTM_TRACE_ERROR(
1077+ "btm_read_remote_ext_features_complete evt length too short. length=%d",
1078+ evt_len);
1079+ return;
1080+ }
1081+
10731082 ++p;
10741083 STREAM_TO_UINT16(handle, p);
10751084 STREAM_TO_UINT8(page_num, p);
@@ -1089,6 +1098,19 @@ void btm_read_remote_ext_features_complete(uint8_t* p) {
10891098 return;
10901099 }
10911100
1101+ if (page_num > HCI_EXT_FEATURES_PAGE_MAX) {
1102+ android_errorWriteLog(0x534e4554, "141552859");
1103+ BTM_TRACE_ERROR("btm_read_remote_ext_features_complete num_page=%d invalid",
1104+ page_num);
1105+ return;
1106+ }
1107+
1108+ if (page_num > max_page) {
1109+ BTM_TRACE_WARNING(
1110+ "btm_read_remote_ext_features_complete num_page=%d, max_page=%d "
1111+ "invalid", page_num, max_page);
1112+ }
1113+
10921114 p_acl_cb = &btm_cb.acl_db[acl_idx];
10931115
10941116 /* Copy the received features page */
--- a/stack/btm/btm_int.h
+++ b/stack/btm/btm_int.h
@@ -110,7 +110,7 @@ extern void btm_acl_encrypt_change(uint16_t handle, uint8_t status,
110110 extern uint16_t btm_get_acl_disc_reason_code(void);
111111 extern tBTM_STATUS btm_remove_acl(BD_ADDR bd_addr, tBT_TRANSPORT transport);
112112 extern void btm_read_remote_features_complete(uint8_t* p);
113-extern void btm_read_remote_ext_features_complete(uint8_t* p);
113+extern void btm_read_remote_ext_features_complete(uint8_t* p, uint8_t evt_len);
114114 extern void btm_read_remote_ext_features_failed(uint8_t status,
115115 uint16_t handle);
116116 extern void btm_read_remote_version_complete(uint8_t* p);
--- a/stack/btu/btu_hcif.cc
+++ b/stack/btu/btu_hcif.cc
@@ -72,7 +72,8 @@ static void btu_hcif_authentication_comp_evt(uint8_t* p);
7272 static void btu_hcif_rmt_name_request_comp_evt(uint8_t* p, uint16_t evt_len);
7373 static void btu_hcif_encryption_change_evt(uint8_t* p);
7474 static void btu_hcif_read_rmt_features_comp_evt(uint8_t* p);
75-static void btu_hcif_read_rmt_ext_features_comp_evt(uint8_t* p);
75+static void btu_hcif_read_rmt_ext_features_comp_evt(uint8_t* p,
76+ uint8_t evt_len);
7677 static void btu_hcif_read_rmt_version_comp_evt(uint8_t* p);
7778 static void btu_hcif_qos_setup_comp_evt(uint8_t* p);
7879 static void btu_hcif_command_complete_evt(BT_HDR* response, void* context);
@@ -184,7 +185,7 @@ void btu_hcif_process_event(UNUSED_ATTR uint8_t controller_id, BT_HDR* p_msg) {
184185 btu_hcif_read_rmt_features_comp_evt(p);
185186 break;
186187 case HCI_READ_RMT_EXT_FEATURES_COMP_EVT:
187- btu_hcif_read_rmt_ext_features_comp_evt(p);
188+ btu_hcif_read_rmt_ext_features_comp_evt(p, hci_evt_len);
188189 break;
189190 case HCI_READ_RMT_VERSION_COMP_EVT:
190191 btu_hcif_read_rmt_version_comp_evt(p);
@@ -800,7 +801,8 @@ static void btu_hcif_read_rmt_features_comp_evt(uint8_t* p) {
800801 * Returns void
801802 *
802803 ******************************************************************************/
803-static void btu_hcif_read_rmt_ext_features_comp_evt(uint8_t* p) {
804+static void btu_hcif_read_rmt_ext_features_comp_evt(uint8_t* p,
805+ uint8_t evt_len) {
804806 uint8_t* p_cur = p;
805807 uint8_t status;
806808 uint16_t handle;
@@ -808,7 +810,7 @@ static void btu_hcif_read_rmt_ext_features_comp_evt(uint8_t* p) {
808810 STREAM_TO_UINT8(status, p_cur);
809811
810812 if (status == HCI_SUCCESS)
811- btm_read_remote_ext_features_complete(p);
813+ btm_read_remote_ext_features_complete(p, evt_len);
812814 else {
813815 STREAM_TO_UINT16(handle, p_cur);
814816 btm_read_remote_ext_features_failed(status, handle);
--- a/stack/include/hcidefs.h
+++ b/stack/include/hcidefs.h
@@ -1567,6 +1567,8 @@ typedef struct {
15671567
15681568 #define HCI_FEATURE_BYTES_PER_PAGE 8
15691569
1570+#define HCI_EXT_FEATURES_SUCCESS_EVT_LEN 13
1571+
15701572 #define HCI_FEATURES_KNOWN(x) \
15711573 (((x)[0] | (x)[1] | (x)[2] | (x)[3] | (x)[4] | (x)[5] | (x)[6] | (x)[7]) != 0)
15721574