Skip to contentSkip to conversation

HID: hyperx-headset: Add support for HyperX headset devices

PATCH Superseded Sofia Schneider 2 participants 2 messages Jun 27 HID

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 HID: hyperx-headset: Add support for HyperX headset devices

Introduce a HID driver for HyperX Cloud III Wireless headsets, supporting battery reporting and connection status.

Tested with a HyperX Cloud III Wireless only, for lack of other testable devices.

---
v2:
- Call hid_hw_stop() before cancelling work queues in remove() to prevent UAF.
- Safe unregistration of power supply using the spinlock in remove() to prevent race conditions.
- Cancel battery_work in the hid_hw_start() error path in probe() to prevent UAF.
- Dynamically allocate power supply names to avoid sysfs naming collisions.

v1: https://lore.kernel.org/linux-input/[email protected]/T/#t

 MAINTAINERS                      |   6 +
 drivers/hid/Kconfig              |  11 +
 drivers/hid/Makefile             |   1 +
 drivers/hid/hid-hyperx-headset.c | 387 +++++++++++++++++++++++++++++++
 drivers/hid/hid-ids.h            |   1 +
 5 files changed, 406 insertions(+)
 create mode 100644 drivers/hid/hid-hyperx-headset.c
MAINTAINERS +6 -0
index d8252026bbd4..fa49655255f6 100644
@@ -11419,6 +11419,12 @@ F:	include/uapi/linux/hid*
 F:	samples/hid/
 F:	tools/testing/selftests/hid/
 
+HID HYPERX HEADSET DRIVER
+M:	Sofia Schneider <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/hid/hid-hyperx-headset.c
+
 HID LOGITECH DRIVERS
 R:	Filipe Laíns <[email protected]>
 L:	[email protected]
drivers/hid/Kconfig +11 -0
index f9bcaeb66385..e9f5f1f982c9 100644
@@ -1215,6 +1215,17 @@ config HID_HYPERV_MOUSE
 	help
 	Select this option to enable the Hyper-V mouse driver.
 
+config HID_HYPERX_HEADSET
+	tristate "HyperX headset devices"
+	depends on USB_HID
+	select POWER_SUPPLY
+	help
+	Support for HyperX headset devices.
+
+	Say Y here if you would like to enable support for HyperX headset devices.
+	To compile this driver as a module, choose M here: the module will be called
+	hid-hyperx-headset.
+
 config HID_SMARTJOYPLUS
 	tristate "SmartJoy PLUS PS2/USB adapter support"
 	help
drivers/hid/Makefile +1 -0
index 23e6e3dd0c56..9f3fd2c21837 100644
@@ -67,6 +67,7 @@ obj-$(CONFIG_HID_HOLTEK)	+= hid-holtek-kbd.o
 obj-$(CONFIG_HID_HOLTEK)	+= hid-holtek-mouse.o
 obj-$(CONFIG_HID_HOLTEK)	+= hid-holtekff.o
 obj-$(CONFIG_HID_HYPERV_MOUSE)	+= hid-hyperv.o
+obj-$(CONFIG_HID_HYPERX_HEADSET)	+= hid-hyperx-headset.o
 obj-$(CONFIG_HID_ICADE)		+= hid-icade.o
 obj-$(CONFIG_HID_ITE)		+= hid-ite.o
 obj-$(CONFIG_HID_JABRA)		+= hid-jabra.o
drivers/hid/hid-hyperx-headset.c new file +387 -0

387 lines not on this page · raw message

drivers/hid/hid-ids.h +1 -0
index 1059922baaac..aa2c3a71315b 100644
@@ -696,6 +696,7 @@
 #define USB_PRODUCT_ID_HP_PIXART_OEM_USB_OPTICAL_MOUSE_0941	0x0941
 #define USB_PRODUCT_ID_HP_PIXART_OEM_USB_OPTICAL_MOUSE_0641	0x0641
 #define USB_PRODUCT_ID_HP_PIXART_OEM_USB_OPTICAL_MOUSE_1f4a	0x1f4a
+#define USB_DEVICE_ID_HP_HYPERX_CLOUD_III_WIRELESS 0x05b7
 
 #define USB_VENDOR_ID_HUION		0x256c
 #define USB_DEVICE_ID_HUION_TABLET	0x006e
Signature · 1 line
2.54.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Missing power supply unregister on the `hid_hw_start` failure path causes a resource leak and…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing power supply unregister on the hid_hw_start failure path causes a resource leak and Use-After-Free. --

commit 100439ac6279809f99a9f4158c6fe4a272508223
Author: Sofia Schneider <[email protected]>

HID: hyperx-headset: Add support for HyperX headset devices

Introduce a HID driver for HyperX Cloud III Wireless headsets, supporting battery reporting and connection status.

Quoted 5 lines
drivers/hid/hid-hyperx-headset.c new file +0 -0
new file mode 100644
index 0000000000000..b77931d4dfb08

[ ... ]

Quoted 3 lines
drivers/hid/hid-hyperx-headset.c new file +3 -0
+static int hyperx_headset_probe(struct hid_device *hdev,
+				const struct hid_device_id *id)
+{

[ ... ]

drivers/hid/hid-hyperx-headset.c line 305

Quoted 4 lines
drivers/hid/hid-hyperx-headset.c new file +4 -0
+	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
+	if (ret != 0) {
+		hid_err(hdev, "hw_start failed\n");
+		cancel_work_sync(&drvdata->battery_work);

[Severity: High]
Does this error path leak the power supply if it was already registered?

If the device sends a connected event early during hid_hw_start(), battery_work may execute concurrently. It can register the power supply and store it in drvdata->battery. If hid_hw_start() subsequently fails (e.g. during hid_connect), this error path cancels the work but fails to unregister drvdata->battery.

Because drvdata is managed by devm, it will be freed when probe returns an error. This leaves the registered power supply with a dangling pointer to drvdata, which can lead to a use-after-free if its sysfs attributes are accessed.

Should this path check and unregister drvdata->battery before returning?

Quoted 7 lines
drivers/hid/hid-hyperx-headset.c new file +7 -0
+		return ret;
+	}
+
+	schedule_delayed_work(&drvdata->poll_work, 0);
+
+	return 0;
+}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1