Skip to content

Commit 6bbd0d3

Browse files
Pavel ShpakovskiyVudentz
authored andcommitted
Bluetooth: hci_sync: fix set_local_name race condition
Function set_name_sync() uses hdev->dev_name field to send HCI_OP_WRITE_LOCAL_NAME command, but copying from data to hdev->dev_name is called after mgmt cmd was queued, so it is possible that function set_name_sync() will read old name value. This change adds name as a parameter for function hci_update_name_sync() to avoid race condition. Fixes: 6f6ff38 ("Bluetooth: hci_sync: Convert MGMT_OP_SET_LOCAL_NAME") Signed-off-by: Pavel Shpakovskiy <[email protected]> Reviewed-by: Paul Menzel <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 55b9551 commit 6bbd0d3

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

include/net/bluetooth/hci_sync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ int hci_update_class_sync(struct hci_dev *hdev);
9393

9494
int hci_update_eir_sync(struct hci_dev *hdev);
9595
int hci_update_class_sync(struct hci_dev *hdev);
96-
int hci_update_name_sync(struct hci_dev *hdev);
96+
int hci_update_name_sync(struct hci_dev *hdev, const u8 *name);
9797
int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode);
9898

9999
int hci_get_random_address(struct hci_dev *hdev, bool require_privacy,

net/bluetooth/hci_sync.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3481,13 +3481,13 @@ int hci_update_scan_sync(struct hci_dev *hdev)
34813481
return hci_write_scan_enable_sync(hdev, scan);
34823482
}
34833483

3484-
int hci_update_name_sync(struct hci_dev *hdev)
3484+
int hci_update_name_sync(struct hci_dev *hdev, const u8 *name)
34853485
{
34863486
struct hci_cp_write_local_name cp;
34873487

34883488
memset(&cp, 0, sizeof(cp));
34893489

3490-
memcpy(cp.name, hdev->dev_name, sizeof(cp.name));
3490+
memcpy(cp.name, name, sizeof(cp.name));
34913491

34923492
return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LOCAL_NAME,
34933493
sizeof(cp), &cp,
@@ -3540,7 +3540,7 @@ int hci_powered_update_sync(struct hci_dev *hdev)
35403540
hci_write_fast_connectable_sync(hdev, false);
35413541
hci_update_scan_sync(hdev);
35423542
hci_update_class_sync(hdev);
3543-
hci_update_name_sync(hdev);
3543+
hci_update_name_sync(hdev, hdev->dev_name);
35443544
hci_update_eir_sync(hdev);
35453545
}
35463546

net/bluetooth/mgmt.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3892,8 +3892,11 @@ static void set_name_complete(struct hci_dev *hdev, void *data, int err)
38923892

38933893
static int set_name_sync(struct hci_dev *hdev, void *data)
38943894
{
3895+
struct mgmt_pending_cmd *cmd = data;
3896+
struct mgmt_cp_set_local_name *cp = cmd->param;
3897+
38953898
if (lmp_bredr_capable(hdev)) {
3896-
hci_update_name_sync(hdev);
3899+
hci_update_name_sync(hdev, cp->name);
38973900
hci_update_eir_sync(hdev);
38983901
}
38993902

0 commit comments

Comments
 (0)