All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shengzhuo Wei" <me@cherr.cc>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v3] HID: hid-oxp: fix UAF on pending work in remove()
Date: Sun, 23 Aug 2026 21:05:50 +0000	[thread overview]
Message-ID: <20260823210550.BC6741F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260824-oxp-fix-v3-1-599b12c91a77@cherr.cc>

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

New issues:
- [High] Calling `cancel_delayed_work_sync()` on uninitialized work structures triggers a kernel `WARN_ON`.

Pre-existing issues:
- [Critical] Global `drvdata` leads to cross-device memory corruption and broken isolation.
- [High] Missing delayed work cancellation in probe error path leads to Use-After-Free.
- [High] Re-arming of delayed works during and after `remove()` causes Use-After-Free.
- [High] Missing report size validation in raw event handlers leads to out-of-bounds memory read.
--

--- Patch [1]: [PATCH v3] HID: hid-oxp: fix UAF on pending work in remove() ---
commit 626193303fb8331bebf2a55e5dc615127fc1f7e7
Author: Shengzhuo Wei <me@cherr.cc>

HID: hid-oxp: fix UAF on pending work in remove()

This commit addresses a use-after-free regression by changing
cancel_delayed_work() to cancel_delayed_work_sync() in oxp_hid_remove().
This ensures workers exit before the device is freed, preventing asleep
workers from waking up and dereferencing a stale hid_device.

Link: https://lore.kernel.org/r/20260804-oxp-fix-v2-1-b2d56e4c8a2c@cherr.cc
Link: https://lore.kernel.org/r/20260804-oxp-fix-v1-1-51a4fe787167@cherr.cc

> diff --git a/drivers/hid/hid-oxp.c b/drivers/hid/hid-oxp.c
> index 20a54f337220d..d8fb6a69d40d4 100644
> --- a/drivers/hid/hid-oxp.c
> +++ b/drivers/hid/hid-oxp.c
> @@ -1552,9 +1552,9 @@ static int oxp_hid_probe(struct hid_device *hdev,

[Severity: Critical]
This isn't a bug introduced by this patch, but does using a single static global
structure for per-device state cause cross-device memory corruption?

When oxp_cfg_probe() runs for a new device, it unconditionally overwrites
drvdata.hdev, drvdata.bmap_1, and drvdata.bmap_2 with its own allocations:

oxp_cfg_probe()
    ...
    hid_set_drvdata(hdev, &drvdata);
    mutex_init(&drvdata.cfg_mutex);
    drvdata.hdev = hdev;
    ...
    drvdata.bmap_1 = bmap_1;
    drvdata.bmap_2 = bmap_2;

If multiple supported interfaces or gamepads are connected, won't they
clobber each other's state, leading to a use-after-free regression if one
is unbound while the other remains active?

[Severity: High]
This isn't a bug introduced by this patch, but could the probe error path leak
a running delayed work?

In oxp_cfg_probe(), drvdata.oxp_mcu_init is armed via mod_delayed_work().
If subsequent initialization like devm_device_add_group() fails, it
returns an error.

The error handler in oxp_hid_probe() cleans up hardware state but doesn't
cancel the pending delayed work before returning.

Could this allow the work to run after devres frees the device memory,
causing a use-after-free regression when oxp_mcu_init_fn() dereferences
the freed pointers?

[Severity: High]
This isn't a bug introduced by this patch, but do the raw event handlers
validate the incoming report size?

In both oxp_hid_raw_event_gen_1() and oxp_hid_raw_event_gen_2(), the code
casts the buffer and reads fields like rgb_rep->effect or checks indices
like data[3] without checking the size of the incoming HID report buffer.

If a device sends a truncated report, could this result in an out-of-bounds
memory read regression?

>  static void oxp_hid_remove(struct hid_device *hdev)
>  {
> -	cancel_delayed_work(&drvdata.oxp_rgb_queue);
> -	cancel_delayed_work(&drvdata.oxp_btn_queue);
> -	cancel_delayed_work(&drvdata.oxp_mcu_init);
> +	cancel_delayed_work_sync(&drvdata.oxp_rgb_queue);
> +	cancel_delayed_work_sync(&drvdata.oxp_btn_queue);
> +	cancel_delayed_work_sync(&drvdata.oxp_mcu_init);

[Severity: High]
If a device connects and exposes a standard HID interface, oxp_hid_probe()
can return success without calling oxp_cfg_probe(), leaving the work
structures uninitialized.

When the device is disconnected, oxp_hid_remove() will unconditionally
call cancel_delayed_work_sync() on these zero-initialized structures.

Could this trigger a WARN_ON(!work->func) inside __flush_work()?

[Severity: High]
This is a pre-existing issue, but modifying these lines highlights a
regression where cancellation happens before hid_hw_stop().

Because the hardware is not stopped, incoming USB reports can still invoke
oxp_hid_raw_event_gen_2(), which unconditionally calls mod_delayed_work().

Furthermore, sysfs attributes managed by devres remain accessible to
userspace until devres cleanup occurs after remove().

Can an unprivileged user writing to sysfs (like map_button_store) or
incoming hardware events re-arm the works after this synchronization,
causing a use-after-free regression when devres frees the memory?

>  	hid_hw_close(hdev);
>  	hid_hw_stop(hdev);
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260824-oxp-fix-v3-1-599b12c91a77@cherr.cc?part=1

      reply	other threads:[~2026-08-23 21:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-23 20:54 [PATCH v3] HID: hid-oxp: fix UAF on pending work in remove() Shengzhuo Wei
2026-08-23 21:05 ` sashiko-bot [this message]

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=20260823210550.BC6741F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=me@cherr.cc \
    --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.