Skip to content

Commit 103a2f3

Browse files
Itay IellinVudentz
authored andcommitted
Bluetooth: Fix the creation of hdev->name
Set a size limit of 8 bytes of the written buffer to "hdev->name" including the terminating null byte, as the size of "hdev->name" is 8 bytes. If an id value which is greater than 9999 is allocated, then the "snprintf(hdev->name, sizeof(hdev->name), "hci%d", id)" function call would lead to a truncation of the id value in decimal notation. Set an explicit maximum id parameter in the id allocation function call. The id allocation function defines the maximum allocated id value as the maximum id parameter value minus one. Therefore, HCI_MAX_ID is defined as 10000. Signed-off-by: Itay Iellin <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 3f95a74 commit 103a2f3

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

include/net/bluetooth/hci_core.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
/* HCI priority */
3737
#define HCI_PRIO_MAX 7
3838

39+
/* HCI maximum id value */
40+
#define HCI_MAX_ID 10000
41+
3942
/* HCI Core structures */
4043
struct inquiry_data {
4144
bdaddr_t bdaddr;

net/bluetooth/hci_core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,10 +2555,10 @@ int hci_register_dev(struct hci_dev *hdev)
25552555
*/
25562556
switch (hdev->dev_type) {
25572557
case HCI_PRIMARY:
2558-
id = ida_simple_get(&hci_index_ida, 0, 0, GFP_KERNEL);
2558+
id = ida_simple_get(&hci_index_ida, 0, HCI_MAX_ID, GFP_KERNEL);
25592559
break;
25602560
case HCI_AMP:
2561-
id = ida_simple_get(&hci_index_ida, 1, 0, GFP_KERNEL);
2561+
id = ida_simple_get(&hci_index_ida, 1, HCI_MAX_ID, GFP_KERNEL);
25622562
break;
25632563
default:
25642564
return -EINVAL;
@@ -2567,7 +2567,7 @@ int hci_register_dev(struct hci_dev *hdev)
25672567
if (id < 0)
25682568
return id;
25692569

2570-
sprintf(hdev->name, "hci%d", id);
2570+
snprintf(hdev->name, sizeof(hdev->name), "hci%d", id);
25712571
hdev->id = id;
25722572

25732573
BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);

0 commit comments

Comments
 (0)