]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
Bluetooth: hci_sync: fix set_local_name race condition
authorPavel Shpakovskiy <pashpakovskii@salutedevices.com>
Fri, 22 Aug 2025 09:20:55 +0000 (12:20 +0300)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 22 Aug 2025 17:57:31 +0000 (13:57 -0400)
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: 6f6ff38a1e14 ("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>
include/net/bluetooth/hci_sync.h
net/bluetooth/hci_sync.c
net/bluetooth/mgmt.c

index 5224f57f6af2c410b5ee1c737bb14e279ef4a309..e352a4e0ef8d76ff7b2762e0556c634927c4d58b 100644 (file)
@@ -93,7 +93,7 @@ int hci_update_class_sync(struct hci_dev *hdev);
 
 int hci_update_eir_sync(struct hci_dev *hdev);
 int hci_update_class_sync(struct hci_dev *hdev);
-int hci_update_name_sync(struct hci_dev *hdev);
+int hci_update_name_sync(struct hci_dev *hdev, const u8 *name);
 int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode);
 
 int hci_get_random_address(struct hci_dev *hdev, bool require_privacy,
index 31d72b9683ef52f91d434ad474e0b23bfaca908c..b6f888d8354e3fcd8c2a91ef5c39fbc77a092d29 100644 (file)
@@ -3481,13 +3481,13 @@ int hci_update_scan_sync(struct hci_dev *hdev)
        return hci_write_scan_enable_sync(hdev, scan);
 }
 
-int hci_update_name_sync(struct hci_dev *hdev)
+int hci_update_name_sync(struct hci_dev *hdev, const u8 *name)
 {
        struct hci_cp_write_local_name cp;
 
        memset(&cp, 0, sizeof(cp));
 
-       memcpy(cp.name, hdev->dev_name, sizeof(cp.name));
+       memcpy(cp.name, name, sizeof(cp.name));
 
        return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LOCAL_NAME,
                                            sizeof(cp), &cp,
@@ -3540,7 +3540,7 @@ int hci_powered_update_sync(struct hci_dev *hdev)
                        hci_write_fast_connectable_sync(hdev, false);
                hci_update_scan_sync(hdev);
                hci_update_class_sync(hdev);
-               hci_update_name_sync(hdev);
+               hci_update_name_sync(hdev, hdev->dev_name);
                hci_update_eir_sync(hdev);
        }
 
index 90e37ff2c85db239c8864d910c6708f3154506e0..50634ef5c8b707a73db8a272bc72b321a0099a8e 100644 (file)
@@ -3892,8 +3892,11 @@ static void set_name_complete(struct hci_dev *hdev, void *data, int err)
 
 static int set_name_sync(struct hci_dev *hdev, void *data)
 {
+       struct mgmt_pending_cmd *cmd = data;
+       struct mgmt_cp_set_local_name *cp = cmd->param;
+
        if (lmp_bredr_capable(hdev)) {
-               hci_update_name_sync(hdev);
+               hci_update_name_sync(hdev, cp->name);
                hci_update_eir_sync(hdev);
        }