Skip to content

Commit 2d3f53a

Browse files
rodrigorcJiri Kosina
authored andcommitted
HID: steam: fixes race in handling device list.
Using uhid and KASAN this driver crashed because it was getting several connection events where it only expected one. Then the device was added several times to the static device list and it got corrupted. This patch checks if the device is already in the list before adding it. Signed-off-by: Rodrigo Rivas Costa <[email protected]> Tested-by: Siarhei Vishniakou <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 6363d20 commit 2d3f53a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/hid/hid-steam.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,8 @@ static int steam_register(struct steam_device *steam)
526526
steam_battery_register(steam);
527527

528528
mutex_lock(&steam_devices_lock);
529-
list_add(&steam->list, &steam_devices);
529+
if (list_empty(&steam->list))
530+
list_add(&steam->list, &steam_devices);
530531
mutex_unlock(&steam_devices_lock);
531532
}
532533

@@ -552,7 +553,7 @@ static void steam_unregister(struct steam_device *steam)
552553
hid_info(steam->hdev, "Steam Controller '%s' disconnected",
553554
steam->serial_no);
554555
mutex_lock(&steam_devices_lock);
555-
list_del(&steam->list);
556+
list_del_init(&steam->list);
556557
mutex_unlock(&steam_devices_lock);
557558
steam->serial_no[0] = 0;
558559
}
@@ -738,6 +739,7 @@ static int steam_probe(struct hid_device *hdev,
738739
mutex_init(&steam->mutex);
739740
steam->quirks = id->driver_data;
740741
INIT_WORK(&steam->work_connect, steam_work_connect_cb);
742+
INIT_LIST_HEAD(&steam->list);
741743

742744
steam->client_hdev = steam_create_client_hid(hdev);
743745
if (IS_ERR(steam->client_hdev)) {

0 commit comments

Comments
 (0)