From: Taylor Hewetson <taylor@exponent.digital>
To: Jiri Kosina <jikos@kernel.org>, Benjamin Tissoires <bentiss@kernel.org>
Cc: linux-usb@vger.kernel.org, linux-input@vger.kernel.org,
linux-kernel@vger.kernel.org,
Taylor Hewetson <taylor@exponent.digital>
Subject: [PATCH] HID: usbhid: sanitize hid->uniq against non-printable bytes
Date: Sat, 18 Apr 2026 14:58:23 +1200 [thread overview]
Message-ID: <20260418025823.21767-1-taylor@exponent.digital> (raw)
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) {
next reply other threads:[~2026-04-18 2:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-18 2:58 Taylor Hewetson [this message]
2026-04-18 7:14 ` [PATCH] HID: usbhid: sanitize hid->uniq against non-printable bytes Greg KH
2026-04-23 5:55 ` Eric Naim
2026-04-23 9:29 ` Greg KH
2026-04-23 9:36 ` Eric Naim
2026-04-23 9:49 ` Oliver Neukum
2026-04-23 14:03 ` Alan Stern
2026-04-18 19:08 ` USB: core: sanitize string descriptors against C0 control characters Taylor Hewetson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260418025823.21767-1-taylor@exponent.digital \
--to=taylor@exponent.digital \
--cc=bentiss@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.