HID: flydigi: add support for vader 5 pro
Subsystems (2)
v4 cover HID: flydigi: add support for vader 5 pro
Hi all,
A few days ago I was contacted by a friend of mine who was having his share of issues with his Flydigi Vader 5 Pro controller: specifically the rumble didn't work correctly, alongside other issues that were partially solved by using the linked project.
However at the current time his main interest is in Steam support and the driver was working in everything but Steam, which insists on using the controller in hid mode rather than evdev mode by default, and when in evdev mode it is disregarding additional buttons and the gyroscope.
So we ended up with a perfectly working driver for the controller, that at the cost of gyroscope support and back buttons has rumble working correctly in Steam.
Since the driver works in basically everything that is not Steam, including the browser, I decided to submit it anyway as someone else will surely be interested in using some other way that is not the aforementioned program.
To make optimal use of this device the xpad driver should not bind to the controller, and this is the case for more than just this controller as Derek told me, so I added some basic infrastructure to use the best available driver for the device.
I also want to thank the original authors that did the work of implementing the controller the first time (in SDL).
Best regards,
Denis Benato
Link v1: https://lore.kernel.org/all/[email protected]/
Link v2: https://lore.kernel.org/all/[email protected]/
Link v3: https://lore.kernel.org/all/[email protected]/
v2:
- HID: flydigi: add support for vader 5 pro
- Solve flagged vulnerabilities
v3:
- HID: flydigi: add support for vader 5 pro
- Solve the flagged vulnerability
v4:
- HID: flydigi: add support for vader 5 pro
- Fix rumble possibly getting overwhelmed
- Implement battery reporting
- Improve imu reporting
Denis Benato (2):
HID: flydigi: add support for vader 5 pro
Input: xpad - introduce a static table to ignore devices
drivers/hid/Kconfig | 8 + drivers/hid/Makefile | 1 + drivers/hid/hid-flydigi.c | 1129 +++++++++++++++++++++++++++++++++ drivers/hid/hid-ids.h | 3 + drivers/input/joystick/xpad.c | 24 + 5 files changed, 1165 insertions(+) create mode 100644 drivers/hid/hid-flydigi.c
Signature · 1 line
2.47.3
PATCH v4 1/2 HID: flydigi: add support for vader 5 pro
The Flydigi Vader Pro 5 is a gamepad with additional buttons and a gyroscope that is connected wireless to a PC via its own dongle so it's always a USB device: add support for it by following the enstablished pattern of spawning two evdevs that share the same uniqid so that SDL can match the two and expose them as a single controller.
--- drivers/hid/Kconfig | 8 + drivers/hid/Makefile | 1 + drivers/hid/hid-flydigi.c | 1129 +++++++++++++++++++++++++++++++++++++ drivers/hid/hid-ids.h | 3 + 4 files changed, 1141 insertions(+) create mode 100644 drivers/hid/hid-flydigi.c
drivers/hid/Kconfig +8 -0
@@ -1196,6 +1196,14 @@ config STEAM_FF Say Y here if you want to enable force feedback support for the Steam Deck. +config HID_FLYDIGI + tristate "Flydigi game controller support" + depends on USB_HID + select INPUT_FF_MEMLESS + help + Support for Flydigi game controllers that use the vendor-specific + HID protocol, including Vader 5 Pro. + config HID_STEELSERIES tristate "Steelseries devices support" depends on USB_HID
drivers/hid/Makefile +1 -0
@@ -56,6 +56,7 @@ obj-$(CONFIG_HID_FT260) += hid-ft260.o obj-$(CONFIG_HID_GEMBIRD) += hid-gembird.o obj-$(CONFIG_HID_GFRM) += hid-gfrm.o obj-$(CONFIG_HID_GLORIOUS) += hid-glorious.o +obj-$(CONFIG_HID_FLYDIGI) += hid-flydigi.o obj-$(CONFIG_HID_VIVALDI_COMMON) += hid-vivaldi-common.o obj-$(CONFIG_HID_GOODIX_SPI) += hid-goodix-spi.o obj-$(CONFIG_HID_GOOGLE_HAMMER) += hid-google-hammer.o
drivers/hid/hid-flydigi.c new file +1129 -0
1,129 lines not on this page · raw message
drivers/hid/hid-ids.h +3 -0
@@ -523,6 +523,9 @@#define USB_VENDOR_ID_FLATFROG 0x25b5#define USB_DEVICE_ID_MULTITOUCH_3200 0x0002 +#define USB_VENDOR_ID_FLYDIGI 0x37d7 +#define USB_DEVICE_ID_FLYDIGI_VADER5 0x2401 +#define USB_VENDOR_ID_FUTABA 0x0547#define USB_DEVICE_ID_LED_DISPLAY 0x7000
Signature · 1 line
2.47.3
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Use-after-free of custom workqueue due to devres lifecycle mismatch. - [High] Invalid pointer…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Use-after-free of custom workqueue due to devres lifecycle mismatch.
- [High] Invalid pointer dereference of ERR_PTR on probe failure.
--
commit 7c54f2d9cfb04d2dfe81eebdf0f885848becc9b4
Author: Denis Benato <[email protected]>
HID: flydigi: add support for vader 5 pro
This commit introduces support for the Flydigi Vader Pro 5 gamepad. It exposes two evdev nodes with matching unique IDs for the gamepad and motion sensors so userspace applications can pair them.
Quoted 5 lines
drivers/hid/hid-flydigi.c new file +0
-0
[ ... ]
drivers/hid/hid-flydigi.c line 929
Quoted 7 lines
drivers/hid/hid-flydigi.c new file +7
-0+ fd->battery_status =POWER_SUPPLY_STATUS_UNKNOWN ; + fd->battery_capacity =0 ; + + fd->battery =devm_power_supply_register (&hdev->dev, &fd->battery_desc, + &psy_cfg); +if (IS_ERR (fd->battery)) +return PTR_ERR (fd->battery);
[Severity: High]
Can this result in an invalid pointer dereference on probe failure?
If devm_power_supply_register() fails, fd->battery is directly assigned an ERR_PTR. The function returns an error, leading to the err_stop cleanup path.
If an incoming FLYDIGI_CMD_INFO packet from the device is processed during this cleanup window (before hid_hw_stop() fully disables events), it will call flydigi_report_battery():
if (fd->battery)
power_supply_changed(fd->battery);Since an ERR_PTR evaluates to true, the error pointer will be passed to power_supply_changed() and dereferenced. This regression could be triggered by an untrusted USB device spamming status packets.
[ ... ]
drivers/hid/hid-flydigi.c line 1101
Quoted 13 lines
drivers/hid/hid-flydigi.c new file +13
-0+static void flydigi_remove (struct hid_device *hdev) +{ +struct flydigi_device *fd =hid_get_drvdata (hdev); + + scoped_guard(spinlock_irqsave, &fd->lock) { + fd->removed = true; + fd->strong =0 ; + fd->weak =0 ; + } + +cancel_delayed_work_sync (&fd->acquire_work); +cancel_delayed_work_sync (&fd->rumble_work); +destroy_workqueue (fd->wq);
[Severity: High]
Does this cause a use-after-free of the workqueue due to a devres lifecycle mismatch?
The custom workqueue fd->wq is explicitly destroyed here in flydigi_remove() and similarly in the err_stop probe error path. However, the input devices are allocated with devm_input_allocate_device(), meaning they will be unregistered by devres after flydigi_remove() completes.
During this window, the input devices are still visible to userspace. If userspace opens the gamepad or sends force-feedback effects, callbacks like flydigi_gamepad_open() or flydigi_play_effect() will attempt to queue work on the destroyed fd->wq, leading to a use-after-free.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v4 2/2 Input: xpad - introduce a static table to ignore devices
In reply to Denis BenatoCertain devices can work both as HID and as an xpad device: binding both would duplicate inputs causing userspace to receive double inputs; at the same time if a HID device is available it is to be preferred as it can support additional features such as integrated IMU and additional buttons and more, depending on the specific driver, therefore allow only the best driver available to bind the device.
--- drivers/input/joystick/xpad.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/input/joystick/xpad.c +24 -0
@@ -407,6 +407,18 @@ static const struct xpad_device { { 0x0000, 0x0000, "Generic X-Box pad", 0, XTYPE_UNKNOWN } }; +#define XPAD_SUBSTITUTE (_vid, _pid, _enabled) \ + { .vid = (_vid), .pid = (_pid), .enabled = (_enabled) } + +static const struct xpad_excluded_device { +u16 vid; +u16 pid; +bool enabled; +} xpad_excluded_devices[] = { +XPAD_SUBSTITUTE (0x37d7 ,0x2401 ,IS_ENABLED (CONFIG_HID_FLYDIGI )), + { } +}; +/* buttons shared with xbox and xbox360 */ static const signed short xpad_common_btn[] = {BTN_A ,BTN_B ,BTN_X ,BTN_Y ,/* "analog" buttons */
@@ -2046,11 +2058,23 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *idstruct usb_device *udev =interface_to_usbdev (intf);struct usb_xpad *xpad;struct usb_endpoint_descriptor *ep_irq_in, *ep_irq_out; +const struct xpad_excluded_device *excluded;int i, error;if (intf->cur_altsetting->desc.bNumEndpoints !=2 )return -ENODEV ; +for (excluded = xpad_excluded_devices; + excluded->vid || excluded->pid; + excluded++) { +if (!excluded->enabled) +continue ; + +if (le16_to_cpu (udev->descriptor.idVendor) == excluded->vid && +le16_to_cpu (udev->descriptor.idProduct) == excluded->pid) +return -ENODEV ; + } +for (i =0 ; xpad_device[i].idVendor; i++) {if ((le16_to_cpu (udev->descriptor.idVendor) == xpad_device[i].idVendor) && (le16_to_cpu (udev->descriptor.idProduct) == xpad_device[i].idProduct))
Signature · 1 line
2.47.3