Input: xbox_gip - Add new driver for Xbox GIP
Subsystems (3)
v5 cover Input: xbox_gip - Add new driver for Xbox GIP
This is a new version of the previously submitted xbox-gip series.
This introduces a new driver for the Xbox One/Series controller protocol, officially known as the Gaming Input Protocol, or GIP for short.
Microsoft released documentation on (some of) GIP in late 2024, upon which this driver is based. Though the documentation was incomplete, it still provided enough information to warrant a clean start over the previous, incomplete implementation.
This driver is already at feature parity with the GIP support in xpad, along with several more enhancements:
- Proper support for parsing message length and fragmented messages
- Metadata parsing, allowing for auto-detection on various parameters, including the presence and location in the message of the share button, as well as detection of specific device types
- Controllable LED support
- HID passthrough for the Chatpad
- Battery information support
- Arcade stick support
- Racing wheel support
- Support for the security flow, allowing use with wireless controllers that include their own dongles. (This does not include support for the first-party dongle yet.)
The framework set out in this driver also allows future expansion for specialized device types and additional features more cleanly than xpad.
Future plans include:
- Adding support for more device types, such as flight sticks.
- Exposing a raw character device to enable sending vendor-specific commands from userspace.
- Event logging to either sysfs or dmesg.
- Support for the headphone jack.
This version cleans up issues found by sashiko as well as some smaller refactoring to clean up reused code.
Vicki Pfau (12):
Input: xbox_gip - Add new driver for Xbox GIP
Input: xpad - Remove Xbox One support
Input: xbox_gip - Add controllable LED support
Input: xbox_gip - Add HID relaying
Input: xbox_gip - Add battery support
Input: xbox_gip - Allow sending fragmented and ACME messages
Input: xbox_gip - Add security implementation from xone
Input: xbox_gip - Add arcade stick support
Input: xbox_gip - Add support for PDP guitar controllers
Input: Add ABS_CLUTCH, HANDBRAKE, and SHIFTER
HID: Map more automobile simulation inputs
Input: xbox_gip - Add wheel support
Documentation/input/devices/xpad.rst | 17 +- MAINTAINERS | 6 + drivers/hid/hid-debug.c | 16 +- drivers/hid/hid-input.c | 2 + drivers/input/joystick/Kconfig | 2 + drivers/input/joystick/Makefile | 1 + drivers/input/joystick/gip/Kconfig | 21 + drivers/input/joystick/gip/Makefile | 8 + drivers/input/joystick/gip/gip-arcade-stick.c | 173 + drivers/input/joystick/gip/gip-core.c | 3234 +++++++++++++++++ drivers/input/joystick/gip/gip-drivers.c | 222 ++ drivers/input/joystick/gip/gip-pdp-jaguar.c | 129 + drivers/input/joystick/gip/gip-security.c | 795 ++++ drivers/input/joystick/gip/gip-wheel.c | 349 ++ drivers/input/joystick/gip/gip.h | 431 +++ drivers/input/joystick/xpad.c | 684 +--- include/uapi/linux/input-event-codes.h | 3 + include/uapi/linux/input.h | 1 + 18 files changed, 5397 insertions(+), 697 deletions(-) create mode 100644 drivers/input/joystick/gip/Kconfig create mode 100644 drivers/input/joystick/gip/Makefile create mode 100644 drivers/input/joystick/gip/gip-arcade-stick.c create mode 100644 drivers/input/joystick/gip/gip-core.c create mode 100644 drivers/input/joystick/gip/gip-drivers.c create mode 100644 drivers/input/joystick/gip/gip-pdp-jaguar.c create mode 100644 drivers/input/joystick/gip/gip-security.c create mode 100644 drivers/input/joystick/gip/gip-wheel.c create mode 100644 drivers/input/joystick/gip/gip.h
Signature · 1 line
2.54.0
PATCH v5 1/12 Input: xbox_gip - Add new driver for Xbox GIP
This introduces a new driver for the Xbox One/Series controller protocol, officially known as the Gaming Input Protocol, or GIP for short.
Microsoft released documentation on (some of) GIP in late 2024, upon which this driver is based. Though the documentation was incomplete, it still provided enough information to warrant a clean start over the previous, incomplete implementation.
This driver is already at feature parity with the GIP support in xpad, along with several more enhancements:
- Proper support for parsing message length and fragmented messages
- Metadata parsing, allowing for auto-detection on various parameters, including the presence and location in the message of the share button, as well as detection of specific device types
The framework set out in this driver also allows future expansion for specialized device types and additional features more cleanly than xpad.
Future plans include:
- Adding support for more device types, such as arcade sticks, racing wheels and flight sticks.
- Support for the security handshake, which is required for devices that use wireless dongles.
- Exposing a raw character device to enable sending vendor-specific commands from userspace.
- Event logging to either sysfs or dmesg.
- Support for the headphone jack.
--- MAINTAINERS | 6 + drivers/input/joystick/Kconfig | 2 + drivers/input/joystick/Makefile | 1 + drivers/input/joystick/gip/Kconfig | 21 + drivers/input/joystick/gip/Makefile | 4 + drivers/input/joystick/gip/gip-core.c | 2591 ++++++++++++++++++++++ drivers/input/joystick/gip/gip-drivers.c | 204 ++ drivers/input/joystick/gip/gip.h | 344 +++ 8 files changed, 3173 insertions(+) create mode 100644 drivers/input/joystick/gip/Kconfig create mode 100644 drivers/input/joystick/gip/Makefile create mode 100644 drivers/input/joystick/gip/gip-core.c create mode 100644 drivers/input/joystick/gip/gip-drivers.c create mode 100644 drivers/input/joystick/gip/gip.h
MAINTAINERS +6 -0
@@ -29347,6 +29347,12 @@ S: Maintained F: drivers/media/rc/keymaps/rc-xbox-dvd.c F: drivers/media/rc/xbox_remote.c +XBOX GIP +M: Vicki Pfau <[email protected]> +L: [email protected] +S: Maintained +F: drivers/input/joystick/gip/ + XC2028/3028 TUNER DRIVER M: Mauro Carvalho Chehab <[email protected]> L: [email protected]
drivers/input/joystick/Kconfig +2 -0
@@ -291,6 +291,8 @@ config JOYSTICK_JOYDUMP To compile this driver as a module, choose M here: the module will be called joydump. +source "drivers/input/joystick/gip/Kconfig" + config JOYSTICK_XPAD tristate "Xbox gamepad support" depends on USB_ARCH_HAS_HCD
drivers/input/joystick/Makefile +1 -0
@@ -39,5 +39,6 @@ obj-$(CONFIG_JOYSTICK_TURBOGRAFX) += turbografx.o obj-$(CONFIG_JOYSTICK_TWIDJOY) += twidjoy.o obj-$(CONFIG_JOYSTICK_WARRIOR) += warrior.o obj-$(CONFIG_JOYSTICK_WALKERA0701) += walkera0701.o +obj-$(CONFIG_JOYSTICK_XBOX_GIP) += gip/ obj-$(CONFIG_JOYSTICK_XPAD) += xpad.o obj-$(CONFIG_JOYSTICK_ZHENHUA) += zhenhua.o
drivers/input/joystick/gip/Kconfig new file +21 -0
@@ -0,0 +1,21 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Gaming Input Protocol driver configuration +# +config JOYSTICK_XBOX_GIP + tristate "Xbox One/Series controller support" + depends on USB && USB_ARCH_HAS_HCD + help + Say Y here if you want to use Xbox One and Series controllers with your + computer. Make sure to say Y to "Joystick support" (CONFIG_INPUT_JOYDEV) + and/or "Event interface support" (CONFIG_INPUT_EVDEV) as well. + + To compile this driver as a module, choose M here: the + module will be called xbox_gip. + +config JOYSTICK_XBOX_GIP_FF + bool "Xbox One/Series controller rumble support" + depends on JOYSTICK_XBOX_GIP && INPUT + select INPUT_FF_MEMLESS + help + Say Y here if you want to take advantage of Xbox One/Series rumble.
drivers/input/joystick/gip/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +obj-$(CONFIG_JOYSTICK_XBOX_GIP) += xbox-gip.o +# Base driver +xbox-gip-y := gip-core.o gip-drivers.o
drivers/input/joystick/gip/gip-core.c new file +2591 -0
2,591 lines not on this page · raw message
drivers/input/joystick/gip/gip-drivers.c new file +204 -0
204 lines not on this page · raw message
drivers/input/joystick/gip/gip.h new file +344 -0
154 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.54.0
Part of the diff is not shown here. View the raw message.
PATCH v5 2/12 Input: xpad - Remove Xbox One support
In reply to Vicki PfauIt has been superseded by xbox_gip. As the new driver is already at feature parity, removing the fairly rough Xbox One support from xpad is safe and will prevent any potential conflicts.
--- Documentation/input/devices/xpad.rst | 17 +- drivers/input/joystick/xpad.c | 684 +-------------------------- 2 files changed, 11 insertions(+), 690 deletions(-)
Documentation/input/devices/xpad.rst +7 -10
@@ -2,19 +2,19 @@ xpad - Linux USB driver for Xbox compatible controllers ======================================================= -This driver exposes all first-party and third-party Xbox compatible -controllers. It has a long history and has enjoyed considerable usage -as Windows' xinput library caused most PC games to focus on Xbox -controller compatibility. +This driver exposes all first-party and third-party Xbox and Xbox 360 +compatible controllers. It has a long history and has enjoyed considerable +usage as Windows' xinput library caused most PC games to focus on Xbox +controller compatibility. Xbox One/Series controller support has been +superseded by the xbox_gip driver, which specializes in the Gaming Input +Protocl that is introduced on the Xbox One. Due to backwards compatibility all buttons are reported as digital. This only affects Original Xbox controllers. All later controller models have only digital face buttons. Rumble is supported on some models of Xbox 360 controllers but not of -Original Xbox controllers nor on Xbox One controllers. As of writing -the Xbox One's rumble protocol has not been reverse-engineered but in -the future could be supported. +Original Xbox controllers. Notes
@@ -98,9 +98,6 @@ All generations of Xbox controllers speak USB over the wire. - Wireless Xbox 360 controllers require a 'Xbox 360 Wireless Gaming Receiver for Windows' - Wired Xbox 360 controllers use standard USB connectors. -- Xbox One controllers can be wireless but speak Wi-Fi Direct and are not - yet supported. -- Xbox One controllers can be wired and use standard Micro-USB connectors.
drivers/input/joystick/xpad.c +4 -680
1,024 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v5 3/12 Input: xbox_gip - Add controllable LED support
In reply to Vicki PfauXbox One controllers have two different types of controllable LED support:
- Monochrome white, which most controllers have.
- RGBW addressible, which the Elite 2 controllers have.
This exposes both types as led cdevs.
--- drivers/input/joystick/gip/Kconfig | 2 +- drivers/input/joystick/gip/gip-core.c | 115 ++++++++++++++++++++++++++ drivers/input/joystick/gip/gip.h | 6 +- 3 files changed, 121 insertions(+), 2 deletions(-)
drivers/input/joystick/gip/Kconfig +1 -1
@@ -4,7 +4,7 @@ # config JOYSTICK_XBOX_GIP tristate "Xbox One/Series controller support" - depends on USB && USB_ARCH_HAS_HCD + depends on USB && USB_ARCH_HAS_HCD && LEDS_CLASS_MULTICOLOR help Say Y here if you want to use Xbox One and Series controllers with your computer. Make sure to say Y to "Joystick support" (CONFIG_INPUT_JOYDEV)
drivers/input/joystick/gip/gip-core.c +115 -0
130 lines not on this page · raw message
drivers/input/joystick/gip/gip.h +5 -1
@@ -12,6 +12,7 @@#ifndef _GIP_H#define _GIP_H +#include <linux/led-class-multicolor.h> #include <linux/rcupdate.h> #include <linux/usb/input.h>
@@ -234,6 +235,10 @@ struct gip_attachment {uint8_t seq_vendor;uint8_t device_state; +union { +struct led_classdev standard; +struct led_classdev_mc color; + } guide_led;struct gip_extended_status status;
@@ -245,7 +250,6 @@ struct gip_attachment {int extra_axes;bool dpad_as_buttons; -struct hid_device __rcu *hdev; };struct gip_urb {
Signature · 1 line
2.54.0
PATCH v5 4/12 Input: xbox_gip - Add HID relaying
In reply to Vicki PfauGIP allows tunneling of HID packets, with the HID descriptor embedded in the GIP metadata exchanged during the initial handshake. This patch creates a hid_device for this HID descriptor if found, as well as relaying the HID packets.
--- drivers/input/joystick/gip/gip-core.c | 114 +++++++++++++++++++++++++- drivers/input/joystick/gip/gip.h | 2 + include/uapi/linux/input.h | 1 + 3 files changed, 114 insertions(+), 3 deletions(-)
drivers/input/joystick/gip/gip-core.c +111 -3
@@ -560,6 +560,54 @@ int gip_send_vendor_message(struct gip_attachment *attachment, bytes, num_bytes); } +static int gip_hid_ll_parse (struct hid_device *hdev) +{ +struct gip_attachment *attachment = hdev->driver_data; + +return hid_parse_report (hdev, + attachment->metadata.device.hid_descriptor, + attachment->metadata.device.hid_descriptor_size); +} + +static int gip_hid_ll_start (struct hid_device *hdev) +{ +return 0 ; +} + +static void gip_hid_ll_stop (struct hid_device *hdev) +{ +} + +static int gip_hid_ll_open (struct hid_device *hdev) +{ +return 0 ; +} + +static void gip_hid_ll_close (struct hid_device *hdev) +{ +} + +static int gip_hid_ll_raw_request (struct hid_device *hdev, +unsigned char reportnum,uint8_t *buf,size_t count, +unsigned char report_type,int reqtype) +{ +/* +* TODO: Based on the metadata, output reports appear to be possible, +* but the chatpad doesn't have the LEDs it claims to support, so +* it's not clear how to test we're sending them properly. +*/ +return 0 ; +} + +static const struct hid_ll_driver gip_hid_ll_driver = { + .parse = gip_hid_ll_parse, + .start = gip_hid_ll_start, + .stop = gip_hid_ll_stop, + .open = gip_hid_ll_open, + .close = gip_hid_ll_close, + .raw_request = gip_hid_ll_raw_request, +}; +static void gip_metadata_free (struct device *dev,struct gip_metadata *metadata) {devm_kfree (dev, metadata->device.audio_formats);
@@ -1303,6 +1351,48 @@ static int gip_init_input_device(struct gip_attachment *attachment)return rc; } +static int gip_create_hdev (struct gip_attachment *attachment) +{ +struct hid_device *hdev; +int rc; + +if (!attachment->metadata.device.hid_descriptor) +return 0 ; + +rcu_read_lock (); + hdev =rcu_dereference (attachment->hdev); +rcu_read_unlock (); +if (hdev) +return 0 ; + + hdev =hid_allocate_device (); + +if (IS_ERR (hdev)) +return PTR_ERR (hdev); + + hdev->ll_driver = &gip_hid_ll_driver; + hdev->bus =BUS_GIP ; + hdev->vendor = attachment->vendor_id; + hdev->product = attachment->product_id; + hdev->dev.parent =to_gip_device (attachment); + hdev->driver_data = attachment; +if (attachment->name) +strscpy (hdev->name, attachment->name); +else +strscpy (hdev->name,"Xbox Chatpad" ); +strscpy (hdev->phys, attachment->phys); + rc =hid_add_device (hdev); +if (rc) { +gip_err (attachment,"HID device add failed: %d\n" , rc); +hid_destroy_device (hdev); + }else { +rcu_assign_pointer (attachment->hdev, hdev); +synchronize_rcu (); + } + +return rc; +} +static int gip_send_init_sequence (struct gip_attachment *attachment) {int rc =0 ;
@@ -1368,7 +1458,11 @@ static int gip_send_init_sequence(struct gip_attachment *attachment)if (rc)return rc; -return 0 ; + rc =gip_create_hdev (attachment); +if (rc) +return rc; + +return rc; }static void gip_fragment_timeout (struct work_struct *work)
@@ -1388,19 +1482,25 @@ static void gip_fragment_timeout(struct work_struct *work)static void gip_free_devices (struct gip_attachment *attachment) {struct input_dev *input; +struct hid_device *hdev;if (attachment->driver && attachment->driver->remove) attachment->driver->remove (attachment);rcu_read_lock (); input =rcu_dereference (attachment->input); + hdev =rcu_dereference (attachment->hdev);rcu_read_unlock ();rcu_assign_pointer (attachment->input,NULL ); +rcu_assign_pointer (attachment->hdev,NULL );synchronize_rcu ();if (input)input_unregister_device (input); + +if (hdev) +hid_destroy_device (hdev); }static void gip_reset_metadata (struct gip_attachment *attachment)
@@ -1768,9 +1868,17 @@ static int gip_handle_command_firmware(struct gip_attachment *attachment,static int gip_handle_command_hid_report (struct gip_attachment *attachment,const struct gip_header *header,uint8_t *bytes,int num_bytes) { -gip_warn (attachment,"Unimplemented HID report message\n" ); +struct hid_device *hdev; -return -EOPNOTSUPP ; +guard (rcu)(); + hdev =rcu_dereference (attachment->hdev); +if (hdev) +return hid_safe_input_report (hdev,HID_INPUT_REPORT , bytes, + num_bytes,umin (header->length, num_bytes), true); + +gip_warn (attachment,"Got HID report with no HID descriptor\n" ); + +return -EPROTO ; } static int gip_handle_command_extended(struct gip_attachment *attachment,
drivers/input/joystick/gip/gip.h +2 -0
@@ -12,6 +12,7 @@#ifndef _GIP_H#define _GIP_H +#include <linux/hid.h> #include <linux/led-class-multicolor.h> #include <linux/rcupdate.h> #include <linux/usb/input.h>
@@ -250,6 +251,7 @@ struct gip_attachment {int extra_axes;bool dpad_as_buttons; +struct hid_device __rcu *hdev; };struct gip_urb {
include/uapi/linux/input.h +1 -0
@@ -276,6 +276,7 @@ struct input_mask {#define BUS_INTEL_ISHTP 0x1F#define BUS_AMD_SFH 0x20#define BUS_SDW 0x21 +#define BUS_GIP 0x22/* * MT_TOOL types
Signature · 1 line
2.54.0
PATCH v5 5/12 Input: xbox_gip - Add battery support
In reply to Vicki PfauControllers are required to give information about the battery in the controller, if present. This patch exposes that information as a power_supply device.
--- drivers/input/joystick/gip/gip-core.c | 125 +++++++++++++++++++++++++- drivers/input/joystick/gip/gip.h | 4 + 2 files changed, 125 insertions(+), 4 deletions(-)
drivers/input/joystick/gip/gip-core.c +121 -4
@@ -255,6 +255,13 @@ static const struct gip_audio_format gip_audio_format_table[MAX_GIP_AUDIO_FORMAT }; +static enum power_supply_property gip_battery_props[] = { +POWER_SUPPLY_PROP_PRESENT , +POWER_SUPPLY_PROP_CAPACITY_LEVEL , +POWER_SUPPLY_PROP_SCOPE , +POWER_SUPPLY_PROP_STATUS , +}; +static const struct gip_quirks base_quirks[] = { {GIP_VID_PDP ,GIP_PID_PDP_ROCK_CANDY ,0 , .quirks =GIP_QUIRK_NO_HELLO },
@@ -1199,6 +1206,106 @@ static int gip_guide_led_probe(struct gip_attachment *attachment, struct devicereturn rc; } +static int gip_battery_get_property (struct power_supply *psy, +enum power_supply_property psp,union power_supply_propval *val) +{ +struct gip_attachment *attachment =power_supply_get_drvdata (psy); + +guard (spinlock_irqsave)(&attachment->battery_lock); +switch (psp) { +case POWER_SUPPLY_PROP_PRESENT : + val->intval = attachment->status.base.battery_type !=GIP_BATTERY_ABSENT ; +break ; +case POWER_SUPPLY_PROP_SCOPE : + val->intval =POWER_SUPPLY_SCOPE_DEVICE ; +break ; +case POWER_SUPPLY_PROP_STATUS : +if (attachment->status.base.battery_type ==GIP_BATTERY_ABSENT ) { + val->intval =POWER_SUPPLY_STATUS_NOT_CHARGING ; + }else { +switch (attachment->status.base.charge) { +case GIP_CHARGING : +if (attachment->status.base.battery_level ==GIP_BATTERY_FULL ) + val->intval =POWER_SUPPLY_STATUS_FULL ; +else + val->intval =POWER_SUPPLY_STATUS_CHARGING ; +break ; +case GIP_NOT_CHARGING : + val->intval =POWER_SUPPLY_STATUS_DISCHARGING ; +break ; +case GIP_CHARGE_ERROR : +default : + val->intval =POWER_SUPPLY_STATUS_UNKNOWN ; +break ; + } + } +break ; +case POWER_SUPPLY_PROP_CAPACITY_LEVEL : +if (attachment->status.base.battery_type ==GIP_BATTERY_ABSENT ) { + val->intval =POWER_SUPPLY_CAPACITY_LEVEL_FULL ; + }else { +switch (attachment->status.base.battery_level) { +case GIP_BATTERY_CRITICAL : + val->intval =POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL ; +break ; +case GIP_BATTERY_LOW : + val->intval =POWER_SUPPLY_CAPACITY_LEVEL_LOW ; +break ; +case GIP_BATTERY_MEDIUM : + val->intval =POWER_SUPPLY_CAPACITY_LEVEL_NORMAL ; +break ; +case GIP_BATTERY_FULL : + val->intval =POWER_SUPPLY_CAPACITY_LEVEL_FULL ; +break ; +default : + val->intval =POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN ; +break ; + } +break ; + } +break ; +default : +return -EINVAL ; + } +return 0 ; +} + +static int gip_battery_create (struct gip_attachment *attachment,struct device *dev) +{ +struct power_supply_config supply_config = { .drv_data = attachment, }; +int rc; + + attachment->battery_desc.properties = gip_battery_props; + attachment->battery_desc.num_properties =ARRAY_SIZE (gip_battery_props); + attachment->battery_desc.get_property = gip_battery_get_property; + attachment->battery_desc.type =POWER_SUPPLY_TYPE_BATTERY ; + attachment->battery_desc.name =devm_kasprintf (dev,GFP_KERNEL , +"gip-battery-%s" ,dev_name (dev)); + +if (!attachment->battery_desc.name) +return -ENOMEM ; + + attachment->battery =devm_power_supply_register (dev, + &attachment->battery_desc, &supply_config); +if (IS_ERR (attachment->battery)) { + rc =PTR_ERR (attachment->battery); + goto err_out; + } + + rc =power_supply_powers (attachment->battery, dev); +if (rc <0 ) { +power_supply_unregister (attachment->battery); + goto err_out; + } + +return 0 ; + +err_out: + attachment->battery =NULL ; +devm_kfree (dev, attachment->battery_desc.name); +return rc; +} +static bool gip_send_set_device_state (struct gip_attachment *attachment,uint8_t state) {uint8_t buffer[] = { state };
@@ -1312,6 +1419,9 @@ static int gip_setup_input_device(struct gip_attachment *attachment) rc =gip_guide_led_probe (attachment, &input->dev);if (rc)gip_err (attachment,"Failed to register LEDs: %d\n" , rc); + rc =gip_battery_create (attachment, &input->dev); +if (rc) +gip_err (attachment,"Failed to register battery: %d\n" , rc);return 0 ;
@@ -1494,6 +1604,8 @@ static void gip_free_devices(struct gip_attachment *attachment)rcu_assign_pointer (attachment->input,NULL );rcu_assign_pointer (attachment->hdev,NULL ); +/* The following are freed by devres */ + attachment->battery =NULL ;synchronize_rcu ();if (input)
@@ -1629,10 +1741,14 @@ static int gip_handle_command_status_device(struct gip_attachment *attachment,if (num_bytes <1 )return -EINVAL ; - attachment->status.base.battery_level = bytes[0 ] &3 ; - attachment->status.base.battery_type = (bytes[0 ] >>2 ) &3 ; - attachment->status.base.charge = (bytes[0 ] >>4 ) &3 ; - attachment->status.base.power_level = (bytes[0 ] >>6 ) &3 ; + scoped_guard(spinlock_irqsave, &attachment->battery_lock) { + attachment->status.base.battery_level = bytes[0 ] &3 ; + attachment->status.base.battery_type = (bytes[0 ] >>2 ) &3 ; + attachment->status.base.charge = (bytes[0 ] >>4 ) &3 ; + attachment->status.base.power_level = (bytes[0 ] >>6 ) &3 ; + } +if (attachment->battery) +power_supply_changed (attachment->battery);if (num_bytes >=4 ) { attachment->status.device_active = bytes[1 ] &1 ;
@@ -2122,6 +2238,7 @@ static struct gip_attachment *gip_ensure_attachment(struct gip_device *device, device->attachments[attachment_index] = attachment;mutex_init (&attachment->lock); +spin_lock_init (&attachment->battery_lock);INIT_DELAYED_WORK (&attachment->in_fragment_timeout, gip_fragment_timeout);INIT_DELAYED_WORK (&attachment->metadata_next, gip_retry_metadata);
drivers/input/joystick/gip/gip.h +4 -0
@@ -14,6 +14,7 @@#include <linux/hid.h> #include <linux/led-class-multicolor.h> +#include <linux/power_supply.h> #include <linux/rcupdate.h> #include <linux/usb/input.h>
@@ -241,6 +242,9 @@ struct gip_attachment {struct led_classdev_mc color; } guide_led; +spinlock_t battery_lock; +struct power_supply *battery; +struct power_supply_desc battery_desc;struct gip_extended_status status;enum gip_elite_button_format xbe_format;
Signature · 1 line
2.54.0
PATCH v5 6/12 Input: xbox_gip - Allow sending fragmented and ACME messages
In reply to Vicki PfauGIP supports sending messages that exceed the length of the MTU using a fragmented message flow. It sits on top of a reliable message transmission flow, which uses the ACME flag to signal that a message must be ACKed if it is received properly. We already supported receiving and coalescing these messages, but the ability to send them wasn't yet present due to not needing it for basic usage. This patch adds it for future use with the security flow.
--- drivers/input/joystick/gip/gip-core.c | 330 ++++++++++++++++++++++++-- drivers/input/joystick/gip/gip.h | 17 ++ 2 files changed, 330 insertions(+), 17 deletions(-)
drivers/input/joystick/gip/gip-core.c +313 -17
@@ -8,7 +8,6 @@* - Audio device support * - Security packet handshake * - Event logging -* - Sending fragmented messages * - Raw character device * - Wheel support * - Flight stick support
@@ -28,6 +27,7 @@#define GIP_WIRED_INTF_DATA 0#define GIP_WIRED_INTF_AUDIO 1 +#define GIP_DUAL_LENGTH 6#define MAX_MESSAGE_LENGTH 0x4000#define MAX_AUDIO_MESSAGES 9
@@ -437,6 +437,13 @@ static uint8_t gip_sequence_next(struct gip_attachment *attachment,return seq; } +static unsigned int gip_fragment_id (const struct gip_attachment *attachment, +const struct gip_out_fragment *fragment) +{ +return BIT (attachment->attachment_index *MAX_OUT_FRAGMENTS + + (unsigned ) (fragment - attachment->out_fragments)); +} +static void gip_handle_quirks_array (struct gip_attachment *attachment,const struct gip_quirks *quirks) {
@@ -479,6 +486,42 @@ static void gip_handle_quirks(struct gip_attachment *attachment)gip_handle_quirks_array (attachment, attachment->driver->quirks); } +static struct gip_out_fragment *gip_find_fragment (struct gip_attachment *attachment, +uint8_t message_type,uint8_t flags,uint8_t seq,bool strict) +{ +int i; + +for (i =0 ; i <MAX_OUT_FRAGMENTS ; i++) { +if (!attachment->out_fragments[i].active) +continue ; +if (attachment->out_fragments[i].message != message_type) +continue ; +if ((attachment->out_fragments[i].flags ^ flags) &GIP_FLAG_SYSTEM ) +continue ; +if (attachment->out_fragments[i].seq != seq) { +if (strict) +continue ; + +/* +* Found one with the wrong sequence number. For some +* reason the official driver allows this. +*/ +gip_warn (attachment, +"Found fragment with different sequence number %02x, wanted %02x\n" , + attachment->out_fragments[i].seq, seq); + } + +return &attachment->out_fragments[i]; + } +return NULL ; +} + +static void gip_free_fragment (struct gip_out_fragment *fragment) +{ +kfree (fragment->data); +memset (fragment,0 ,sizeof (*fragment)); +} +static int gip_send_raw_message (struct gip_attachment *attachment,uint8_t message_type,uint8_t flags,uint8_t seq,const uint8_t *bytes,int num_bytes)
@@ -486,20 +529,25 @@ static int gip_send_raw_message(struct gip_attachment *attachment,struct gip_interface *intf;int offset =3 ;struct gip_urb *urb =NULL ; +struct gip_out_fragment *fragment =NULL ;int i;int rc =0 ; +int mtu = gip_data_class_mtu[message_type >>GIP_DATA_CLASS_SHIFT ]; +int reduced_mtu = mtu -GIP_DUAL_LENGTH ; +/* +* This buffer size shouldn't need to be more than 6 (there should never +* be more than 3 length bytes), but add enough extra to fit fully +* extended bignums for 32 bit (5 bytes) + 16 bit (3 bytes) values to be +* safe and then WARN_ON if we go over. If this ever happens it would be +* due to driver bugs. +*/ +uint8_t header[11 ];if (num_bytes <0 ) {gip_warn (attachment,"Invalid message length %d\n" , num_bytes);return -EINVAL ; } -if (num_bytes +6 > gip_data_class_mtu[message_type >>GIP_DATA_CLASS_SHIFT ]) { -gip_err (attachment, -"Attempted to send a message that requires fragmenting, which is not yet supported.\n" ); -return -EOPNOTSUPP ; - } -if ((message_type &GIP_DATA_CLASS_MASK ) ==GIP_DATA_CLASS_AUDIO ) intf = &attachment->device->audio;else
@@ -511,6 +559,90 @@ static int gip_send_raw_message(struct gip_attachment *attachment,return -EOPNOTSUPP ; } + header[0 ] = message_type; + header[2 ] = seq; + +if (num_bytes > reduced_mtu || + (flags & (GIP_FLAG_ACME |GIP_FLAG_FRAGMENT )) ==GIP_FLAG_ACME ) { +for (i =0 ; i <MAX_OUT_FRAGMENTS ; i++) { +if (attachment->out_fragments[i].active) +continue ; + + fragment = &attachment->out_fragments[i]; +break ; + } + +if (!fragment) { +gip_err (attachment,"Fragmented message queue is full; dropping message\n" ); +return -EALREADY ; + } + + fragment->data =kmalloc (num_bytes,GFP_KERNEL ); +if (!fragment->data) +return -ENOMEM ; + fragment->active = true; + fragment->message = message_type; + fragment->flags = flags &GIP_FLAG_SYSTEM ; + fragment->acked = false; + fragment->seq = seq; + fragment->total_length = num_bytes; + fragment->fragment_offset =0 ; +memcpy (fragment->data, bytes, num_bytes); + bytes = fragment->data; + +if (num_bytes > reduced_mtu) { +gip_dbg (attachment,"Starting new reliable message: %02x%02x%02x, total length %u\n" , + message_type, flags, seq, num_bytes); + flags |=GIP_FLAG_INIT_FRAG |GIP_FLAG_FRAGMENT |GIP_FLAG_ACME ; + fragment->flags |=GIP_FLAG_FRAGMENT ; +/* The spec says to extend the value to fit in 3 bytes */ + offset +=gip_encode_length (reduced_mtu, &header[offset],sizeof (header)); +if (offset ==4 && reduced_mtu <0x80 && num_bytes <0x80 ) { + header[3 ] |=0x80 ; + header[4 ] =0 ; + offset =5 ; + } + offset +=gip_encode_length (num_bytes, &header[offset], +sizeof (header) - offset); +WARN_ON (offset !=GIP_DUAL_LENGTH ); + num_bytes = mtu - offset; + }else { + offset +=gip_encode_length (num_bytes, &header[offset], +sizeof (header) - offset); + } + }else if (flags &GIP_FLAG_FRAGMENT ) { + fragment =gip_find_fragment (attachment, message_type, flags, seq, true); +if (!fragment) { +gip_err (attachment, +"Attempted to send message fragment with no associated message\n" ); +return -EINVAL ; + } + + num_bytes =min (reduced_mtu, fragment->total_length - fragment->fragment_offset); + offset +=gip_encode_length (num_bytes, &header[offset], +sizeof (header) - offset); +if (offset ==4 && num_bytes <0x80 && fragment->fragment_offset <0x80 ) { + header[3 ] |=0x80 ; + header[4 ] =0 ; + offset =5 ; + } + offset +=gip_encode_length (fragment->fragment_offset, &header[offset], +sizeof (header) - offset); +WARN_ON (offset !=GIP_DUAL_LENGTH ); + +if (num_bytes && fragment->fragment_offset + num_bytes == fragment->total_length) { +/* The final fragment in a fragmented message must be ACKed */ + flags |=GIP_FLAG_ACME ; + fragment->acked = false; + } + bytes = &fragment->data[fragment->fragment_offset]; + }else if (num_bytes >=0 ) { + offset +=gip_encode_length (num_bytes, &header[offset], +sizeof (header) - offset); + } + + header[1 ] = flags; +guard (spinlock_irqsave)(&attachment->device->message_lock);for (i =0 ; i <MAX_OUT_MESSAGES && !urb; i++) {if (!intf->out_queue[i].urb)
@@ -520,17 +652,13 @@ static int gip_send_raw_message(struct gip_attachment *attachment, }if (!urb) {gip_err (attachment,"Output queue is full; dropping message\n" ); -return -ENOSPC ; + rc = -ENOSPC ; + goto err_free_fragment; } - urb->data[0 ] = message_type; - urb->data[1 ] = flags; - urb->data[2 ] = seq; - offset +=gip_encode_length (num_bytes, &urb->data[offset], -sizeof (urb->data) - offset); +memcpy (urb->data, header, offset);if (num_bytes >0 )memcpy (&urb->data[offset], bytes, num_bytes); - num_bytes += offset; urb->urb->transfer_buffer_length = num_bytes;
@@ -545,9 +673,96 @@ static int gip_send_raw_message(struct gip_attachment *attachment, __func__, rc);usb_unanchor_urb (urb->urb); rc = -EIO ; + goto err_free_fragment; + } + +if (fragment) { +/* +* Sending further fragments is handled in gip_urb_out if this fragment doesn't need +* ACKing or in gip_handle_command_protocol_control if it does. The flag should also +* be cleared if we're done sending this packet. +*/ +if (fragment->total_length > reduced_mtu && !(flags &GIP_FLAG_ACME )) + intf->has_pending_out |=gip_fragment_id (attachment, fragment); +else + intf->has_pending_out &= ~gip_fragment_id (attachment, fragment); }return rc; + +err_free_fragment: +gip_free_fragment (fragment); +return rc; +} + +static int gip_send_next_fragment (struct gip_attachment *attachment, +struct gip_out_fragment *fragment) +{ +struct gip_interface *intf; +int next_bytes; +int flags =GIP_FLAG_FRAGMENT | fragment->flags | attachment->attachment_index; +int mtu; +int rc; + + mtu = gip_data_class_mtu[fragment->message >>GIP_DATA_CLASS_SHIFT ] -GIP_DUAL_LENGTH ; +if (fragment->fragment_offset == fragment->total_length) { +if ((fragment->message &GIP_DATA_CLASS_MASK ) ==GIP_DATA_CLASS_AUDIO ) + intf = &attachment->device->audio; +else + intf = &attachment->device->data; + + next_bytes =0 ; + intf->has_pending_out &= ~gip_fragment_id (attachment, fragment); + }else if (fragment->fragment_offset + mtu >= fragment->total_length) { + next_bytes = fragment->total_length - fragment->fragment_offset; + flags |=GIP_FLAG_ACME ; + }else { + next_bytes = mtu; + } + + rc =gip_send_raw_message (attachment, fragment->message, flags, + fragment->seq, &fragment->data[fragment->fragment_offset], + next_bytes); + +if (rc <0 ) +return rc; + +if (fragment->acked) + fragment->fragment_offset += next_bytes; +if (next_bytes ==0 && !(fragment->flags &GIP_FLAG_ACME )) +/* Finished sending the message */ +gip_free_fragment (fragment); +return next_bytes; +} + +static void gip_send_fragment_work (struct work_struct *work) +{ + struct gip_interface *intf = container_of(work, struct gip_interface, send_fragment); +struct gip_out_fragment *fragment; +unsigned int has_pending_out; +unsigned long flags; +int i, j; + +spin_lock_irqsave (&intf->device->message_lock, flags); + has_pending_out = intf->has_pending_out; +spin_unlock_irqrestore (&intf->device->message_lock, flags); +for (i =0 ; i <MAX_ATTACHMENTS ; i++) { +struct gip_attachment *attachment = intf->device->attachments[i]; + +for (j =0 ; j <MAX_OUT_FRAGMENTS ; j++) { +/* Check for pending output fragments */ +if (!(has_pending_out &BIT (i *MAX_OUT_FRAGMENTS + j))) +continue ; + +guard (mutex)(&attachment->lock); + fragment = &attachment->out_fragments[j]; +if (!fragment->active) +continue ; +if (!(fragment->flags &GIP_FLAG_FRAGMENT )) +continue ; +gip_send_next_fragment (attachment, fragment); + } + } } int gip_send_system_message(struct gip_attachment *attachment,
@@ -1659,6 +1874,8 @@ static int gip_ensure_metadata(struct gip_attachment *attachment)static void gip_reset_attachment (struct gip_attachment *attachment) { +int i; +cancel_delayed_work (&attachment->metadata_next);cancel_delayed_work (&attachment->in_fragment_timeout);
@@ -1668,15 +1885,84 @@ static void gip_reset_attachment(struct gip_attachment *attachment) attachment->in_fragment_message =-1 ; } +for (i =0 ; i <MAX_OUT_FRAGMENTS ; i++) { +if (attachment->out_fragments[i].active) +gip_free_fragment (&attachment->out_fragments[i]); + } +gip_free_devices (attachment); + }static int gip_handle_command_protocol_control (struct gip_attachment *attachment,const struct gip_header *header,const uint8_t *bytes,int num_bytes) { -/* TODO */ -gip_warn (attachment,"Unimplemented Protocol Control message\n" ); -return -EOPNOTSUPP ; +const struct gip_protocol_control_ack *ack; +struct gip_out_fragment *fragment =NULL ; +uint32_t fragment_offset; +uint16_t remaining_buffer; +bool ok = true; +int mtu; +int rc; + +if (num_bytes <1 ) +return -EINVAL ; + +if (bytes[0 ] !=GIP_CONTROL_CODE_ACK ) { +gip_warn (attachment,"Unimplemented Protocol Control code %i message\n" , bytes[0 ]); +return -EOPNOTSUPP ; + } + +if (num_bytes <sizeof (*ack)) +return -EINVAL ; + + ack = (const struct gip_protocol_control_ack *)bytes; + + fragment =gip_find_fragment (attachment, ack->message_type, ack->flags, + header->sequence_id, false); +if (!fragment) { +gip_warn (attachment,"Received ACK for unknown message\n" ); + rc = -EINVAL ; + goto resend; + } + + + fragment_offset =le32_to_cpu (ack->fragment_offset); + remaining_buffer =le16_to_cpu (ack->remaining_buffer); + +if (fragment_offset > fragment->total_length) + ok = false; + mtu = gip_data_class_mtu[fragment->message >>GIP_DATA_CLASS_SHIFT ] -GIP_DUAL_LENGTH ; +if (!ok) { +gip_warn (attachment,"Received invalid buffer offset in ACK, " +"got offset=%u + remaining=%u, expected offset=%u + remaining=%u\n" , + fragment_offset, remaining_buffer, + fragment->fragment_offset, fragment->total_length - fragment->fragment_offset); + rc = -EINVAL ; + goto resend; + }else if ((fragment->flags &GIP_FLAG_FRAGMENT ) && + (fragment->fragment_offset > fragment_offset || + fragment->fragment_offset + mtu < fragment_offset)) { +gip_warn (attachment,"Received unexpected buffer offset in ACK, " +"got offset=%u, expected offset=%u\n" , + fragment_offset, fragment->fragment_offset + mtu); + } + + fragment->acked = true; +if (fragment->flags &GIP_FLAG_FRAGMENT ) { + fragment->fragment_offset = fragment_offset; + rc =gip_send_next_fragment (attachment, fragment); +if (rc <0 ) +return rc; + }else { +gip_free_fragment (fragment); + } + +return 0 ; + +resend: +// TODO +return rc; } static bool gip_handle_command_hello_device(struct gip_attachment *attachment,
@@ -2220,6 +2506,7 @@ static struct gip_attachment *gip_ensure_attachment(struct gip_device *device, uint8_t attachment_index) {struct gip_attachment *attachment = device->attachments[attachment_index]; +int i;if (!attachment) { attachment =devm_kzalloc (to_gip_device (device),sizeof (*attachment),GFP_KERNEL );
@@ -2235,6 +2522,9 @@ static struct gip_attachment *gip_ensure_attachment(struct gip_device *device, attachment->product_id = device->udev->descriptor.idProduct; } +for (i =0 ; i <MAX_OUT_FRAGMENTS ; i++) + attachment->out_fragments[i].message =-1 ; + device->attachments[attachment_index] = attachment;mutex_init (&attachment->lock);
@@ -2549,6 +2839,7 @@ static void gip_urb_out(struct urb *urb)switch (status) {case 0 :/* success */ +schedule_work (&intf->send_fragment);break ;case -ECONNRESET :
@@ -2745,9 +3036,11 @@ static int gip_probe(struct usb_interface *intf, const struct usb_device_id *id) gip->data.device = gip; gip->data.intf = intf; gip->data.mtu =BASE_GIP_MTU ; +INIT_WORK (&gip->data.send_fragment, gip_send_fragment_work); gip->audio.device = gip; gip->audio.mtu =MAX_GIP_MTU ; gip->audio.isoc_messages =MAX_AUDIO_MESSAGES ; +INIT_WORK (&gip->audio.send_fragment, gip_send_fragment_work);INIT_WORK (&gip->receive_message, gip_receive_work);spin_lock_init (&gip->message_lock);
@@ -2779,6 +3072,9 @@ static int gip_shutdown(struct gip_device *device)int i;cancel_work_sync (&device->receive_message); +cancel_work_sync (&device->data.send_fragment); +if (device->audio.intf) +cancel_work_sync (&device->audio.send_fragment);for (i =0 ; i <MAX_ATTACHMENTS ; i++) {struct gip_attachment *attachment = device->attachments[i];
drivers/input/joystick/gip/gip.h +17 -0
@@ -25,6 +25,7 @@#define MAX_IN_MESSAGES 8#define MAX_OUT_MESSAGES 8 +#define MAX_OUT_FRAGMENTS 2#define GIP_VID_MICROSOFT 0x045e#define GIP_VID_PDP 0x0e6f
@@ -194,6 +195,17 @@ struct gip_extended_status {struct gip_status_event events[5 ]; }; +struct gip_out_fragment { +bool active; +bool acked; +uint8_t message; +uint8_t flags; +uint8_t seq; +uint16_t total_length; +uint32_t fragment_offset; +uint8_t *data; +}; +struct gip_attachment ;typedef int (*gip_command_handler )(struct gip_attachment *a,const struct gip_header *header,const uint8_t *bytes,int num_bytes);
@@ -222,6 +234,8 @@ struct gip_attachment {struct delayed_work in_fragment_timeout;int in_fragment_retries; +struct gip_out_fragment out_fragments[MAX_OUT_FRAGMENTS ]; +uint16_t firmware_major_version;uint16_t firmware_minor_version;
@@ -275,6 +289,9 @@ struct gip_interface {struct usb_anchor out_anchor;struct gip_urb out_queue[MAX_OUT_MESSAGES ]; + +struct work_struct send_fragment; +unsigned int has_pending_out; };struct gip_device {
Signature · 1 line
2.54.0
PATCH v5 7/12 Input: xbox_gip - Add security implementation from xone
In reply to Vicki PfauThis patch imports and adapts the security message implementation from the out-of-tree xone driver, which is licensed under the GPL 2.0. This message is necessary for most controllers that use wireless dongles. The implementation is largely unchanged, with minor changes being made to adapt it to the xbox_gip driver and renaming components as appropriate for the official terminology from the released spec.
--- drivers/input/joystick/gip/Kconfig | 2 +- drivers/input/joystick/gip/Makefile | 2 +- drivers/input/joystick/gip/gip-core.c | 48 +- drivers/input/joystick/gip/gip-drivers.c | 8 + drivers/input/joystick/gip/gip-security.c | 795 ++++++++++++++++++++++ drivers/input/joystick/gip/gip.h | 54 +- 6 files changed, 883 insertions(+), 26 deletions(-) create mode 100644 drivers/input/joystick/gip/gip-security.c
drivers/input/joystick/gip/Kconfig +1 -1
@@ -4,7 +4,7 @@ # config JOYSTICK_XBOX_GIP tristate "Xbox One/Series controller support" - depends on USB && USB_ARCH_HAS_HCD && LEDS_CLASS_MULTICOLOR + depends on USB && USB_ARCH_HAS_HCD && LEDS_CLASS_MULTICOLOR && CRYPTO_ECDH help Say Y here if you want to use Xbox One and Series controllers with your computer. Make sure to say Y to "Joystick support" (CONFIG_INPUT_JOYDEV)
drivers/input/joystick/gip/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-or-later obj-$(CONFIG_JOYSTICK_XBOX_GIP) += xbox-gip.o # Base driver -xbox-gip-y := gip-core.o gip-drivers.o +xbox-gip-y := gip-core.o gip-drivers.o gip-security.o
drivers/input/joystick/gip/gip-core.c +25 -23
96 lines not on this page · raw message
drivers/input/joystick/gip/gip-drivers.c +8 -0
@@ -81,6 +81,14 @@ const struct gip_driver gip_driver_gamepad = { 0xa3, 0x12, 0x7a, 0xf1, 0x97, 0xb5), .quirks = (const struct gip_quirks []) { +/* PowerA Xbox One Classic Controller */ + {GIP_VID_BDA ,GIP_PID_BDA_XB1_CLASSIC ,0 , + .quirks =GIP_QUIRK_SKIP_SECURITY }, + +/* PowerA Xbox One Fusion Pro */ + {GIP_VID_BDA ,GIP_PID_BDA_XB1_FUSION_PRO ,0 , + .quirks =GIP_QUIRK_SKIP_SECURITY }, +/* Xbox One Controller (model 1573) */ {GIP_VID_MICROSOFT ,GIP_PID_XBOX_ONE_1573 ,0 , .override_name ="Xbox One Controller" },
drivers/input/joystick/gip/gip-security.c new file +795 -0
795 lines not on this page · raw message
drivers/input/joystick/gip/gip.h +53 -1
117 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v5 8/12 Input: xbox_gip - Add arcade stick support
In reply to Vicki PfauThis adds support for the arcade stick device type. Currently I'm only aware of one Xbox controller that uses this device type, the Razer Atrox, so testing coverage is limited.
--- drivers/input/joystick/gip/Makefile | 2 + drivers/input/joystick/gip/gip-arcade-stick.c | 173 ++++++++++++++++++ drivers/input/joystick/gip/gip-core.c | 6 +- drivers/input/joystick/gip/gip.h | 4 +- 4 files changed, 181 insertions(+), 4 deletions(-) create mode 100644 drivers/input/joystick/gip/gip-arcade-stick.c
drivers/input/joystick/gip/Makefile +2 -0
@@ -2,3 +2,5 @@ obj-$(CONFIG_JOYSTICK_XBOX_GIP) += xbox-gip.o # Base driver xbox-gip-y := gip-core.o gip-drivers.o gip-security.o +# Additional device support +xbox-gip-y += gip-arcade-stick.o
drivers/input/joystick/gip/gip-arcade-stick.c new file +173 -0
173 lines not on this page · raw message
drivers/input/joystick/gip/gip-core.c +4 -2
@@ -10,7 +10,8 @@* - Raw character device * - Wheel support * - Flight stick support -* - Arcade stick support +* - More arcade stick testing +* - Arcade stick extra buttons * - Split into driver-per-attachment GIP-as-a-bus approach drivers * * This driver is based on the Microsoft GIP spec at:
@@ -328,6 +329,7 @@ struct gip_direct_motor {static const struct gip_driver *base_drivers[] = { &gip_driver_navigation, &gip_driver_gamepad, + &gip_driver_arcade_stick,NULL /* Sentinel */ };
@@ -1566,7 +1568,7 @@ static int gip_handle_command_raw_report(struct gip_attachment *attachment,return 0 ; } -static int gip_setup_input_device (struct gip_attachment *attachment) +int gip_setup_input_device (struct gip_attachment *attachment) {struct input_dev *input;int rc;
drivers/input/joystick/gip/gip.h +2 -2
@@ -403,6 +403,8 @@ static inline struct device *gip_security_dev(struct gip_security *security) return gip_attachment_dev(container_of(security, struct gip_attachment, security)); } +int gip_setup_input_device (struct gip_attachment *attachment); +bool gip_supports_vendor_message (struct gip_attachment *attachment,uint8_t command,bool upstream); int gip_send_system_message(struct gip_attachment *attachment,
@@ -418,6 +420,4 @@ void gip_security_release(struct gip_security *security);extern const struct gip_driver gip_driver_navigation;extern const struct gip_driver gip_driver_gamepad;extern const struct gip_driver gip_driver_arcade_stick; -extern const struct gip_driver gip_driver_wheel; -extern const struct gip_driver gip_driver_flight_stick;#endif
Signature · 1 line
2.54.0
PATCH v5 9/12 Input: xbox_gip - Add support for PDP guitar controllers
In reply to Vicki PfauThis patch adds support for the PDP guitar controllers, namely the Fender Jaguar and RiffMaster models. These use mostly the same protocol, but the RiffMaster appears t use a slightly newer variant.
--- drivers/input/joystick/gip/Makefile | 1 + drivers/input/joystick/gip/gip-core.c | 1 + drivers/input/joystick/gip/gip-pdp-jaguar.c | 129 ++++++++++++++++++++ drivers/input/joystick/gip/gip.h | 2 + 4 files changed, 133 insertions(+) create mode 100644 drivers/input/joystick/gip/gip-pdp-jaguar.c
drivers/input/joystick/gip/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-$(CONFIG_JOYSTICK_XBOX_GIP) += xbox-gip.o xbox-gip-y := gip-core.o gip-drivers.o gip-security.o # Additional device support xbox-gip-y += gip-arcade-stick.o +xbox-gip-y += gip-pdp-jaguar.o
drivers/input/joystick/gip/gip-core.c +1 -0
@@ -330,6 +330,7 @@ static const struct gip_driver *base_drivers[] = { &gip_driver_navigation, &gip_driver_gamepad, &gip_driver_arcade_stick, + &gip_driver_pdp_jaguar, NULL /* Sentinel */ };
drivers/input/joystick/gip/gip-pdp-jaguar.c new file +129 -0
129 lines not on this page · raw message
drivers/input/joystick/gip/gip.h +2 -0
@@ -41,6 +41,7 @@#define GIP_PID_XBOX_WIRELESS 0x0b12#define GIP_PID_PDP_ROCK_CANDY 0x0246 +#define GIP_PID_PDP_RIFFMASTER 0x0248#define GIP_PID_BDA_XB1_CLASSIC 0x581a#define GIP_PID_BDA_XB1_FUSION_PRO 0x591a
@@ -420,4 +421,5 @@ void gip_security_release(struct gip_security *security);extern const struct gip_driver gip_driver_navigation;extern const struct gip_driver gip_driver_gamepad;extern const struct gip_driver gip_driver_arcade_stick; +extern const struct gip_driver gip_driver_pdp_jaguar;#endif
Signature · 1 line
2.54.0
PATCH v5 10/12 Input: Add ABS_CLUTCH, HANDBRAKE, and SHIFTER
In reply to Vicki PfauAdd new absolute axes for racing game controllers
--- drivers/hid/hid-debug.c | 16 +++++++++------- include/uapi/linux/input-event-codes.h | 3 +++ 2 files changed, 12 insertions(+), 7 deletions(-)
drivers/hid/hid-debug.c +9 -7
@@ -3511,13 +3511,15 @@ static const char *absolutes[ABS_CNT] = { [ABS_RY] = "Ry", [ABS_RZ] = "Rz", [ABS_THROTTLE] = "Throttle", [ABS_RUDDER] = "Rudder", [ABS_WHEEL] = "Wheel", [ABS_GAS] = "Gas", - [ABS_BRAKE] = "Brake", [ABS_HAT0X] = "Hat0X", - [ABS_HAT0Y] = "Hat0Y", [ABS_HAT1X] = "Hat1X", - [ABS_HAT1Y] = "Hat1Y", [ABS_HAT2X] = "Hat2X", - [ABS_HAT2Y] = "Hat2Y", [ABS_HAT3X] = "Hat3X", - [ABS_HAT3Y] = "Hat 3Y", [ABS_PRESSURE] = "Pressure", - [ABS_DISTANCE] = "Distance", [ABS_TILT_X] = "XTilt", - [ABS_TILT_Y] = "YTilt", [ABS_TOOL_WIDTH] = "ToolWidth", + [ABS_BRAKE] = "Brake", [ABS_CLUTCH] = "Clutch", + [ABS_HANDBRAKE] = "Handbrake", [ABS_SHIFTER] = "Shifter", + [ABS_HAT0X] = "Hat0X", [ABS_HAT0Y] = "Hat0Y", + [ABS_HAT1X] = "Hat1X", [ABS_HAT1Y] = "Hat1Y", + [ABS_HAT2X] = "Hat2X", [ABS_HAT2Y] = "Hat2Y", + [ABS_HAT3X] = "Hat3X", [ABS_HAT3Y] = "Hat3Y", + [ABS_PRESSURE] = "Pressure", [ABS_DISTANCE] = "Distance", + [ABS_TILT_X] = "XTilt", [ABS_TILT_Y] = "YTilt", + [ABS_TOOL_WIDTH] = "ToolWidth", [ABS_VOLUME] = "Volume", [ABS_PROFILE] = "Profile", [ABS_SND_PROFILE] = "SoundProfile", [ABS_MISC] = "Misc",
include/uapi/linux/input-event-codes.h +3 -0
@@ -879,6 +879,9 @@#define ABS_WHEEL 0x08#define ABS_GAS 0x09#define ABS_BRAKE 0x0a +#define ABS_CLUTCH 0x0b +#define ABS_HANDBRAKE 0x0c +#define ABS_SHIFTER 0x0d#define ABS_HAT0X 0x10#define ABS_HAT0Y 0x11#define ABS_HAT1X 0x12
Signature · 1 line
2.54.0
PATCH v5 11/12 HID: Map more automobile simulation inputs
In reply to Vicki PfauThe HID usage tables section 5.3 specify clutch and shifter values that had previously been ignored. As the ABS_CLUTCH and ABS_SHIFTER bits now exist, we should use them appropriately.
--- drivers/hid/hid-input.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/hid/hid-input.c +2 -0
@@ -828,6 +828,8 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fielcase 0xbb :map_abs (ABS_THROTTLE );break ;case 0xc4 :map_abs (ABS_GAS );break ;case 0xc5 :map_abs (ABS_BRAKE );break ; +case 0xc6 :map_abs (ABS_CLUTCH );break ; +case 0xc7 :map_abs (ABS_SHIFTER );break ;case 0xc8 :map_abs (ABS_WHEEL );break ;default : goto ignore; }
Signature · 1 line
2.54.0
PATCH v5 12/12 Input: xbox_gip - Add wheel support
In reply to Vicki PfauThis adds preliminary support for racing wheel support in xbox_gip, exposing them mapped to the newly added axes.
--- drivers/input/joystick/gip/Makefile | 1 + drivers/input/joystick/gip/gip-core.c | 4 +- drivers/input/joystick/gip/gip-drivers.c | 10 + drivers/input/joystick/gip/gip-wheel.c | 349 +++++++++++++++++++++++ drivers/input/joystick/gip/gip.h | 6 + 5 files changed, 369 insertions(+), 1 deletion(-) create mode 100644 drivers/input/joystick/gip/gip-wheel.c
drivers/input/joystick/gip/Makefile +1 -0
@@ -5,3 +5,4 @@ xbox-gip-y := gip-core.o gip-drivers.o gip-security.o # Additional device support xbox-gip-y += gip-arcade-stick.o xbox-gip-y += gip-pdp-jaguar.o +xbox-gip-y += gip-wheel.o
drivers/input/joystick/gip/gip-core.c +3 -1
@@ -8,7 +8,7 @@* - Audio device support * - Event logging * - Raw character device -* - Wheel support +* - Wheel force feedback * - Flight stick support * - More arcade stick testing * - Arcade stick extra buttons
@@ -331,6 +331,8 @@ static const struct gip_driver *base_drivers[] = { &gip_driver_gamepad, &gip_driver_arcade_stick, &gip_driver_pdp_jaguar, + &gip_driver_trueforce_wheel, + &gip_driver_wheel, NULL /* Sentinel */ };
drivers/input/joystick/gip/gip-drivers.c +10 -0
@@ -142,6 +142,11 @@ static int gip_setup_navigation_input(struct gip_attachment *attachment, structinput_set_capability (input,EV_KEY ,BTN_TR );input_set_capability (input,EV_KEY ,BTN_TL ); +if (attachment->quirks &GIP_QUIRK_FORCE_GAMEPAD_SB ) { +input_set_capability (input,EV_KEY ,BTN_THUMBR ); +input_set_capability (input,EV_KEY ,BTN_THUMBL ); + } + attachment->dpad_as_buttons = dpad_as_buttons;if (attachment->dpad_as_buttons) {input_set_capability (input,EV_KEY ,BTN_DPAD_UP );
@@ -193,6 +198,11 @@ static int gip_handle_navigation_report(struct gip_attachment *attachment,input_report_key (input,BTN_TR , bytes[1 ] &BIT (5 )); } +if (attachment->quirks &GIP_QUIRK_FORCE_GAMEPAD_SB ) { +input_report_key (input,BTN_THUMBL , bytes[1 ] &BIT (6 )); +input_report_key (input,BTN_THUMBR , bytes[1 ] &BIT (7 )); + } +return 0 ; }
drivers/input/joystick/gip/gip-wheel.c new file +349 -0
349 lines not on this page · raw message
drivers/input/joystick/gip/gip.h +6 -0
@@ -28,10 +28,13 @@#define MAX_OUT_MESSAGES 8#define MAX_OUT_FRAGMENTS 2 +#define GIP_VID_THRUSTMASTER 0x044f#define GIP_VID_MICROSOFT 0x045e#define GIP_VID_PDP 0x0e6f#define GIP_VID_BDA 0x24c6 +#define GIP_PID_THRUSTMASTER_T128X 0xb69c +#define GIP_PID_XBOX_ONE_1573 0x02d1#define GIP_PID_XBOX_ONE_1697 0x02dd#define GIP_PID_XBOX_ELITE 0x02e3
@@ -50,6 +53,7 @@#define GIP_QUIRK_NO_IMPULSE_VIBRATION BIT(1)#define GIP_QUIRK_SWAP_LB_RB BIT(2)#define GIP_QUIRK_SKIP_SECURITY BIT(3) +#define GIP_QUIRK_FORCE_GAMEPAD_SB BIT(4)/* * Driver-specific quirks should start from 31 and go downwards to avoid * conflicts with newly-added core quirks
@@ -422,4 +426,6 @@ extern const struct gip_driver gip_driver_navigation;extern const struct gip_driver gip_driver_gamepad;extern const struct gip_driver gip_driver_arcade_stick;extern const struct gip_driver gip_driver_pdp_jaguar; +extern const struct gip_driver gip_driver_wheel; +extern const struct gip_driver gip_driver_trueforce_wheel;#endif
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v5 06/12] Input: xbox_gip - Allow sending fragmented and ACME messages
In reply to Vicki PfauThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [Critical] Unconditional dereference of NULL fragment pointer on error path for non-fragmented messages.…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Critical] Unconditional dereference of NULL fragment pointer on error path for non-fragmented messages.
- [High] Missing synchronization when allocating and initializing out_fragments slots.
- [High] Unsynchronized read-modify-write of the intf->has_pending_out bitmask.
- [High] Dropped ACKs permanently leak out_fragments slots.
--
commit 317888ee9cccdc0f09f7f1c8d616d2664382777a
Author: Vicki Pfau <[email protected]>
Input: xbox_gip - Allow sending fragmented and ACME messages
This commit introduces support for sending fragmented messages that exceed the MTU length and messages requiring ACKs using the ACME flag in the GIP protocol. It adds queuing, processing, and acknowledgment handling logic to the xbox_gip driver.
Quoted 4 lines
drivers/input/joystick/gip/gip-core.c +0
-0
[ ... ]
Quoted 5 lines
drivers/input/joystick/gip/gip-core.c +5
-0+static void gip_free_fragment (struct gip_out_fragment *fragment) +{ +kfree (fragment->data); +memset (fragment,0 ,sizeof (*fragment)); +}
[ ... ]
Quoted 10 lines
static int gip_send_raw_message(struct
gip_attachment*attachment,drivers/input/joystick/gip/gip-core.c +1
-0uint8_t message_type, uint8_t flags, uint8_t seq, const uint8_t *bytes, int num_bytes)@@ -486,20 +529,25 @@ static int gip_send_raw_message(struct gip_attachment *attachment,struct gip_interface *intf;int offset =3 ;struct gip_urb *urb =NULL ; +struct gip_out_fragment *fragment =NULL ;int i;int rc =0 ;
[ ... ]
drivers/input/joystick/gip/gip-core.c static int gip_send_raw_message(struct gip_attachment *attachment, · line 573
Quoted 9 lines
drivers/input/joystick/gip/gip-core.c +9
-0+if (num_bytes > reduced_mtu || + (flags & (GIP_FLAG_ACME |GIP_FLAG_FRAGMENT )) ==GIP_FLAG_ACME ) { +for (i =0 ; i <MAX_OUT_FRAGMENTS ; i++) { +if (attachment->out_fragments[i].active) +continue ; + + fragment = &attachment->out_fragments[i]; +break ; + }
[Severity: High]
Does this code have a missing synchronization issue?
The fragment slot is claimed and initialized locklessly here. If concurrent callers (like force feedback workers, sysfs, or incoming message handlers) pick the same inactive slot, could this lead to double-allocation (a memory leak) and state corruption?
drivers/input/joystick/gip/gip-core.c static int gip_send_raw_message(struct gip_attachment *attachment, · line 583
Quoted 10 lines
drivers/input/joystick/gip/gip-core.c +10
-0+ +if (!fragment) { +gip_err (attachment,"Fragmented message queue is full; dropping message\n" ); +return -EALREADY ; + } + + fragment->data =kmalloc (num_bytes,GFP_KERNEL ); +if (!fragment->data) +return -ENOMEM ; + fragment->active = true;
[Severity: High]
Can these out_fragments slots permanently leak if ACKs are dropped?
When an outgoing message requires an ACK, the slot is marked active here and relies entirely on a device-initiated ACK to be freed. Because there is no timeout mechanism, if the device drops the message or fails to respond, could the slot remain locked forever? Since MAX_OUT_FRAGMENTS is only 2, a couple of dropped packets might permanently exhaust the queue.
[ ... ]
Quoted 3 lines
drivers/input/joystick/gip/gip-core.c +0
-0guard (spinlock_irqsave)(&attachment->device->message_lock);for (i =0 ; i <MAX_OUT_MESSAGES && !urb; i++) {if (!intf->out_queue[i].urb)
[ ... ]
Quoted 8 lines
drivers/input/joystick/gip/gip-core.c +8
-0+if (fragment) { +/* +* Sending further fragments is handled in gip_urb_out if this fragment doesn't need +* ACKing or in gip_handle_command_protocol_control if it does. The flag should also +* be cleared if we're done sending this packet. +*/ +if (fragment->total_length > reduced_mtu && !(flags &GIP_FLAG_ACME )) + intf->has_pending_out |=gip_fragment_id (attachment, fragment);
drivers/input/joystick/gip/gip-core.c static int gip_send_raw_message(struct gip_attachment *attachment, · line 696
Quoted 10 lines
drivers/input/joystick/gip/gip-core.c +7
-0+else + intf->has_pending_out &= ~gip_fragment_id (attachment, fragment); }return rc; + +err_free_fragment: +gip_free_fragment (fragment); +return rc; +}
[Severity: Critical]
Does this error path unconditionally dereference a NULL pointer?
If gip_send_raw_message() is called for a standard, non-fragmented message, the fragment pointer remains NULL. If the output queue is full or usb_submit_urb() fails, the function jumps to err_free_fragment and calls gip_free_fragment().
Since gip_free_fragment() unconditionally accesses fragment->data and calls memset(fragment, ...), won't this immediately crash the kernel when fragment is NULL?
[ ... ]
Quoted 4 lines
drivers/input/joystick/gip/gip-core.c +4
-0+static int gip_send_next_fragment (struct gip_attachment *attachment, +struct gip_out_fragment *fragment) +{ +struct gip_interface *intf;
[ ... ]
drivers/input/joystick/gip/gip-core.c static int gip_send_raw_message(struct gip_attachment *attachment, · line 715
Quoted 8 lines
drivers/input/joystick/gip/gip-core.c +8
-0+if (fragment->fragment_offset == fragment->total_length) { +if ((fragment->message &GIP_DATA_CLASS_MASK ) ==GIP_DATA_CLASS_AUDIO ) + intf = &attachment->device->audio; +else + intf = &attachment->device->data; + + next_bytes =0 ; + intf->has_pending_out &= ~gip_fragment_id (attachment, fragment);
[Severity: High]
Is there an unsynchronized read-modify-write data race here?
Here in gip_send_next_fragment(), intf->has_pending_out is updated without holding message_lock. However, as seen in gip_send_raw_message(), this shared bitmask is also modified under message_lock.
Could concurrent updates to this shared variable cause lost updates, permanently stalling fragment transmission for any attachments whose bits get lost?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
[email protected]
AI reviewRe: [PATCH v5 07/12] Input: xbox_gip - Add security implementation from xone
In reply to Vicki PfauThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
New issues:
- [High] Stack-allocated buffers are used for cryptographic scatterlists, violating DMA constraints and causing kernel panics on architectures with virtually mapped stacks.
- [High] An ABBA deadlock occurs between attachment->lock and cancel_work_sync() during device teardown or reset.
- [Medium] The driver utilizes CRYPTO_LIB_SHA256 and CRYPTO_RSA but lacks the required Kconfig declarations, which can lead to build and runtime failures.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but incorrect teardown order in gip_disconnect() allows the URB completion handler to re-queue a work item after it was cancelled, leading to a Use-After-Free. --
commit 0028f224002448741826a03077075da976d732d6
Author: Vicki Pfau <[email protected]>
Subject: Input: xbox_gip - Add security implementation from xone
This patch imports and adapts the security message implementation from the out-of-tree xone driver. This message is necessary for most controllers that use wireless dongles. The implementation hooks into the xbox_gip driver to handle security commands.
drivers/input/joystick/gip/Kconfig line 7
Quoted 10 lines
drivers/input/joystick/gip/Kconfig +1
-1@@ -4,7 +4,7 @@ # config JOYSTICK_XBOX_GIP tristate "Xbox One/Series controller support" - depends on USB && USB_ARCH_HAS_HCD && LEDS_CLASS_MULTICOLOR + depends on USB && USB_ARCH_HAS_HCD && LEDS_CLASS_MULTICOLOR && CRYPTO_ECDH
[Severity: Medium]
This patch introduces a dependency on CRYPTO_LIB_SHA256 and CRYPTO_RSA (used in gip-security.c), but these are missing from the Kconfig depends block. Can this lead to build and runtime failures when compiling without these crypto options, or when a device requiring the security handshake connects?
Quoted 3 lines
drivers/input/joystick/gip/Kconfig +0
-0help Say Y here if you want to use Xbox One and Series controllers with your computer. Make sure to say Y to "Joystick support" (CONFIG_INPUT_JOYDEV)
[ ... ]
Quoted 4 lines
drivers/input/joystick/gip/gip-core.c +0
-0
[ ... ]
drivers/input/joystick/gip/gip-core.c static void gip_free_devices(struct gip_attachment *attachment) · line 1801
Quoted 6 lines
drivers/input/joystick/gip/gip-core.c +2
-0@@ -1809,6 +1797,8 @@ static void gip_free_devices(struct gip_attachment *attachment)struct input_dev *input;struct hid_device *hdev; +gip_security_release (&attachment->security); +
[Severity: High]
This is a pre-existing issue, but the teardown order in the pre-existing gip_disconnect() function appears to cancel work items before stopping the USB URB.
gip_disconnect() calls gip_shutdown() (which eventually calls gip_security_release() here), and only afterwards calls usb_kill_urb(). If the incoming URB completes in this window, it can process messages and re-queue the cancelled work items (e.g., work_exchange_rsa).
After the device is freed by devres, can the re-queued work item execute and dereference freed pointers, leading to a Use-After-Free?
Quoted 2 lines
drivers/input/joystick/gip/gip-core.c +0
-0if (attachment->driver && attachment->driver->remove) attachment->driver->remove (attachment);
[ ... ]
Quoted 5 lines
drivers/input/joystick/gip/gip-security.c new file +0
-0
[ ... ]
Quoted 4 lines
drivers/input/joystick/gip/gip-security.c new file +4
-0+static int gip_security_ecdh_get_secret (struct crypto_kpp *tfm,u8 *pubkey, +int pubkey_len,u8 *secret,int secret_len) +{ +struct kpp_request *req;
drivers/input/joystick/gip/gip-security.c line 313
Quoted 10 lines
drivers/input/joystick/gip/gip-security.c new file +10
-0+struct scatterlist src, dest; +DECLARE_CRYPTO_WAIT (wait); +int err; + + req =kpp_request_alloc (tfm,GFP_KERNEL ); +if (!req) +return -ENOMEM ; + +sg_init_one (&src, pubkey, pubkey_len); +sg_init_one (&dest, secret, secret_len);
[Severity: High]
Does this code use a stack-allocated buffer (secret) for a cryptographic scatterlist? Passing stack memory to sg_init_one() violates DMA constraints and can cause a kernel panic/Oops (due to BUG_ON(!virt_addr_valid(buf))) on architectures with virtually mapped stacks.
Quoted 2 lines
drivers/input/joystick/gip/gip-security.c new file +2
-0+kpp_request_set_input (req, &src, pubkey_len); +kpp_request_set_output (req, &dest, secret_len);
[ ... ]
Quoted 18 lines
drivers/input/joystick/gip/gip-security.c new file +18
-0+static int gip_security_compute_ecdh (u8 *pubkey_in,u8 *pubkey_out,int pubkey_len,u8 *secret_hash) +{ +struct crypto_kpp *tfm_ecdh; +u8 secret[GIP_SECURITY_ECDH_SECRET_LEN ] = {0 }; +int err; + + tfm_ecdh =crypto_alloc_kpp ("ecdh-nist-p256" ,0 ,0 ); +if (IS_ERR (tfm_ecdh)) { + err =PTR_ERR (tfm_ecdh); + goto err_free_secret; + } + + err =gip_security_ecdh_get_pubkey (tfm_ecdh, pubkey_out, pubkey_len); +if (err) + goto err_free_ecdh; + + err =gip_security_ecdh_get_secret (tfm_ecdh, pubkey_in, pubkey_len, + secret,sizeof (secret));
[ ... ]
Quoted 9 lines
drivers/input/joystick/gip/gip-security.c new file +9
-0+static void gip_security_exchange_rsa (struct work_struct *work) +{ +struct gip_security *security =container_of (work,typeof (*security), work_exchange_rsa); + struct gip_attachment *attachment = container_of(security, struct gip_attachment, security); +struct gip_security_host_secret message = {}; +u8 random[GIP_SECURITY_RANDOM_LEN *2 ]; +int err; + +guard (mutex)(&attachment->lock);
[ ... ]
drivers/input/joystick/gip/gip-security.c line 753
Quoted 6 lines
drivers/input/joystick/gip/gip-security.c new file +6
-0+void gip_security_release (struct gip_security *security) +{ +if (security->status <GIP_SECURITY_SENT ) +return ; + +cancel_work_sync (&security->work_exchange_rsa);
[Severity: High]
Can this cause an ABBA deadlock during device teardown?
During hot-unplug, gip_shutdown() in gip-core.c acquires attachment->lock and then calls gip_security_release(), which synchronously waits for the work item using cancel_work_sync().
Simultaneously, the running gip_security_exchange_rsa() work item blocks trying to acquire the same attachment->lock mutex.
Quoted 7 lines
drivers/input/joystick/gip/gip-security.c new file +7
-0+cancel_work_sync (&security->work_exchange_ecdh); +cancel_work_sync (&security->work_complete); + +memzero_explicit (&security->transcript,sizeof (security->transcript)); + + security->status =GIP_SECURITY_PENDING ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
[email protected]
AI reviewRe: [PATCH v5 05/12] Input: xbox_gip - Add battery support
In reply to Vicki PfauThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Devres actions on `input->dev` are delayed until userspace drops all references, causing the power…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Devres actions on input->dev are delayed until userspace drops all references, causing the power supply to outlive the attachment structure and resulting in a Use-After-Free.
- [High] Manually unregistering a devm-managed power supply and freeing its name on an error path leads to a double-unregister and UAF when devres cleanup executes. --
commit 7a0e19630adf51b35545780bfe01529fdc2adba8
Author: Vicki Pfau <[email protected]>
Input: xbox_gip - Add battery support
This commit adds battery support to the xbox_gip driver by exposing the controller's battery information as a power_supply device.
Quoted 3 lines
drivers/input/joystick/gip/gip-core.c +0
-0
[ ... ]
Quoted 1 line
drivers/input/joystick/gip/gip-core.c +0
-0@@ -1199,6 +1206,106 @@ static int gip_guide_led_probe(struct gip_attachment *attachment, struct device
[ ... ]
Quoted 4 lines
drivers/input/joystick/gip/gip-core.c +4
-0+static int gip_battery_create (struct gip_attachment *attachment,struct device *dev) +{ +struct power_supply_config supply_config = { .drv_data = attachment, }; +int rc;
[ ... ]
drivers/input/joystick/gip/gip-core.c static int gip_guide_led_probe(struct gip_attachment *attachment, struct device · line 1299
Quoted 12 lines
drivers/input/joystick/gip/gip-core.c +12
-0+ attachment->battery =devm_power_supply_register (dev, + &attachment->battery_desc, &supply_config); +if (IS_ERR (attachment->battery)) { + rc =PTR_ERR (attachment->battery); + goto err_out; + } + + rc =power_supply_powers (attachment->battery, dev); +if (rc <0 ) { +power_supply_unregister (attachment->battery); + goto err_out; + }
[Severity: High]
Because attachment->battery was allocated using devm_power_supply_register(), a devres action is already queued to unregister it. If power_supply_powers() fails and we manually call power_supply_unregister() here, will devres attempt to unregister it again later when the input device is cleaned up, leading to a double-free?
[ ... ]
drivers/input/joystick/gip/gip-core.c static void gip_free_devices(struct gip_attachment *attachment) · line 1609
Quoted 7 lines
drivers/input/joystick/gip/gip-core.c +2
-0@@ -1494,6 +1604,8 @@ static void gip_free_devices(struct gip_attachment *attachment)rcu_assign_pointer (attachment->input,NULL );rcu_assign_pointer (attachment->hdev,NULL ); +/* The following are freed by devres */ + attachment->battery =NULL ;synchronize_rcu ();
[Severity: High]
The battery was registered with devm using the input device (input->dev). Since input device devres actions are delayed until userspace drops all evdev file descriptor references, does setting attachment->battery to NULL here leave the power supply active after the driver disconnects?
If a user reads the sysfs attributes for the power supply after the device is unplugged, could gip_battery_get_property() attempt to access the freed attachment structure?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
[email protected]
AI reviewRe: [PATCH v5 03/12] Input: xbox_gip - Add controllable LED support
In reply to Vicki PfauThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] LED classdev remains registered after driver disconnect, leading to a Use-After-Free…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] LED classdev remains registered after driver disconnect, leading to a Use-After-Free vulnerability. --
commit c366b72f3332d21395d97672e39c1566b23f91d5
Author: Vicki Pfau <[email protected]>
Input: xbox_gip - Add controllable LED support
This commit adds controllable LED support for Xbox One controllers. It supports both monochrome white LEDs and RGBW addressable LEDs for Elite 2 controllers, exposing them as LED class devices.
Quoted 4 lines
drivers/input/joystick/gip/gip-core.c +0
-0
[ ... ]
Quoted 31 lines
drivers/input/joystick/gip/gip-core.c +31
-0+static int gip_guide_led_probe (struct gip_attachment *attachment,struct device *dev) +{ +int rc =0 ; + +if (!gip_supports_system_message (attachment,GIP_CMD_LED , false)) +return 0 ; + +if (attachment->features &GIP_FEATURE_GUIDE_COLOR ) { +struct mc_subled *mc_led_info; +struct led_classdev_mc *mc_cdev = &attachment->guide_led.color; +struct led_classdev *cdev = &mc_cdev->led_cdev; + + mc_led_info =devm_kcalloc (dev,4 , +sizeof (*mc_led_info),GFP_KERNEL ); +if (!mc_led_info) +return -ENOMEM ; + + mc_led_info[0 ].color_index =LED_COLOR_ID_RED ; + mc_led_info[0 ].intensity =51 ; + mc_led_info[1 ].color_index =LED_COLOR_ID_GREEN ; + mc_led_info[1 ].intensity =51 ; + mc_led_info[2 ].color_index =LED_COLOR_ID_BLUE ; + mc_led_info[2 ].intensity =51 ; + mc_led_info[3 ].color_index =LED_COLOR_ID_WHITE ; + mc_led_info[3 ].intensity =51 ; + + mc_cdev->subled_info = mc_led_info; + mc_cdev->num_colors =4 ; + + cdev->brightness =51 ; + cdev->max_brightness =255 ;
drivers/input/joystick/gip/gip-core.c static int gip_send_guide_button_led(struct gip_attachment *attachment, · line 1129
Quoted 10 lines
drivers/input/joystick/gip/gip-core.c +10
-0+ cdev->flags =LED_CORE_SUSPENDRESUME |LED_RETAIN_AT_SHUTDOWN ; + cdev->brightness_set_blocking = gip_guide_color_led_set; + cdev->name =devm_kasprintf (dev,GFP_KERNEL , +"%s:rgb:power" ,dev_name (dev)); +if (!cdev->name) + rc = -ENOMEM ; + +if (!rc) + rc =devm_led_classdev_multicolor_register (dev, + mc_cdev);
[Severity: High]
Does binding this LED to the input device's lifecycle cause a use-after-free if the controller is disconnected while an input event node is still open?
Since the devres action for unregistering the LED is bound to the input device (&input->dev), the LED will remain registered as long as userspace holds an evdev file descriptor open.
However, during driver unbind, gip_disconnect() calls:devm_kfree(to_gip_device(attachment), attachment);
This immediately frees the attachment structure containing the registered led_classdev and led_classdev_mc structures. Subsequent accesses to the LED's sysfs attributes (such as changing brightness via gip_guide_color_led_set) would then dereference this freed memory.
Should this register against the physical device instead, such as to_gip_device(attachment), to ensure the LED is unregistered synchronously during driver unbind?
[ ... ]
drivers/input/joystick/gip/gip-core.c static int gip_send_guide_button_led(struct gip_attachment *attachment, · line 1145
Quoted 13 lines
drivers/input/joystick/gip/gip-core.c +13
-0+ }else { +struct led_classdev *cdev = &attachment->guide_led.standard; + + cdev->max_brightness =GIP_LED_GUIDE_MAX_BRIGHTNESS ; + cdev->brightness =GIP_LED_GUIDE_INIT_BRIGHTNESS ; + cdev->flags =LED_CORE_SUSPENDRESUME |LED_RETAIN_AT_SHUTDOWN ; + cdev->brightness_set_blocking = gip_guide_led_set; + cdev->name =devm_kasprintf (dev,GFP_KERNEL , +"%s:white:power" ,dev_name (dev)); +if (!cdev->name) +return -ENOMEM ; + + rc =devm_led_classdev_register (dev, cdev);
[Severity: High]
Can this similarly cause a use-after-free since the standard LED is also registered using the input device as the devres parent?
[ ... ]
drivers/input/joystick/gip/gip-core.c static int gip_setup_input_device(struct gip_attachment *attachment) · line 1264
Quoted 5 lines
drivers/input/joystick/gip/gip-core.c +1
-0@@ -1150,6 +1261,10 @@ static int gip_setup_input_device(struct gip_attachment *attachment)if (rc) goto err_free_device; + rc =gip_guide_led_probe (attachment, &input->dev);
[Severity: High]
By passing &input->dev instead of the physical device to gip_guide_led_probe(), the LED lifecycle becomes tied to the input device.
Input devices only run their devres actions when the last userspace reference is released. If the LED memory resides in attachment, shouldn't the LED be tied to the attachment's device so that unregistration happens before the attachment is freed?
Quoted 6 lines
drivers/input/joystick/gip/gip-core.c +3
-0+if (rc) +gip_err (attachment,"Failed to register LEDs: %d\n" , rc); +return 0 ; err_free_device:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH v5 04/12] Input: xbox_gip - Add HID relaying
In reply to Vicki PfauThank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
New issues:
- [Critical] gip_reset_metadata() frees hid_descriptor before destroying the HID device, allowing a concurrent UAF during HID probe.
- [High] Fragmented HID reports are processed with a payload size of 0, causing the entire assembled report to be truncated and silently dropped.
- [Medium] Useless synchronize_rcu() call delays device initialization.
- [Medium] The hid_device fields version, country, and uniq are not initialized before calling hid_add_device().
Pre-existing issues:
- [Critical] Use-after-free in receive worker due to incorrect shutdown ordering. --
commit e6352eb8b59489fd2119b2f3d053cfef65ac2c92
Author: Vicki Pfau <[email protected]>
Subject: Input: xbox_gip - Add HID relaying
This patch allows tunneling of HID packets by creating a hid_device for the HID descriptor embedded in the GIP metadata, and relays the packets.
Quoted 6 lines
drivers/input/joystick/gip/gip-core.c +0
-0@@ -560,6 +560,54 @@ int gip_send_vendor_message(struct gip_attachment *attachment, bytes, num_bytes);
drivers/input/joystick/gip/gip-core.c int gip_send_vendor_message(struct gip_attachment *attachment, · line 570
Quoted 10 lines
drivers/input/joystick/gip/gip-core.c +8
-0} +static int gip_hid_ll_parse (struct hid_device *hdev) +{ +struct gip_attachment *attachment = hdev->driver_data; + +return hid_parse_report (hdev, + attachment->metadata.device.hid_descriptor, + attachment->metadata.device.hid_descriptor_size); +}
[Severity: Critical]
Can this lead to a use-after-free during a concurrent HID probe?
If a device reset or hotplug occurs, gip_reset_metadata() frees the metadata before destroying the child devices:
gip_reset_metadata()
gip_metadata_free(to_gip_device(attachment), &attachment->metadata);
gip_free_devices(attachment);Since gip_metadata_free() synchronously frees hid_descriptor, if the HID core concurrently probes the device and calls gip_hid_ll_parse() before gip_free_devices() unregisters the HID device, it would dereference the freed descriptor memory.
[ ... ]
Quoted 25 lines
drivers/input/joystick/gip/gip-core.c +21
-0@@ -1303,6 +1351,48 @@ static int gip_init_input_device(struct gip_attachment *attachment)return rc; } +static int gip_create_hdev (struct gip_attachment *attachment) +{ +struct hid_device *hdev; +int rc; + +if (!attachment->metadata.device.hid_descriptor) +return 0 ; + +rcu_read_lock (); + hdev =rcu_dereference (attachment->hdev); +rcu_read_unlock (); +if (hdev) +return 0 ; + + hdev =hid_allocate_device (); + +if (IS_ERR (hdev)) +return PTR_ERR (hdev); + + hdev->ll_driver = &gip_hid_ll_driver; + hdev->bus =BUS_GIP ;
drivers/input/joystick/gip/gip-core.c static int gip_init_input_device(struct gip_attachment *attachment) · line 1384
Quoted 10 lines
drivers/input/joystick/gip/gip-core.c +10
-0+ hdev->vendor = attachment->vendor_id; + hdev->product = attachment->product_id; + hdev->dev.parent =to_gip_device (attachment); + hdev->driver_data = attachment; +if (attachment->name) +strscpy (hdev->name, attachment->name); +else +strscpy (hdev->name,"Xbox Chatpad" ); +strscpy (hdev->phys, attachment->phys); + rc =hid_add_device (hdev);
[Severity: Medium]
Are we missing the initialization of some standard hid_device fields here?
It appears that the version, country, and uniq fields are not populated before calling hid_add_device(). This might break userspace expectations that rely on these standard HID properties for device matching or configuration.
drivers/input/joystick/gip/gip-core.c static int gip_init_input_device(struct gip_attachment *attachment) · line 1391
Quoted 7 lines
drivers/input/joystick/gip/gip-core.c +7
-0+if (rc) { +gip_err (attachment,"HID device add failed: %d\n" , rc); +hid_destroy_device (hdev); + }else { +rcu_assign_pointer (attachment->hdev, hdev); +synchronize_rcu (); + }
[Severity: Medium]
Is this synchronize_rcu() call necessary on the successful allocation path?
Since we are publishing a new pointer where the previous value was NULL, there are no existing readers holding an old pointer that needs to be reclaimed. This seems to delay device initialization by a full RCU grace period unnecessarily.
[ ... ]
drivers/input/joystick/gip/gip-core.c static int gip_handle_command_firmware(struct gip_attachment *attachment, · line 1877
Quoted 13 lines
drivers/input/joystick/gip/gip-core.c +6
-2@@ -1768,9 +1868,17 @@ static int gip_handle_command_firmware(struct gip_attachment *attachment,static int gip_handle_command_hid_report (struct gip_attachment *attachment,const struct gip_header *header,uint8_t *bytes,int num_bytes) { -gip_warn (attachment,"Unimplemented HID report message\n" ); +struct hid_device *hdev; -return -EOPNOTSUPP ; +guard (rcu)(); + hdev =rcu_dereference (attachment->hdev); +if (hdev) +return hid_safe_input_report (hdev,HID_INPUT_REPORT , bytes, + num_bytes,umin (header->length, num_bytes), true);
[Severity: High]
Could this cause large fragmented HID reports to be silently dropped?
When gip_receive_fragment() reassembles a fragmented message, it completes upon receiving a terminator fragment where header->length is 0. It then calls gip_handle_message() using this final header.
If umin(header->length, num_bytes) is evaluated with header->length == 0, the payload size passed to hid_safe_input_report() will be 0, causing the entire reassembled HID report to be truncated.
drivers/input/joystick/gip/gip-core.c static int gip_handle_command_firmware(struct gip_attachment *attachment, · line 1882
Quoted 5 lines
drivers/input/joystick/gip/gip-core.c +4
-0+ +gip_warn (attachment,"Got HID report with no HID descriptor\n" ); + +return -EPROTO ; }
[ ... ]
[Severity: Critical]
This is a pre-existing issue, but is there a use-after-free risk in the receive worker due to incorrect shutdown ordering in gip_disconnect()?
Looking at gip_disconnect():
gip_shutdown(gip); ... usb_kill_urb(gip->data.urb_in);
The gip_shutdown() function synchronously cancels the receive worker. However, this happens before usb_kill_urb() is called. If an incoming URB completes right after cancel_work_sync() returns, gip_urb_in() could re-queue the worker.
When gip_disconnect() then proceeds to free the gip structure, the re-queued worker will execute gip_receive_work() and access the freed memory. Should the URBs be killed before cancelling the workers?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH v5 10/12] Input: Add ABS_CLUTCH, HANDBRAKE, and SHIFTER
In reply to Vicki PfauThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The hid-universal-pidff driver fails to adjust fuzz and deadzone for the newly added racing axes…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The hid-universal-pidff driver fails to adjust fuzz and deadzone for the newly added racing axes (ABS_CLUTCH, ABS_HANDBRAKE, ABS_SHIFTER). --
commit 6be790038ce1202a4794a1e9066e937b7c0b308a
Author: Vicki Pfau <[email protected]>
Input: Add ABS_CLUTCH, HANDBRAKE, and SHIFTER
This commit adds new absolute axes for racing game controllers.
[ ... ]
include/uapi/linux/input-event-codes.h line 884
Quoted 11 lines
include/uapi/linux/input-event-codes.h +3
-0@@ -879,6 +879,9 @@#define ABS_WHEEL 0x08#define ABS_GAS 0x09#define ABS_BRAKE 0x0a +#define ABS_CLUTCH 0x0b +#define ABS_HANDBRAKE 0x0c +#define ABS_SHIFTER 0x0d
[Severity: Medium]
Will this cause an issue with fuzz and deadzone adjustment for the newly added racing axes?
Looking at drivers/hid/hid-universal-pidff.c in universal_pidff_input_configured(), there is a loop that controls the fuzz and deadzone configuration for racing controllers:
/* Decrease fuzz and deadzone on available axes */
for (axis = ABS_X; axis <= ABS_BRAKE; axis++) {
if (!test_bit(axis, input->absbit))
continue;This loop stops at ABS_BRAKE, skipping the newly appended ABS_CLUTCH, ABS_HANDBRAKE, and ABS_SHIFTER axes.
High-resolution inputs for these newly added axes (like a clutch pedal or analog handbrake) will retain the HID input core's default large fuzz or deadzone values. This could lead to "steppy" input response and dropped small movements.
Does the loop in universal_pidff_input_configured() need to be updated to include these new axes?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
[email protected]
AI reviewRe: [PATCH v5 08/12] Input: xbox_gip - Add arcade stick support
In reply to Vicki PfauThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Missing `input_sync()` when discarding too-short reports, leaving events stuck in the input core…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Missing input_sync() when discarding too-short reports, leaving events stuck in the input core buffers. --
commit 11239c49a7f8de98682a983be88f926f7595b94d
Author: Vicki Pfau <[email protected]>
Input: xbox_gip - Add arcade stick support
This adds support for the arcade stick device type to the xbox_gip driver. Currently only the Razer Atrox controller is known to use this type.
Quoted 5 lines
drivers/input/joystick/gip/gip-arcade-stick.c new file +0
-0
[ ... ]
Quoted 7 lines
drivers/input/joystick/gip/gip-arcade-stick.c new file +7
-0+static int gip_handle_arcade_stick_report (struct gip_attachment *attachment, +struct input_dev *input,const uint8_t *bytes,int num_bytes) +{ +struct gip_arcade_stick_info *info = attachment->driver_data; +int rc; + +if (!info)
drivers/input/joystick/gip/gip-arcade-stick.c line 111
Quoted 10 lines
drivers/input/joystick/gip/gip-arcade-stick.c new file +10
-0+return -ENODEV ; + + rc = gip_driver_navigation.handle_input_report (attachment, input, bytes, num_bytes); +if (rc <0 ) +return rc; + +if (num_bytes <6 ) { +gip_dbg (attachment,"Discarding too-short input report\n" ); +return -EINVAL ; + }
[Severity: Medium]
When an input report is received with a length between 2 and 5 bytes, gip_driver_navigation.handle_input_report() successfully parses the first two bytes and calls input_report_key() and input_report_abs() to update the device state.
If num_bytes < 6, this error path in gip_handle_arcade_stick_report() returns -EINVAL before the device state can be synchronized. This error code is propagated back to the caller in drivers/input/joystick/gip/gip-core.c (gip_handle_ll_input_report()), which then immediately returns without calling input_sync(input).
Because of this early return, does the driver leave the reported key and axis events buffered in the input core without flushing them to userspace? Could this result in missed or delayed events if the hardware sends unexpectedly short event packets?
Quoted 5 lines
drivers/input/joystick/gip/gip-arcade-stick.c new file +5
-0+ +if (info->actuator_bias >0 ) { +input_report_abs (input,ABS_X ,get_unaligned_le16 (&bytes[2 ]) - info->actuator_bias); +input_report_abs (input,ABS_Y ,get_unaligned_le16 (&bytes[4 ]) - info->actuator_bias); + }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 17 potential issue(s) to consider: - [Critical] Failed `INIT_FRAG` validation leaves state desynchronized, leading to NULL pointer…
Thank you for your contribution! Sashiko AI review found 17 potential issue(s) to consider:
- [Critical] Failed INIT_FRAG validation leaves state desynchronized, leading to NULL pointer dereference.
- [Critical] Kernel panic due to NULL pointer dereference in gip_free_fragment during error handling.
- [High] Devm allocations bound to udev->dev instead of intf->dev cause memory leaks.
- [High] System suspend unregisters input devices, breaking userspace file descriptors.
- [High] Improper workqueue teardown order relative to URB killing causes Use-After-Free.
- [High] Race condition between fragment reception and timeout can incorrectly free a valid fragment buffer.
- [High] Undefined behavior due to unbounded bitwise shift in gip_decode_length.
- [High] Unreachable goto cleanup code in interface initialization causes memory leaks on failure.
- [High] Intermediate message fragments fail to advance fragment_offset, causing an infinite transmission loop.
- [High] Manual power_supply_unregister on a devm-managed power supply causes a double free.
- [High] Missing bounds check in gip_handle_elite_buttons leads to an out-of-bounds array read.
- [High] Data race on attachment creation during probe leads to duplicate allocation and memory leaks.
- [High] Unprotected state modifications during message transmission cause data races.
- [High] Manual devm_kfree of attachment in gip_disconnect causes UAF when sysfs callbacks run concurrently.
- [Medium] Early return in gip_parse_metadata leaks devres-allocated fields.
- [Medium] Anti-pattern: Using devres (devm_kmalloc) for per-message data buffers in the hot path.
- [Medium] Buffer overflow in gip_urb_in when copying URB data into a fixed 64-byte message queue. --
commit 6e5a9bf1d68de07f6142d692c36b2ce1b34a0cc6
Author: Vicki Pfau <[email protected]>
Subject: Input: xbox_gip - Add new driver for Xbox GIP
This introduces a new driver for the Xbox One/Series controller protocol, officially known as the Gaming Input Protocol, or GIP for short. It is based on the Microsoft GIP spec and provides features like fragmented message parsing and auto-detection via metadata.
Quoted 5 lines
drivers/input/joystick/gip/gip.h new file +1
-0@@ -0,0 +1,344 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */
[ ... ]
drivers/input/joystick/gip/gip.h line 320
Quoted 4 lines
drivers/input/joystick/gip/gip.h new file +4
-0+static inline struct device *gip_attachment_dev (struct gip_attachment *attachment) +{ +return &attachment->device->udev->dev; +}
[Severity: High]
Does this helper force all attachment devm allocations to be bound to the USB device instead of the interface?
If devm_input_allocate_device() or devm_kzalloc() use this device pointer, they will be bound to the parent udev->dev. When the driver is unbound from the interface (e.g., via sysfs), the devres actions attached to the interface will run, but those attached to the USB device will not, causing a persistent memory leak of driver structures and input devices.
Quoted 2 lines
drivers/input/joystick/gip/gip.h new file +2
-0+ +static inline struct device *gip_interface_dev (struct gip_interface *intf)
[ ... ]
Quoted 4 lines
drivers/input/joystick/gip/gip-core.c new file +0
-0@@ -0,0 +1,2591 @@
[ ... ]
drivers/input/joystick/gip/gip-core.c line 336
Quoted 9 lines
drivers/input/joystick/gip/gip-core.c new file +9
-0+static int gip_decode_length (uint64_t *length,const uint8_t *bytes,int num_bytes) +{ + *length =0 ; +int offset; + +for (offset =0 ; offset < num_bytes; offset++) { +uint8_t byte = bytes[offset]; + + *length |= (byte &0x7full ) << (offset *7 );
[Severity: High]
Can this bitwise shift result in undefined behavior?
The while loop is bounded only by num_bytes. If a malicious USB device sends a packet with 10 or more consecutive bytes having the 0x80 bit set, offset * 7 will equal or exceed 64, shifting a 64-bit integer out of bounds and leading to corrupted length parsing.
Quoted 7 lines
drivers/input/joystick/gip/gip-core.c new file +7
-0+if (!(byte &0x80 )) { + offset++; +break ; + } + } +return offset; +}
[ ... ]
Quoted 6 lines
drivers/input/joystick/gip/gip-core.c new file +6
-0+static uint8_t gip_sequence_next (struct gip_attachment *attachment, +uint8_t command,bool system) +{ +uint8_t seq; + +if (system) {
[ ... ]
drivers/input/joystick/gip/gip-core.c line 431
Quoted 7 lines
drivers/input/joystick/gip/gip-core.c new file +7
-0+ }else { + seq = attachment->seq_vendor++; +if (!seq) + seq = attachment->seq_vendor++; + } +return seq; +}
[Severity: High]
Are these shared sequence numbers protected against concurrent modification?
Modifying shared state like seq_vendor without locks could cause data races. Concurrent attempts to send messages (e.g., from force-feedback rumble updates and background ACME acks) might race to increment sequence IDs and cause sequence number duplication. This pattern of unprotected modification also occurs in gip_send_raw_message when claiming out_fragments slots.
Quoted 2 lines
drivers/input/joystick/gip/gip-core.c new file +2
-0+ +static void gip_handle_quirks_array(struct gip_attachment *attachment,
[ ... ]
Quoted 4 lines
drivers/input/joystick/gip/gip-core.c new file +4
-0+static int gip_send_raw_message (struct gip_attachment *attachment, +uint8_t message_type,uint8_t flags,uint8_t seq,const uint8_t *bytes, +int num_bytes) +{
[ ... ]
drivers/input/joystick/gip/gip-core.c line 517
Quoted 5 lines
drivers/input/joystick/gip/gip-core.c new file +5
-0+if (!urb) { +gip_err (attachment,"Output queue is full; dropping message\n" ); + rc = -ENOSPC ; + goto err_free_fragment; + }
[Severity: Critical]
Is it possible for error paths in fragment sending to cause a NULL pointer dereference?
If a fragment pointer is initialized to NULL, and the output queue is full or usb_submit_urb() fails, jumping to an error path that unconditionally calls memset(fragment, 0, ...) (like in a gip_free_fragment function) would immediately panic the kernel.
Quoted 1 line
drivers/input/joystick/gip/gip-core.c new file +1
-0+ urb->data[0 ] = message_type;
[ ... ]
Quoted 3 lines
drivers/input/joystick/gip/gip-core.c new file +3
-0+static bool gip_parse_metadata (struct device *dev, +struct gip_metadata *metadata,const uint8_t *bytes,int num_bytes) +{
[ ... ]
drivers/input/joystick/gip/gip-core.c line 904
Quoted 8 lines
drivers/input/joystick/gip/gip-core.c new file +8
-0+ metadata->num_messages = bytes[offset]; + offset++; +if (metadata->num_messages >0 ) { + metadata->message_metadata =devm_kcalloc (dev, + metadata->num_messages, +sizeof (*metadata->message_metadata),GFP_KERNEL ); +if (!metadata->message_metadata) +return -ENOMEM ;
[Severity: Medium]
Will this early return leak previously allocated devres fields?
If devm_kcalloc fails here, returning -ENOMEM directly bypasses the parse_err cleanup label, which is responsible for freeing previously allocated structures like audio formats and preferred types, causing a persistent memory leak.
Quoted 2 lines
drivers/input/joystick/gip/gip-core.c new file +2
-0+ +for (i =0 ; i < metadata->num_messages; i++) {
[ ... ]
Quoted 8 lines
drivers/input/joystick/gip/gip-core.c new file +8
-0+static int gip_handle_elite_buttons (struct gip_attachment *attachment, +struct input_dev *input,const uint8_t *bytes,int num_bytes) +{ +bool grip[4 ] = {0 ,0 ,0 ,0 }; +int profile =-1 ; + +if (attachment->xbe_format ==GIP_BTN_FMT_XBE1 + && num_bytes >GIP_BTN_OFFSET_XBE1 ) {
[ ... ]
drivers/input/joystick/gip/gip-core.c line 1713
Quoted 10 lines
drivers/input/joystick/gip/gip-core.c new file +10
-0+ }else if ((attachment->xbe_format ==GIP_BTN_FMT_XBE2_4 + || attachment->xbe_format ==GIP_BTN_FMT_XBE2_5 ) + && num_bytes >GIP_BTN_OFFSET_XBE2 ) { +int profile_offset; + +if (attachment->xbe_format ==GIP_BTN_FMT_XBE2_4 ) + profile_offset =15 ; +else + profile_offset =20 ; + profile = bytes[profile_offset] &3 ;
[Severity: High]
Is it possible to encounter an out-of-bounds read here due to insufficient bounds checking?
For GIP_BTN_FMT_XBE2_5 layouts, profile_offset is set to 20. The preceding bounds check only validates that num_bytes > 14 (GIP_BTN_OFFSET_XBE2). If a malicious USB packet arrives with a length of 15 to 20 bytes, reading bytes[profile_offset] causes an out-of-bounds array access.
Quoted 2 lines
drivers/input/joystick/gip/gip-core.c new file +2
-0+ +if (!profile) {
[ ... ]
drivers/input/joystick/gip/gip-core.c line 1886
Quoted 7 lines
drivers/input/joystick/gip/gip-core.c new file +7
-0+static struct gip_attachment *gip_ensure_attachment (struct gip_device *device, +uint8_t attachment_index) +{ +struct gip_attachment *attachment = device->attachments[attachment_index]; + +if (!attachment) { + attachment =devm_kzalloc (to_gip_device (device),sizeof (*attachment),GFP_KERNEL );
[Severity: High]
Does this attachment creation suffer from a data race during probe?
This uses a check-and-allocate pattern for device->attachments[attachment_index] without locking. If gip_probe starts URB reception before ensuring the attachment exists, a racing USB packet could trigger the receive worker. Both threads could concurrently execute gip_ensure_attachment, allocating multiple instances, causing state corruption and memory leaks.
Quoted 2 lines
drivers/input/joystick/gip/gip-core.c new file +2
-0+if (!attachment) +return ERR_PTR (-ENOMEM );
[ ... ]
Quoted 14 lines
drivers/input/joystick/gip/gip-core.c new file +14
-0+static int gip_receive_fragment (struct gip_attachment *attachment, +const struct gip_header *header,int offset, +uint64_t *fragment_offset,uint16_t *bytes_remaining,uint8_t *bytes, +int num_bytes) +{ +int rc =0 ; + +if (header->flags &GIP_FLAG_INIT_FRAG ) { +uint64_t total_length; + +guard (mutex)(&attachment->lock); +if (attachment->in_fragment_message >=0 ) { +/* +* Reset fragment buffer if we get a new initial
drivers/input/joystick/gip/gip-core.c line 1973
Quoted 10 lines
drivers/input/joystick/gip/gip-core.c new file +10
-0+* fragment before finishing the last message. +* TODO: Is this the correct behavior? +*/ +devm_kfree (to_gip_device (attachment), attachment->in_fragment_data); + attachment->in_fragment_data =NULL ; + } + offset +=gip_decode_length (&total_length, &bytes[offset], + num_bytes - offset); +if (total_length >MAX_MESSAGE_LENGTH ) +return -EINVAL ;
[Severity: Critical]
Could this early return leave the state desynchronized if length validation fails?
If an INIT_FRAG arrives while in_fragment_message >= 0, in_fragment_data is freed and set to NULL. If it then fails the total_length validation, the function returns early without resetting in_fragment_message. A subsequent fragment of the same type would skip initialization checks and call memcpy into the NULL in_fragment_data pointer, causing an immediate kernel panic.
Quoted 2 lines
drivers/input/joystick/gip/gip-core.c new file +2
-0+ +if (header->length > num_bytes - offset) {
[ ... ]
Quoted 1 line
drivers/input/joystick/gip/gip-core.c new file +1
-0+if (header->length > total_length) {
[ ... ]
drivers/input/joystick/gip/gip-core.c line 1988
Quoted 2 lines
drivers/input/joystick/gip/gip-core.c new file +2
-0+ attachment->in_fragment_data =devm_kmalloc (to_gip_device (attachment), + total_length,GFP_KERNEL );
[Severity: Medium]
Should devres be used for per-message data buffers in the hot path?
Allocating and freeing dynamic buffers for every fragmented message using devm_kmalloc and devm_kfree causes performance degradation and lock contention. Devres is designed for device lifecycle management, not high-frequency data path allocations.
Quoted 1 line
drivers/input/joystick/gip/gip-core.c new file +1
-0+if (!attachment->in_fragment_data)
[ ... ]
Quoted 1 line
drivers/input/joystick/gip/gip-core.c new file +1
-0+if (*fragment_offset + header->length > attachment->in_total_length) {
[ ... ]
Quoted 8 lines
drivers/input/joystick/gip/gip-core.c new file +8
-0+if (header->length !=0 ) +memcpy (&attachment->in_fragment_data[*fragment_offset], + &bytes[offset], header->length); + *fragment_offset += header->length; + attachment->in_fragment_offset = *fragment_offset; + +if (header->flags &GIP_FLAG_ACME ) +gip_acknowledge (attachment, header, *fragment_offset, *bytes_remaining);
drivers/input/joystick/gip/gip-core.c line 2073
Quoted 10 lines
drivers/input/joystick/gip/gip-core.c new file +10
-0+if (header->length ==0 && !*bytes_remaining) { + rc =gip_handle_message (attachment, header, + attachment->in_fragment_data, + attachment->in_total_length); +devm_kfree (to_gip_device (attachment), attachment->in_fragment_data); + attachment->in_fragment_data =NULL ; + attachment->in_fragment_message =-1 ; + } + } +cancel_delayed_work (&attachment->in_fragment_timeout);
[Severity: High]
Can this asynchronous cancellation race with the timeout handler?
Because cancel_delayed_work is called outside the attachment->lock, it can race with gip_fragment_timeout. If the timeout fires and blocks on the lock while gip_receive_fragment is running, it will acquire the lock right after the new buffer is installed and wrongfully devm_kfree the actively used buffer.
Quoted 4 lines
drivers/input/joystick/gip/gip-core.c new file +4
-0+schedule_delayed_work (&attachment->in_fragment_timeout,HZ ); + +return rc; +}
[ ... ]
Quoted 2 lines
drivers/input/joystick/gip/gip-core.c new file +2
-0+static void gip_urb_in (struct urb *urb) +{
[ ... ]
drivers/input/joystick/gip/gip-core.c line 2190
Quoted 8 lines
drivers/input/joystick/gip/gip-core.c new file +8
-0+spin_lock_irqsave (&gip->message_lock, flags); +if (gip->pending_in_messages >=MAX_IN_MESSAGES ) { +gip_err (gip,"Input queue is full; dropping message\n" ); + }else { + message_id = (gip->next_in_message + gip->pending_in_messages) %MAX_IN_MESSAGES ; + message = &gip->in_queue[message_id]; + gip->pending_in_messages++; +memcpy (message->bytes, intf->in_data, urb->actual_length);
[Severity: Medium]
Might this copy overflow the fixed-size message queue buffer?
message->bytes is hardcoded to 64 bytes (BASE_GIP_MTU). The data is copied using urb->actual_length without validation against the destination size. If a quirky USB device returns more than 64 bytes (or if the audio interface with an MTU of 2048 bytes is ever enabled), this will trigger an out-of-bounds write and corrupt the in_queue ring buffer.
Quoted 7 lines
drivers/input/joystick/gip/gip-core.c new file +7
-0+ message->num_bytes = urb->actual_length; + } +spin_unlock_irqrestore (&gip->message_lock, flags); +schedule_work (&gip->receive_message); + +exit: + status =usb_submit_urb (urb,GFP_ATOMIC );
[ ... ]
Quoted 3 lines
drivers/input/joystick/gip/gip-core.c new file +3
-0+static int gip_init_input (struct gip_interface *intf, +struct usb_endpoint_descriptor *ep_in) +{
[ ... ]
drivers/input/joystick/gip/gip-core.c line 2245
Quoted 7 lines
drivers/input/joystick/gip/gip-core.c new file +7
-0+ intf->in_data =usb_alloc_coherent (udev, intf->mtu,GFP_KERNEL , + &intf->urb_in->transfer_dma); + +if (!intf->in_data) { +return -ENOMEM ; + goto err_free_urb; + }
[Severity: High]
Are these goto cleanup paths unreachable?
Returning -ENOMEM directly prevents the cleanup code from executing, leaking the allocated URB on failure. The same unreachable pattern exists in gip_init_output for err_free_urbs, where it leaks all previously allocated URBs and DMA buffers in the output queue if memory allocation fails mid-loop.
Quoted 2 lines
drivers/input/joystick/gip/gip-core.c new file +2
-0+ + usb_fill_int_urb(intf->urb_in, udev,
[ ... ]
Quoted 8 lines
drivers/input/joystick/gip/gip-core.c new file +8
-0+static int gip_probe (struct usb_interface *intf,const struct usb_device_id *id) +{ +struct usb_device *udev =interface_to_usbdev (intf); +struct gip_device *gip =NULL ; +struct gip_attachment *attachment; +int rc; + +if (intf->cur_altsetting->desc.bInterfaceNumber !=GIP_WIRED_INTF_DATA ) {
[ ... ]
drivers/input/joystick/gip/gip-core.c line 2400
Quoted 3 lines
drivers/input/joystick/gip/gip-core.c new file +3
-0+ } + + gip =devm_kzalloc (&udev->dev,sizeof (*gip),GFP_KERNEL );
[Severity: High]
Should this devm allocation be bound to the interface device (&intf->dev) instead of the USB device (&udev->dev)?
By binding driver state to the USB device instead of the interface, the memory is not freed when the driver unbinds from the interface (e.g., via sysfs). This causes a persistent memory leak of driver structures and input devices since devres actions attached to udev->dev will not fire on driver unbind.
Quoted 2 lines
drivers/input/joystick/gip/gip-core.c new file +2
-0+if (!gip) +return -ENOMEM ;
[ ... ]
drivers/input/joystick/gip/gip-core.c line 2470
Quoted 11 lines
drivers/input/joystick/gip/gip-core.c new file +11
-0+static void gip_disconnect (struct usb_interface *intf) +{ +struct gip_device *gip =usb_get_intfdata (intf); +int i; + +if (!gip) +return ; + +gip_shutdown (gip); + +usb_kill_urb (gip->data.urb_in);
[Severity: High]
Does this workqueue teardown order introduce a Use-After-Free?
gip_shutdown(gip) synchronously cancels the receive workqueue, but the input URBs are killed afterward. If an input URB completes in the window between cancel_work_sync and usb_kill_urb, the completion handler gip_urb_in will reschedule the work again. gip_disconnect will proceed to free the structures, leading to a UAF when the rescheduled work executes.
Quoted 1 line
drivers/input/joystick/gip/gip-core.c new file +1
-0+usb_kill_anchored_urbs (&gip->data.out_anchor);
[ ... ]
drivers/input/joystick/gip/gip-core.c line 2497
Quoted 12 lines
drivers/input/joystick/gip/gip-core.c new file +12
-0+for (i =0 ; i <MAX_ATTACHMENTS ; i++) { +struct gip_attachment *attachment = gip->attachments[i]; + +if (!attachment) +continue ; + +gip_reset_attachment (attachment); +gip_reset_metadata (attachment); + +devm_kfree (to_gip_device (attachment), attachment->uniq); +devm_kfree (to_gip_device (attachment), attachment); + }
[Severity: High]
Can manually freeing the attachment struct cause a UAF with concurrent sysfs access?
Since input_dev devres was bound to &udev->dev, sysfs nodes (such as battery or LED properties) remain active even after unbind. Manually freeing the container structure here creates a window where a concurrent sysfs read could access the freed attachment structure (e.g., locking the freed battery_lock).
Quoted 12 lines
drivers/input/joystick/gip/gip-core.c new file +12
-0+ +devm_kfree (to_gip_device (gip), gip); +} + +static int gip_suspend (struct usb_interface *intf,pm_message_t message) +{ +struct gip_device *gip =usb_get_intfdata (intf); + +if (!gip) +return 0 ; + +usb_kill_urb (gip->data.urb_in);
[ ... ]
drivers/input/joystick/gip/gip-core.c line 2525
Quoted 10 lines
drivers/input/joystick/gip/gip-core.c new file +10
-0+if (gip->attachments[0 ]) { +struct gip_attachment *attachment = gip->attachments[0 ]; + +guard (mutex)(&attachment->lock); +gip_send_set_device_state (attachment,GIP_STATE_OFF ); + attachment->device_state =GIP_STATE_OFF ; + } + +return gip_shutdown (gip); +}
[Severity: High]
Is it intended that system suspend destroys the userspace-visible nodes?
Calling gip_shutdown(gip) completely destroys the driver state and unconditionally unregisters the input_dev and hid_device via gip_free_devices(). When the system resumes, these devices are not recreated, permanently breaking any running applications holding evdev or hidraw file descriptors.
[Severity: High]
Does intermediate message fragment transmission fail to advance fragment_offset?
If an intermediate fragment is sent, it will not have GIP_FLAG_ACME set, so the device never sends an ACK, and the fragment might not be marked as acked. If the offset is only advanced when fragment->acked is true, the driver will repeatedly resend the identical chunk indefinitely, causing an infinite loop that stalls transmission for any message exceeding the MTU limit.
[Severity: High]
Can a manual power_supply_unregister on a devm-managed resource cause a double free?
If the power supply is created with devm_power_supply_register() and later manually unregistered in an error path (e.g., if power_supply_powers() fails), the devres framework remains unaware and will attempt to unregister it again during teardown, resulting in a double-free kernel panic.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH v5 12/12] Input: xbox_gip - Add wheel support
In reply to Vicki PfauThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [Medium] Improper wrap-around calculation for REL_DIAL in TrueForce wheel driver.
- [Medium] Packet length validation happens after partial event reporting, causing input event desync on short packets.
Pre-existing issues:
- [Critical] Workqueues are synchronously cancelled before killing URBs in gip_disconnect, causing a Use-After-Free. --
commit f290772c9ca66efd1e7d5ec4dd73e7af098deefd
Author: Vicki Pfau <[email protected]>
Input: xbox_gip - Add wheel support
This adds preliminary support for racing wheel support in xbox_gip, exposing them mapped to the newly added axes.
Quoted 4 lines
drivers/input/joystick/gip/gip-wheel.c new file +0
-0
[ ... ]
Quoted 5 lines
drivers/input/joystick/gip/gip-wheel.c new file +5
-0+static int gip_handle_wheel_report (struct gip_attachment *attachment, +struct input_dev *input,const uint8_t *bytes,int num_bytes) +{ +uint8_t connections; +struct gip_wheel_info *info = attachment->driver_data;
drivers/input/joystick/gip/gip-wheel.c line 168
Quoted 10 lines
drivers/input/joystick/gip/gip-wheel.c new file +10
-0+int rc = gip_driver_navigation.handle_input_report (attachment, input, bytes, num_bytes); + +if (rc <0 ) +return rc; + +if (!info) +return -ENODEV ; + +if (num_bytes <17 ) +return -EINVAL ;
[Severity: Medium]
Does this cause input events to be desynced on short packets?
If a short packet arrives (between 2 and 16 bytes), the base navigation handler above successfully processes the first bytes and queues events. The length check here then fails and returns -EINVAL, which causes an early exit before the core can call input_sync().
This could leave the device in an inconsistent state with phantom inputs or stuck keys until the next valid packet arrives.
[ ... ]
drivers/input/joystick/gip/gip-wheel.c line 313
Quoted 12 lines
drivers/input/joystick/gip/gip-wheel.c new file +12
-0+static int gip_handle_trueforce_wheel_report (struct gip_attachment *attachment, +struct input_dev *input,const uint8_t *bytes,int num_bytes) +{ +int rc = gip_driver_wheel.handle_input_report (attachment, input, bytes, num_bytes); +struct gip_trueforce_wheel_state *state = attachment->driver_data; +int dial; + +if (rc <0 ) +return rc; + +if (num_bytes <18 ) +return -EINVAL ;
[Severity: Medium]
Similarly, does this early return skip input synchronization for short packets?
Like the base wheel handler, events are queued by gip_driver_wheel.handle_input_report() before this check fails.
[ ... ]
drivers/input/joystick/gip/gip-wheel.c line 332
Quoted 11 lines
drivers/input/joystick/gip/gip-wheel.c new file +11
-0+if (dial ==0 && state->dial ==7 ) +input_report_rel (input,REL_DIAL ,-1 ); +else if (dial ==7 && state->dial ==0 ) +input_report_rel (input,REL_DIAL ,1 ); +else +input_report_rel (input,REL_DIAL , + state->dial - dial); + state->dial = dial; + +return 0 ; +}
[Severity: Medium]
Can this calculation magnify offsets if the dial is turned quickly?
If the wheel's dial is turned fast enough to jump multiple steps between USB reports (e.g., from 6 to 0, crossing the boundary), this falls through the 1-step boundary checks.
The fallback calculation of state->dial - dial would then result in a reported offset of 6 (6 - 0) instead of the actual -2 steps taken.
As a quick aside, I noticed a separate issue in the core code while reviewing:
[Severity: Critical]
This is a pre-existing issue, but does gip_disconnect() have a Use-After-Free race window during device unbind?
drivers/input/joystick/gip/gip-core.c:gip_disconnect() {
...
gip_shutdown(gip);
usb_kill_urb(gip->data.urb_in);
...
}Since workqueues are synchronously cancelled in gip_shutdown() before calling usb_kill_urb(), if an URB completes in that window, its completion handler can reschedule the work on memory that is actively being torn down.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12