From: sashiko-bot@kernel.org
To: "Denis Benato" <denis.benato@linux.dev>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v9 09/12] HID: asus: add support to force feedback
Date: Fri, 09 Oct 2026 13:44:44 +0000 [thread overview]
Message-ID: <sashiko-outbox-165666@kernel.org> (raw)
In-Reply-To: <20261009122820.7603-10-denis.benato@linux.dev>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] hid: asus: UAF in hid_asus_ally_init due to missing gamepad disconnect re-check
--
commit b25c2490b184182f7d805afd2134e7bf9ce60b63
Author: Denis Benato <denis.benato@linux.dev>
Subject: HID: asus: add support to force feedback
This commit adds support for force feedback to the Asus ROG Ally X gamepad,
using a work-queue to avoid sleeping calls in atomic contexts when sending
XInput rumble magnitude updates.
> diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c
> index bb664bd9e140b..298f14b8713d9 100644
> --- a/drivers/hid/hid-asus.c
> +++ b/drivers/hid/hid-asus.c
[ ... ]
> @@ -2679,20 +2846,61 @@ static int ally_x_setup_input(struct hid_device *hdev, struct ally_handheld *all
[ ... ]
> static int hid_asus_ally_init(struct hid_device *hdev, struct ally_handheld *ally)
> {
> + struct hid_device *x_hdev;
> struct ally_config *cfg;
> + unsigned long flags;
> int ret;
>
[ ... ]
> + /*
> + * Snapshot the gamepad interface and send the force-feedback "off"
> + * packet through it. usbhid_stop() frees urbout before NULLing it
> + * while usbhid_output_report() dereferences it unlocked, so a send
> + * overlapping the transport teardown would be a use-after-free: the
> + * device lock is taken around the send because the HID core holds
> + * it across remove() and the hid_hw_stop() that follows, making the
> + * two mutually exclusive. It is taken before intf_mutex, the same
> + * order the core's remove path uses, so no lock inversion exists.
> + */
> + spin_lock_irqsave(&ally_data_lock, flags);
> + x_hdev = ally->ally_x_hdev;
> + if (x_hdev)
> + get_device(&x_hdev->dev);
> + spin_unlock_irqrestore(&ally_data_lock, flags);
> +
> + if (x_hdev) {
> + /* Failure at this point is non-critical */
> + scoped_guard(mutex, &x_hdev->dev.mutex) {
> + scoped_guard(mutex, &ally->intf_mutex) {
> + ret = ally_x_send_ff_off(x_hdev);
[Severity: High]
Can this sequence lead to a use-after-free if the device is concurrently
unplugged?
If hid_asus_ally_init() snapshots x_hdev and takes a reference to it, but the
device is unplugged before the mutex is acquired, the HID core will run the
unbind process (which takes x_hdev->dev.mutex, calls remove(), and then calls
hid_hw_stop()).
During this unbind, remove() safely clears ally->ally_x_hdev under
ally->intf_mutex, and hid_hw_stop() stops the transport and frees the
low-level driver data (e.g. kfree(usbhid)).
Once unbind completes, hid_asus_ally_init() acquires x_hdev->dev.mutex and
ally->intf_mutex. Because it does not re-verify if ally->ally_x_hdev == x_hdev
under the lock, it proceeds to call ally_x_send_ff_off(x_hdev) on the
torn-down transport. This forwards the request to hid_hw_output_report(),
which will dereference the freed low-level driver data, causing a
use-after-free.
Would it be safer to check if ally->ally_x_hdev is still equal to x_hdev
inside the intf_mutex guard before sending the report?
> +
> + if (ret < 0)
> + hid_err(hdev,
> + "Ally failed to init force-feedback off: %d\n",
> + ret);
> + }
> + }
> +
> + put_device(&x_hdev->dev);
> + }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261009122820.7603-1-denis.benato@linux.dev?part=9
next prev parent reply other threads:[~2026-10-09 13:44 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 12:28 [PATCH v9 00/12] HID: asus: add support for ROG Ally handhelds Denis Benato
2026-10-09 12:28 ` [PATCH v9 01/12] HID: asus: reinitialize the device after exiting a sleep state Denis Benato
2026-10-09 12:40 ` sashiko-bot
2026-10-09 12:28 ` [PATCH v9 02/12] HID: asus: add support for ROG Ally handhelds Denis Benato
2026-10-09 12:28 ` [PATCH v9 03/12] HID: asus: add gamepad configuration Denis Benato
2026-10-09 12:28 ` [PATCH v9 04/12] HID: asus: add vibration strength configuration Denis Benato
2026-10-09 12:28 ` [PATCH v9 05/12] HID: asus: add joysticks inner and outer range configuration Denis Benato
2026-10-09 12:28 ` [PATCH v9 06/12] HID: asus: add triggers " Denis Benato
2026-10-09 12:28 ` [PATCH v9 07/12] HID: asus: add joysticks anti-deadzone configuration Denis Benato
2026-10-09 13:22 ` sashiko-bot
2026-10-09 12:28 ` [PATCH v9 08/12] HID: asus: add support for response curve Denis Benato
2026-10-09 12:28 ` [PATCH v9 09/12] HID: asus: add support to force feedback Denis Benato
2026-10-09 13:44 ` sashiko-bot [this message]
2026-10-09 12:28 ` [PATCH v9 10/12] HID: asus: add support for gamepad mode Denis Benato
2026-10-09 12:28 ` [PATCH v9 11/12] HID: asus: add support for turbo buttons Denis Benato
2026-10-09 12:28 ` [PATCH v9 12/12] HID: asus: add support for btn remapping Denis Benato
2026-10-09 14:05 ` sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-165666@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=denis.benato@linux.dev \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.