Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lee Jones" <lee@kernel.org>, linux-input@vger.kernel.org
Cc: dmitry.torokhov@gmail.com
Subject: Re: [PATCH v2 08/10] HID: wacom: Stop HID hardware before releasing resources on mode change
Date: Fri, 27 Nov 2026 17:31:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-237993@kernel.org> (raw)
In-Reply-To: <20261127170712.3163443-9-lee@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] HID: wacom: hid_hw_stop() without driver_input_lock in
  wacom_mode_change_work()
--

commit 8829d08a1079cac40d2eeee82adefcbf5c67e3e6
Author: Lee Jones <lee@kernel.org>

HID: wacom: Stop HID hardware before releasing resources on mode change

This commit moves hid_hw_stop() ahead of wacom_release_resources() for
both the pen and touch interfaces in wacom_mode_change_work().

> diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
> index 2d2a4d56a8da7..121bead90147c 100644
> --- a/drivers/hid/wacom_sys.c
> +++ b/drivers/hid/wacom_sys.c
> @@ -2887,16 +2887,16 @@ static void wacom_mode_change_work(struct work_struct *work)
>  
>  	if (pen) {
>  		wacom1 = hid_get_drvdata(pen);
> -		wacom_release_resources(wacom1);
>  		hid_hw_stop(wacom1->hdev);
> +		wacom_release_resources(wacom1);
>  		wacom1->wacom_wac.has_mode_change = true;
>  		wacom1->wacom_wac.is_direct_mode = is_direct;
>  	}
>  
>  	if (touch) {
>  		wacom2 = hid_get_drvdata(touch);
> -		wacom_release_resources(wacom2);
>  		hid_hw_stop(wacom2->hdev);
> +		wacom_release_resources(wacom2);
>  		wacom2->wacom_wac.has_mode_change = true;
>  		wacom2->wacom_wac.is_direct_mode = is_direct;
>  	}

[Severity: High]
Can calling hid_hw_stop() before wacom_release_resources() without holding
hdev->driver_input_lock cause a use-after-free on hdev->hidraw?

wacom_probe() does not call hid_device_io_start(), so hdev->io_started
remains false and hid_device_probe() releases hdev->driver_input_lock when
probe finishes.  When an input device is open in userspace, wacom_open()
calls hid_hw_open(), starting the low-level transport (such as
usbhid->urbin).

Previously, wacom_release_resources() unregistered the input devices
first, invoking wacom_close() -> hid_hw_close() to stop the transport
before hid_hw_stop() ran (when /dev/hidrawX was not open).  Now
hid_hw_stop() runs while the input devices are still open and delivering
reports:

drivers/hid/hid-core.c:hid_hw_stop() {
	if (hdev->io_started)
		hid_device_io_stop(hdev);
	hid_disconnect(hdev);
	hdev->ll_driver->stop(hdev);
}

Because hdev->io_started is false, hid_hw_stop() skips
hid_device_io_stop() (which would acquire driver_input_lock) and calls
hid_disconnect() before ll_driver->stop() kills active URBs.  If
/dev/hidrawX is not open (hidraw->open == 0), hidraw_disconnect() ->
drop_ref() frees hdev->hidraw before hdev->claimed is cleared:

CPU0 (kworker)                    CPU1 (softirq)
wacom_mode_change_work()
  hid_hw_stop(hdev)
    hid_disconnect(hdev)
      hidraw_disconnect(hdev)
        drop_ref(hidraw, 1)
          kfree(hidraw)
                                  hid_input_report()
                                    down_trylock(&hdev->driver_input_lock)
                                    __hid_input_report()
                                      hid_report_raw_event()
                                        /* hdev->claimed & HID_CLAIMED_HIDRAW */
                                        hidraw_report_event()
                                          dev = hdev->hidraw;
                                          spin_lock_irqsave(&dev->list_lock)
                                          <-- use-after-free
      hdev->claimed = 0;
    hdev->ll_driver->stop(hdev)

Acquiring hdev->driver_input_lock around the teardown and re-registration
(or calling hid_device_io_stop() before hid_hw_stop()) would serialize
against concurrent hid_input_report() calls.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127170712.3163443-1-lee@kernel.org?part=8

  reply	other threads:[~2026-11-27 17:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 17:06 [PATCH v2 00/10] HID: Fix race conditions, UAFs, and bounds bugs Lee Jones
2026-11-27 17:06 ` [PATCH v2 01/10] HID: core: Protect hid->inputs traversal in hid_check_keys_pressed() Lee Jones
2026-11-27 17:06 ` [PATCH v2 02/10] HID: mcp2221: Synchronise rxbuf access against raw_event callback Lee Jones
2026-11-27 17:06 ` [PATCH v2 03/10] HID: logitech-hidpp: Synchronise send_receive_buf against raw events Lee Jones
2026-11-27 17:06 ` [PATCH v2 04/10] HID: sensor-hub: Serialise synchronous read teardown under data->lock Lee Jones
2026-11-27 17:06 ` [PATCH v2 05/10] HID: roccat: pyra: Resolve USB device from parent in actual_profile Lee Jones
2026-11-27 17:06 ` [PATCH v2 06/10] HID: hyperv: Validate VMBus packet and payload bounds on receive Lee Jones
2026-11-27 17:06 ` [PATCH v2 07/10] HID: hid-goodix-spi: Validate package sizes in goodix_hid_irq() Lee Jones
2026-11-27 17:06 ` [PATCH v2 08/10] HID: wacom: Stop HID hardware before releasing resources on mode change Lee Jones
2026-11-27 17:31   ` sashiko-bot [this message]
2026-11-27 17:06 ` [PATCH v2 09/10] HID: debug: Hold driver_input_lock while dumping raw report descriptor Lee Jones
2026-11-27 17:06 ` [PATCH v2 10/10] HID: playstation: Cancel DualSense output worker on create failure Lee Jones

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-237993@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=lee@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox