Skip to content

Commit 2244a2d

Browse files
committed
Bluetooth: hci_sync: fix set_local_name race condition
jira KERNEL-228 cve CVE-2025-39981 Rebuild_History Non-Buildable kernel-5.14.0-611.11.1.el9_7 commit-author Pavel Shpakovskiy <pashpakovskii@salutedevices.com> commit 6bbd0d3 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 <pashpakovskii@salutedevices.com> Reviewed-by: Paul Menzel <pmenzel@molgen.mpg.de> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com> (cherry picked from commit 6bbd0d3) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent e212a12 commit 2244a2d

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
@@ -3412,13 +3412,13 @@ int hci_update_scan_sync(struct hci_dev *hdev)
34123412
return hci_write_scan_enable_sync(hdev, scan);
34133413
}
34143414

3415-
int hci_update_name_sync(struct hci_dev *hdev)
3415+
int hci_update_name_sync(struct hci_dev *hdev, const u8 *name)
34163416
{
34173417
struct hci_cp_write_local_name cp;
34183418

34193419
memset(&cp, 0, sizeof(cp));
34203420

3421-
memcpy(cp.name, hdev->dev_name, sizeof(cp.name));
3421+
memcpy(cp.name, name, sizeof(cp.name));
34223422

34233423
return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LOCAL_NAME,
34243424
sizeof(cp), &cp,
@@ -3471,7 +3471,7 @@ int hci_powered_update_sync(struct hci_dev *hdev)
34713471
hci_write_fast_connectable_sync(hdev, false);
34723472
hci_update_scan_sync(hdev);
34733473
hci_update_class_sync(hdev);
3474-
hci_update_name_sync(hdev);
3474+
hci_update_name_sync(hdev, hdev->dev_name);
34753475
hci_update_eir_sync(hdev);
34763476
}
34773477

net/bluetooth/mgmt.c

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

38913891
static int set_name_sync(struct hci_dev *hdev, void *data)
38923892
{
3893+
struct mgmt_pending_cmd *cmd = data;
3894+
struct mgmt_cp_set_local_name *cp = cmd->param;
3895+
38933896
if (lmp_bredr_capable(hdev)) {
3894-
hci_update_name_sync(hdev);
3897+
hci_update_name_sync(hdev, cp->name);
38953898
hci_update_eir_sync(hdev);
38963899
}
38973900

0 commit comments

Comments
 (0)