* [PATCH] HID: hid-core: sanitize user input in 'new_id_store'
@ 2026-11-25 14:05 Pawel Zalewski
2026-11-25 14:14 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Pawel Zalewski @ 2026-11-25 14:05 UTC (permalink / raw)
To: Jiri Kosina, Benjamin Tissoires
Cc: linux-input, Ping Cheng, Uwe Kleine-König, Pawel Zalewski
Only accept 'driver_data' values that match an existing 'id_table' entry
within the driver. This makes the field mandatory if the 'id_table' is
defined in the HID module and disallows overriding pre-defined values
within the driver module with arbitrary entries from the command line.
This could lead to invalid access as 'driver_data' can be a pointer, hence
the user input needs to be sanitized.
Signed-off-by: Pawel Zalewski <pzalewski@thegoodpenguin.co.uk>
---
This patch was originally part of the series that tidied up the usage of
driver_data [1] - however that did not go anywhere. I think out of the
whole series this patch is the most important as it patches up a potential
invalid memory access in the HID subsystem (as driver_data can be a
pointer).
[1] https://lore.kernel.org/linux-input/20260727-mod-devicetable-hid_device_id-v3-0-980896ca283e@thegoodpenguin.co.uk/
---
drivers/hid/hid-core.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 4a47deb9d833..4de6a0476d30 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -2666,6 +2666,8 @@ static ssize_t new_id_store(struct device_driver *drv, const char *buf,
size_t count)
{
struct hid_driver *hdrv = to_hid_driver(drv);
+ const struct hid_device_id *ids = hdrv->id_table;
+
struct hid_dynid *dynid;
__u32 bus, vendor, product;
unsigned long driver_data = 0;
@@ -2676,6 +2678,22 @@ static ssize_t new_id_store(struct device_driver *drv, const char *buf,
if (ret < 3)
return -EINVAL;
+ /* Only accept driver_data values that match an
+ * existing id_table entry
+ */
+ if (ids) {
+ ret = -EINVAL;
+ while (ids->bus) {
+ if (driver_data == ids->driver_data) {
+ ret = 0;
+ break;
+ }
+ ids++;
+ }
+ if (ret) /* No match */
+ return ret;
+ }
+
dynid = kzalloc_obj(*dynid);
if (!dynid)
return -ENOMEM;
---
base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
change-id: 20261125-acpi-sanitizer-50939c4b8837
Best regards,
--
Pawel Zalewski <pzalewski@thegoodpenguin.co.uk>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] HID: hid-core: sanitize user input in 'new_id_store'
2026-11-25 14:05 [PATCH] HID: hid-core: sanitize user input in 'new_id_store' Pawel Zalewski
@ 2026-11-25 14:14 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-25 14:14 UTC (permalink / raw)
To: Pawel Zalewski; +Cc: linux-input, dmitry.torokhov
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] HID: hid-core: missing Fixes trailer for new_id_store()
driver_data fix
--
commit d1cb0e18023478a6fef5f2aabb283847ff8ab596
Author: Pawel Zalewski <pzalewski@thegoodpenguin.co.uk>
> HID: hid-core: sanitize user input in 'new_id_store'
>
> Only accept 'driver_data' values that match an existing 'id_table' entry
> within the driver. This makes the field mandatory if the 'id_table' is
> defined in the HID module and disallows overriding pre-defined values
> within the driver module with arbitrary entries from the command line.
> This could lead to invalid access as 'driver_data' can be a pointer, hence
> the user input needs to be sanitized.
>
> Signed-off-by: Pawel Zalewski <pzalewski@thegoodpenguin.co.uk>
[Severity: Low]
This fixes a potential invalid memory access when arbitrary driver_data
values are passed through new_id. Should this include:
Fixes: 3a6f82f7a22c ("HID: add dynids facility")
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-acpi-sanitizer-v1-1-44b4aa8c538e@thegoodpenguin.co.uk?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-25 14:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 14:05 [PATCH] HID: hid-core: sanitize user input in 'new_id_store' Pawel Zalewski
2026-11-25 14:14 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox