public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] HID: usbhid: sanitize hid->uniq against non-printable bytes
@ 2026-04-18  2:58 Taylor Hewetson
  2026-04-18  7:14 ` Greg KH
  2026-04-18 19:08 ` USB: core: sanitize string descriptors against C0 control characters Taylor Hewetson
  0 siblings, 2 replies; 3+ messages in thread
From: Taylor Hewetson @ 2026-04-18  2:58 UTC (permalink / raw)
  To: Jiri Kosina, Benjamin Tissoires
  Cc: linux-usb, linux-input, linux-kernel, Taylor Hewetson

Some USB HID devices (observed on ASUS ROG Azoth via its 2.4GHz
dongle, USB ID 0b05:1a85) report an iSerialNumber string whose
USB string descriptor declares a longer length than the actual
serial, leaving uninitialized firmware memory - including control
characters such as 0x18 - appended to the returned string.

These non-printable bytes propagate into hid->uniq, which in turn
populates /sys/class/input/inputN/uniq. Downstream userspace
components (systemd sd-device property_is_valid(), and by extension
mutter input enumeration on GNOME Wayland sessions) reject devices
with control characters in their uniq, rendering otherwise-
functional input devices unusable in graphical sessions despite
the kernel input layer correctly translating keypresses.

Truncate hid->uniq at the first byte outside the printable ASCII
range (0x20..0x7e) after the serial is read.

Signed-off-by: Taylor Hewetson <taylor@exponent.digital>
---
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -1427,8 +1427,17 @@
 		snprintf(hid->phys + len, sizeof(hid->phys) - len,
 			 "%d", intf->altsetting[0].desc.bInterfaceNumber);
 
-	if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0)
+	if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0) {
 		hid->uniq[0] = 0;
+	} else {
+		size_t i;
+		for (i = 0; i < sizeof(hid->uniq) && hid->uniq[i]; i++) {
+			if (hid->uniq[i] < 0x20 || hid->uniq[i] > 0x7e) {
+				hid->uniq[i] = 0;
+				break;
+			}
+		}
+	}
 
 	usbhid = kzalloc(sizeof(*usbhid), GFP_KERNEL);
 	if (usbhid == NULL) {

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-18 19:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-18  2:58 [PATCH] HID: usbhid: sanitize hid->uniq against non-printable bytes Taylor Hewetson
2026-04-18  7:14 ` Greg KH
2026-04-18 19:08 ` USB: core: sanitize string descriptors against C0 control characters Taylor Hewetson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox