Android-x86
Fork
Faire un don

  • R/O
  • HTTP
  • SSH
  • HTTPS

system-bt: Commit

system/bt


Commit MetaInfo

Révision1d788d25a8e1632eee1bfdb2b7c42176ad24b43a (tree)
l'heure2019-12-17 05:40:06
AuteurTed Wang <tedwang@goog...>
CommiterManjae Park

Message de Log

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
(cherry picked from commit 140d8297ace9cd54a903a9cd3a079fd805030f1e)

Change Summary

Modification

--- a/stack/btm/btm_acl.cc
+++ b/stack/btm/btm_acl.cc
@@ -1082,7 +1082,7 @@ void btm_read_remote_features_complete(uint8_t* p) {
10821082 * Returns void
10831083 *
10841084 ******************************************************************************/
1085-void btm_read_remote_ext_features_complete(uint8_t* p) {
1085+void btm_read_remote_ext_features_complete(uint8_t* p, uint8_t evt_len) {
10861086 tACL_CONN* p_acl_cb;
10871087 uint8_t page_num, max_page;
10881088 uint16_t handle;
@@ -1090,6 +1090,14 @@ void btm_read_remote_ext_features_complete(uint8_t* p) {
10901090
10911091 BTM_TRACE_DEBUG("btm_read_remote_ext_features_complete");
10921092
1093+ if (evt_len < HCI_EXT_FEATURES_SUCCESS_EVT_LEN) {
1094+ android_errorWriteLog(0x534e4554, "141552859");
1095+ BTM_TRACE_ERROR(
1096+ "btm_read_remote_ext_features_complete evt length too short. length=%d",
1097+ evt_len);
1098+ return;
1099+ }
1100+
10931101 ++p;
10941102 STREAM_TO_UINT16(handle, p);
10951103 STREAM_TO_UINT8(page_num, p);
@@ -1109,6 +1117,19 @@ void btm_read_remote_ext_features_complete(uint8_t* p) {
11091117 return;
11101118 }
11111119
1120+ if (page_num > HCI_EXT_FEATURES_PAGE_MAX) {
1121+ android_errorWriteLog(0x534e4554, "141552859");
1122+ BTM_TRACE_ERROR("btm_read_remote_ext_features_complete num_page=%d invalid",
1123+ page_num);
1124+ return;
1125+ }
1126+
1127+ if (page_num > max_page) {
1128+ BTM_TRACE_WARNING(
1129+ "btm_read_remote_ext_features_complete num_page=%d, max_page=%d "
1130+ "invalid", page_num, max_page);
1131+ }
1132+
11121133 p_acl_cb = &btm_cb.acl_db[acl_idx];
11131134
11141135 /* Copy the received features page */
--- a/stack/btm/btm_int.h
+++ b/stack/btm/btm_int.h
@@ -118,7 +118,7 @@ extern uint16_t btm_get_acl_disc_reason_code(void);
118118 extern tBTM_STATUS btm_remove_acl(const RawAddress& bd_addr,
119119 tBT_TRANSPORT transport);
120120 extern void btm_read_remote_features_complete(uint8_t* p);
121-extern void btm_read_remote_ext_features_complete(uint8_t* p);
121+extern void btm_read_remote_ext_features_complete(uint8_t* p, uint8_t evt_len);
122122 extern void btm_read_remote_ext_features_failed(uint8_t status,
123123 uint16_t handle);
124124 extern void btm_read_remote_version_complete(uint8_t* p);
--- a/stack/btu/btu_hcif.cc
+++ b/stack/btu/btu_hcif.cc
@@ -71,7 +71,8 @@ static void btu_hcif_authentication_comp_evt(uint8_t* p);
7171 static void btu_hcif_rmt_name_request_comp_evt(uint8_t* p, uint16_t evt_len);
7272 static void btu_hcif_encryption_change_evt(uint8_t* p);
7373 static void btu_hcif_read_rmt_features_comp_evt(uint8_t* p);
74-static void btu_hcif_read_rmt_ext_features_comp_evt(uint8_t* p);
74+static void btu_hcif_read_rmt_ext_features_comp_evt(uint8_t* p,
75+ uint8_t evt_len);
7576 static void btu_hcif_read_rmt_version_comp_evt(uint8_t* p);
7677 static void btu_hcif_qos_setup_comp_evt(uint8_t* p);
7778 static void btu_hcif_command_complete_evt(BT_HDR* response, void* context);
@@ -195,7 +196,7 @@ void btu_hcif_process_event(UNUSED_ATTR uint8_t controller_id, BT_HDR* p_msg) {
195196 btu_hcif_read_rmt_features_comp_evt(p);
196197 break;
197198 case HCI_READ_RMT_EXT_FEATURES_COMP_EVT:
198- btu_hcif_read_rmt_ext_features_comp_evt(p);
199+ btu_hcif_read_rmt_ext_features_comp_evt(p, hci_evt_len);
199200 break;
200201 case HCI_READ_RMT_VERSION_COMP_EVT:
201202 btu_hcif_read_rmt_version_comp_evt(p);
@@ -812,7 +813,8 @@ static void btu_hcif_read_rmt_features_comp_evt(uint8_t* p) {
812813 * Returns void
813814 *
814815 ******************************************************************************/
815-static void btu_hcif_read_rmt_ext_features_comp_evt(uint8_t* p) {
816+static void btu_hcif_read_rmt_ext_features_comp_evt(uint8_t* p,
817+ uint8_t evt_len) {
816818 uint8_t* p_cur = p;
817819 uint8_t status;
818820 uint16_t handle;
@@ -820,7 +822,7 @@ static void btu_hcif_read_rmt_ext_features_comp_evt(uint8_t* p) {
820822 STREAM_TO_UINT8(status, p_cur);
821823
822824 if (status == HCI_SUCCESS)
823- btm_read_remote_ext_features_complete(p);
825+ btm_read_remote_ext_features_complete(p, evt_len);
824826 else {
825827 STREAM_TO_UINT16(handle, p_cur);
826828 btm_read_remote_ext_features_failed(status, handle);
--- a/stack/include/hcidefs.h
+++ b/stack/include/hcidefs.h
@@ -1322,6 +1322,8 @@ typedef struct {
13221322
13231323 #define HCI_FEATURE_BYTES_PER_PAGE 8
13241324
1325+#define HCI_EXT_FEATURES_SUCCESS_EVT_LEN 13
1326+
13251327 #define HCI_FEATURES_KNOWN(x) \
13261328 (((x)[0] | (x)[1] | (x)[2] | (x)[3] | (x)[4] | (x)[5] | (x)[6] | (x)[7]) != 0)
13271329
Afficher sur ancien navigateur de dépôt.