History

Bluetooth: HCI: Use skb_pull_data to parse Inquiry Result with RSSI event

This uses skb_pull_data to check the Inquiry Result with RSSI events received have the minimum required length.

Luiz Augusto von Dentz committed 4 years ago

Commit 8d08d321 parent 27d9eb42 files · +33 −19Browse files

Unified · Split

2 files
  1. include/net/bluetooth/hci.h +10 −2
  2. net/bluetooth/hci_event.c +23 −17
include/net/bluetooth/hci.h+10−2
@@ -2194,7 +2194,7 @@ struct hci_ev_pscan_rep_mode { · 2193 unmodified lines
2194} __packed;2194} __packed;
2195 2195
2196#define HCI_EV_INQUIRY_RESULT_WITH_RSSI 0x222196#define HCI_EV_INQUIRY_RESULT_WITH_RSSI 0x22
2197struct inquiry_info_with_rssi {2197struct inquiry_info_rssi {
2198 bdaddr_t bdaddr;2198 bdaddr_t bdaddr;
2199 __u8 pscan_rep_mode;2199 __u8 pscan_rep_mode;
2200 __u8 pscan_period_mode;2200 __u8 pscan_period_mode;
@@ -2202,7 +2202,7 @@ struct inquiry_info_with_rssi { · 1 unmodified line
2202 __le16 clock_offset;2202 __le16 clock_offset;
2203 __s8 rssi;2203 __s8 rssi;
2204} __packed;2204} __packed;
2205struct inquiry_info_with_rssi_and_pscan_mode {2205struct inquiry_info_rssi_pscan {
2206 bdaddr_t bdaddr;2206 bdaddr_t bdaddr;
2207 __u8 pscan_rep_mode;2207 __u8 pscan_rep_mode;
2208 __u8 pscan_period_mode;2208 __u8 pscan_period_mode;
@@ -2211,6 +2211,14 @@ struct inquiry_info_with_rssi_and_pscan_mode { · 2 unmodified lines
2211 __le16 clock_offset;2211 __le16 clock_offset;
2212 __s8 rssi;2212 __s8 rssi;
2213} __packed;2213} __packed;
2214struct hci_ev_inquiry_result_rssi {
2215 __u8 num;
2216 struct inquiry_info_rssi info[];
2217} __packed;
2218struct hci_ev_inquiry_result_rssi_pscan {
2219 __u8 num;
2220 struct inquiry_info_rssi_pscan info[];
2221} __packed;
2214 2222
2215#define HCI_EV_REMOTE_EXT_FEATURES 0x232223#define HCI_EV_REMOTE_EXT_FEATURES 0x23
2216struct hci_ev_remote_ext_features {2224struct hci_ev_remote_ext_features {
net/bluetooth/hci_event.c+23−17
@@ -4921,12 +4921,21 @@ static void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *skb) · 4920 unmodified lines
4921static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev,4921static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev,
4922 struct sk_buff *skb)4922 struct sk_buff *skb)
4923{4923{
4924 union {
4925 struct hci_ev_inquiry_result_rssi *res1;
4926 struct hci_ev_inquiry_result_rssi_pscan *res2;
4927 } *ev;
4924 struct inquiry_data data;4928 struct inquiry_data data;
4925 int num_rsp = *((__u8 *) skb->data);4929 int i;
4926 4930
4927 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);4931 ev = hci_ev_skb_pull(hdev, skb, HCI_EV_INQUIRY_RESULT_WITH_RSSI,
4932 sizeof(*ev));
4933 if (!ev)
4934 return;
4935
4936 BT_DBG("%s num_rsp %d", hdev->name, ev->res1->num);
4928 4937
4929 if (!num_rsp)4938 if (!ev->res1->num)
4930 return;4939 return;
4931 4940
4932 if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ))4941 if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ))
@@ -4934,16 +4943,13 @@ static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, · 1 unmodified line
4934 4943
4935 hci_dev_lock(hdev);4944 hci_dev_lock(hdev);
4936 4945
4937 if ((skb->len - 1) / num_rsp != sizeof(struct inquiry_info_with_rssi)) {4946 if (skb->len == flex_array_size(ev, res2->info, ev->res2->num)) {
4938 struct inquiry_info_with_rssi_and_pscan_mode *info;4947 struct inquiry_info_rssi_pscan *info;
4939 info = (void *) (skb->data + 1);
4940 4948
4941 if (skb->len < num_rsp * sizeof(*info) + 1)4949 for (i = 0; i < ev->res2->num; i++) {
4942 goto unlock;
4943
4944 for (; num_rsp; num_rsp--, info++) {
4945 u32 flags;4950 u32 flags;
4946 4951
4952 info = &ev->res2->info[i];
4947 bacpy(&data.bdaddr, &info->bdaddr);4953 bacpy(&data.bdaddr, &info->bdaddr);
4948 data.pscan_rep_mode = info->pscan_rep_mode;4954 data.pscan_rep_mode = info->pscan_rep_mode;
4949 data.pscan_period_mode = info->pscan_period_mode;4955 data.pscan_period_mode = info->pscan_period_mode;
@@ -4959,15 +4965,13 @@ static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, · 9 unmodified lines
4959 info->dev_class, info->rssi,4965 info->dev_class, info->rssi,
4960 flags, NULL, 0, NULL, 0);4966 flags, NULL, 0, NULL, 0);
4961 }4967 }
4962 } else {4968 } else if (skb->len == flex_array_size(ev, res1->info, ev->res1->num)) {
4963 struct inquiry_info_with_rssi *info = (void *) (skb->data + 1);4969 struct inquiry_info_rssi *info;
4964 4970
4965 if (skb->len < num_rsp * sizeof(*info) + 1)4971 for (i = 0; i < ev->res1->num; i++) {
4966 goto unlock;
4967
4968 for (; num_rsp; num_rsp--, info++) {
4969 u32 flags;4972 u32 flags;
4970 4973
4974 info = &ev->res1->info[i];
4971 bacpy(&data.bdaddr, &info->bdaddr);4975 bacpy(&data.bdaddr, &info->bdaddr);
4972 data.pscan_rep_mode = info->pscan_rep_mode;4976 data.pscan_rep_mode = info->pscan_rep_mode;
4973 data.pscan_period_mode = info->pscan_period_mode;4977 data.pscan_period_mode = info->pscan_period_mode;
@@ -4983,9 +4987,11 @@ static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, · 9 unmodified lines
4983 info->dev_class, info->rssi,4987 info->dev_class, info->rssi,
4984 flags, NULL, 0, NULL, 0);4988 flags, NULL, 0, NULL, 0);
4985 }4989 }
4990 } else {
4991 bt_dev_err(hdev, "Malformed HCI Event: 0x%2.2x",
4992 HCI_EV_INQUIRY_RESULT_WITH_RSSI);
4986 }4993 }
4987 4994
4988unlock:
4989 hci_dev_unlock(hdev);4995 hci_dev_unlock(hdev);
4990}4996}
4991 4997

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t