Skip to content

Commit 4794394

Browse files
Binary-EaterBenjamin Tissoires
authored andcommitted
HID: multitouch: Correct devm device reference for hidinput input_dev name
Reference the HID device rather than the input device for the devm allocation of the input_dev name. Referencing the input_dev would lead to a use-after-free when the input_dev was unregistered and subsequently fires a uevent that depends on the name. At the point of firing the uevent, the name would be freed by devres management. Use devm_kasprintf to simplify the logic for allocating memory and formatting the input_dev name string. Reported-by: Maxime Ripard <[email protected]> Closes: https://lore.kernel.org/linux-input/ZOZIZCND+L0P1wJc@penguin/T/#m443f3dce92520f74b6cf6ffa8653f9c92643d4ae Fixes: c08d46a ("HID: multitouch: devm conversion") Suggested-by: Maxime Ripard <[email protected]> Suggested-by: Dmitry Torokhov <[email protected]> Signed-off-by: Rahul Rameshbabu <[email protected]> Reviewed-by: Maxime Ripard <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent dd613a4 commit 4794394

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

drivers/hid/hid-multitouch.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,6 @@ static void mt_post_parse(struct mt_device *td, struct mt_application *app)
15941594
static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
15951595
{
15961596
struct mt_device *td = hid_get_drvdata(hdev);
1597-
char *name;
15981597
const char *suffix = NULL;
15991598
struct mt_report_data *rdata;
16001599
struct mt_application *mt_application = NULL;
@@ -1645,15 +1644,9 @@ static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi)
16451644
break;
16461645
}
16471646

1648-
if (suffix) {
1649-
name = devm_kzalloc(&hi->input->dev,
1650-
strlen(hdev->name) + strlen(suffix) + 2,
1651-
GFP_KERNEL);
1652-
if (name) {
1653-
sprintf(name, "%s %s", hdev->name, suffix);
1654-
hi->input->name = name;
1655-
}
1656-
}
1647+
if (suffix)
1648+
hi->input->name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
1649+
"%s %s", hdev->name, suffix);
16571650

16581651
return 0;
16591652
}

0 commit comments

Comments
 (0)