This uses skb_pull_data to check the Inquiry Result with RSSI events received have the minimum required length.
Unified · Split
| @@ -2194,7 +2194,7 @@ struct hci_ev_pscan_rep_mode { · 2193 unmodified lines | ||
| 2194 | 2194 | } __packed; |
| 2195 | 2195 | |
| 2196 | 2196 | #define HCI_EV_INQUIRY_RESULT_WITH_RSSI 0x22 |
| 2197 | −struct inquiry_info_with_rssi { | |
| 2197 | +struct inquiry_info_rssi { | |
| 2198 | 2198 | bdaddr_t bdaddr; |
| 2199 | 2199 | __u8 pscan_rep_mode; |
| 2200 | 2200 | __u8 pscan_period_mode; |
| @@ -2202,7 +2202,7 @@ struct inquiry_info_with_rssi { · 1 unmodified line | ||
| 2202 | 2202 | __le16 clock_offset; |
| 2203 | 2203 | __s8 rssi; |
| 2204 | 2204 | } __packed; |
| 2205 | −struct inquiry_info_with_rssi_and_pscan_mode { | |
| 2205 | +struct inquiry_info_rssi_pscan { | |
| 2206 | 2206 | bdaddr_t bdaddr; |
| 2207 | 2207 | __u8 pscan_rep_mode; |
| 2208 | 2208 | __u8 pscan_period_mode; |
| @@ -2211,6 +2211,14 @@ struct inquiry_info_with_rssi_and_pscan_mode { · 2 unmodified lines | ||
| 2211 | 2211 | __le16 clock_offset; |
| 2212 | 2212 | __s8 rssi; |
| 2213 | 2213 | } __packed; |
| 2214 | +struct hci_ev_inquiry_result_rssi { | |
| 2215 | + __u8 num; | |
| 2216 | + struct inquiry_info_rssi info[]; | |
| 2217 | +} __packed; | |
| 2218 | +struct hci_ev_inquiry_result_rssi_pscan { | |
| 2219 | + __u8 num; | |
| 2220 | + struct inquiry_info_rssi_pscan info[]; | |
| 2221 | +} __packed; | |
| 2214 | 2222 | |
| 2215 | 2223 | #define HCI_EV_REMOTE_EXT_FEATURES 0x23 |
| 2216 | 2224 | struct hci_ev_remote_ext_features { |
| @@ -4921,12 +4921,21 @@ static void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *skb) · 4920 unmodified lines | ||
| 4921 | 4921 | static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, |
| 4922 | 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 | 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 | 4939 | return; |
| 4931 | 4940 | |
| 4932 | 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 | 4944 | hci_dev_lock(hdev); |
| 4936 | 4945 | |
| 4937 | − if ((skb->len - 1) / num_rsp != sizeof(struct inquiry_info_with_rssi)) { | |
| 4938 | − struct inquiry_info_with_rssi_and_pscan_mode *info; | |
| 4939 | − info = (void *) (skb->data + 1); | |
| 4946 | + if (skb->len == flex_array_size(ev, res2->info, ev->res2->num)) { | |
| 4947 | + struct inquiry_info_rssi_pscan *info; | |
| 4940 | 4948 | |
| 4941 | − if (skb->len < num_rsp * sizeof(*info) + 1) | |
| 4942 | − goto unlock; | |
| 4943 | − | |
| 4944 | − for (; num_rsp; num_rsp--, info++) { | |
| 4949 | + for (i = 0; i < ev->res2->num; i++) { | |
| 4945 | 4950 | u32 flags; |
| 4946 | 4951 | |
| 4952 | + info = &ev->res2->info[i]; | |
| 4947 | 4953 | bacpy(&data.bdaddr, &info->bdaddr); |
| 4948 | 4954 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 4949 | 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 | 4965 | info->dev_class, info->rssi, |
| 4960 | 4966 | flags, NULL, 0, NULL, 0); |
| 4961 | 4967 | } |
| 4962 | − } else { | |
| 4963 | − struct inquiry_info_with_rssi *info = (void *) (skb->data + 1); | |
| 4968 | + } else if (skb->len == flex_array_size(ev, res1->info, ev->res1->num)) { | |
| 4969 | + struct inquiry_info_rssi *info; | |
| 4964 | 4970 | |
| 4965 | − if (skb->len < num_rsp * sizeof(*info) + 1) | |
| 4966 | − goto unlock; | |
| 4967 | − | |
| 4968 | − for (; num_rsp; num_rsp--, info++) { | |
| 4971 | + for (i = 0; i < ev->res1->num; i++) { | |
| 4969 | 4972 | u32 flags; |
| 4970 | 4973 | |
| 4974 | + info = &ev->res1->info[i]; | |
| 4971 | 4975 | bacpy(&data.bdaddr, &info->bdaddr); |
| 4972 | 4976 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 4973 | 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 | 4987 | info->dev_class, info->rssi, |
| 4984 | 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 | |
| 4988 | −unlock: | |
| 4989 | 4995 | hci_dev_unlock(hdev); |
| 4990 | 4996 | } |
| 4991 | 4997 | |