Skip to content

Commit 59437cb

Browse files
committed
Bluetooth: hci_core: Fix not checking skb length on hci_scodata_packet
This fixes not checking if skb really contains an SCO header otherwise the code may attempt to access some uninitilized/invalid memory past the valid skb->data. Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 3fe288a commit 59437cb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

net/bluetooth/hci_core.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3814,18 +3814,22 @@ static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb)
38143814
/* SCO data packet */
38153815
static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb)
38163816
{
3817-
struct hci_sco_hdr *hdr = (void *) skb->data;
3817+
struct hci_sco_hdr *hdr;
38183818
struct hci_conn *conn;
38193819
__u16 handle, flags;
38203820

3821-
skb_pull(skb, HCI_SCO_HDR_SIZE);
3821+
hdr = skb_pull_data(skb, sizeof(*hdr));
3822+
if (!hdr) {
3823+
bt_dev_err(hdev, "SCO packet too small");
3824+
goto drop;
3825+
}
38223826

38233827
handle = __le16_to_cpu(hdr->handle);
38243828
flags = hci_flags(handle);
38253829
handle = hci_handle(handle);
38263830

3827-
BT_DBG("%s len %d handle 0x%4.4x flags 0x%4.4x", hdev->name, skb->len,
3828-
handle, flags);
3831+
bt_dev_dbg(hdev, "len %d handle 0x%4.4x flags 0x%4.4x", skb->len,
3832+
handle, flags);
38293833

38303834
hdev->stat.sco_rx++;
38313835

@@ -3843,6 +3847,7 @@ static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb)
38433847
handle);
38443848
}
38453849

3850+
drop:
38463851
kfree_skb(skb);
38473852
}
38483853

0 commit comments

Comments
 (0)