From: sashiko-bot@kernel.org
To: "Rong Zhang" <i@rong.moe>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v7 05/13] HID: Add hid-plugin framework for loadable plugin modules
Date: Sat, 05 Dec 2026 19:12:01 +0000 [thread overview]
Message-ID: <sashiko-outbox-251852@kernel.org> (raw)
In-Reply-To: <20261206-hid-haptic-kmod-v7-5-3eea47035836@rong.moe>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Low] HID: hid-plugin kernel-doc claims Any context for sleeping
helpers
- [Low] HID: struct hid_plugin kernel-doc omits non-devm allocation
constraint
- [Low] hid: __hid_device_probe() calls hid_plugin_prune() without
stopping HID I/O
--
commit 9e6de1f1db3878e50979912e55cc4cba6f26556d
Author: Rong Zhang <i@rong.moe>
HID: Add hid-plugin framework for loadable plugin modules
This commit introduces the hid-plugin framework so HID drivers can
connect to optional loadable or builtin usage-page plugins, requesting
plugin modules asynchronously and reprobing deferred devices once the
plugin registers.
Link: https://lore.kernel.org/linux-input/auypydfkhx2eg7vp764way4batdilzc35inqda3exwzs3tk3ff@oagat6g46zto/
> diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
> index ceff3c80d9962..318ddb9c76cbb 100644
> --- a/drivers/hid/hid-core.c
> +++ b/drivers/hid/hid-core.c
[ ... ]
> @@ -2857,7 +2858,10 @@ static int __hid_device_probe(struct hid_device *hdev, struct hid_driver *hdrv)
> hid_device_io_stop(hdev);
> devres_release_group(&hdev->dev, hdev->devres_group_id);
> hid_close_report(hdev);
> + hid_plugin_cleanup(hdev);
> hdev->driver = NULL;
> + } else {
> + hid_plugin_prune(hdev);
> }
>
> return ret;
[Severity: Low]
Can hid_plugin_prune() race with incoming HID reports when a driver returns
from probe() with hdev->io_started still set?
Drivers such as hidpp_probe() in drivers/hid/hid-logitech-hidpp.c call
hid_device_io_start(hdev) and return 0 without calling hid_device_io_stop().
Because __hid_input_report() serializes against probe through
hdev->driver_input_lock rather than device_lock(&hdev->dev), an input report
handler calling hid_plugin_to_priv() can race with hid_plugin_prune():
CPU0 CPU1
__hid_device_probe()
hdrv->probe()
hid_device_io_start(hdev)
return 0
hid_plugin_prune(hdev)
hid_plugin_disconnect_with_err()
__hid_input_report()
down_trylock(&driver_input_lock)
hid_plugin_to_priv(hdev, id)
plugin->disconnect(hdev, priv)
hdev->plugins[id] = ERR_PTR()
module_put(plugin->owner)
... uses priv <-- use-after-free
No current in-tree driver triggers this today, since the drivers that leave
hdev->io_started set do not call hid_plugin_to_priv() from report handlers,
but it breaks the lockless hid_plugin_to_priv() contract for future callers.
Calling hid_device_io_stop(hdev) when hdev->io_started is true before
disconnecting unbound plugins would serialize pruning against
__hid_input_report(), and hid_device_probe() immediately re-enables input
on return.
[ ... ]
> diff --git a/drivers/hid/hid-plugin.h b/drivers/hid/hid-plugin.h
> new file mode 100644
> index 0000000000000..2d411e9702850
> --- /dev/null
> +++ b/drivers/hid/hid-plugin.h
[ ... ]
> + * @connect: Called on plugin connection to allocate and initialize the
> + * plugin's private data. Usually the private data stores a pointer
> + * to the plugin itself to expose plugin-specific methods. Context:
> + * process context during driver probe.
> + * @disconnect: Called on plugin disconnection to release all allocated
> + * resources. Must be safe to call no matter the plugin is
> + * currently bound or not. Context: process context during driver
> + * probe or removal.
[Severity: Low]
Should the kernel-doc for @connect and @disconnect document that plugin
private data and resources freed in @disconnect must not be allocated with
devm_* tied to &hdev->dev, and that HID reports are already closed when
@disconnect runs during cleanup?
Both __hid_device_probe() on failure and hid_device_remove() call
devres_release_group() and hid_close_report() before hid_plugin_cleanup().
A plugin using devm_* on &hdev->dev would hit a use-after-free or double
free in @disconnect on teardown, and would leak those allocations on early
hid_plugin_disconnect() or hid_plugin_prune().
[ ... ]
> + * Context: Any context outside the plugin module. Can only be called while
> + * probing or removing @hdev driver.
> + */
> +static __always_inline void hid_plugin_disconnect(struct hid_device *hdev, enum hid_plugin_id id)
[Severity: Low]
Should the Context annotations for hid_plugin_disconnect(),
hid_plugin_prune(), hid_plugin_cleanup(), and hid_plugin_exit() specify
process context instead of any context?
__hid_plugin_disconnect(), __hid_plugin_prune(), and __hid_plugin_cleanup()
all assert device_lock(&hdev->dev) and invoke plugin->bound() or
plugin->disconnect(), which are documented as process context and may sleep.
__hid_plugin_exit() calls disable_delayed_work_sync(), which also sleeps.
In addition, hid_plugin_connect() and hid_plugin_disconnect() do not note
that HID input report handling must not be active (driver_input_lock must
be held) while mutating hdev->plugins[id].
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261206-hid-haptic-kmod-v7-0-3eea47035836@rong.moe?part=5
next prev parent reply other threads:[~2026-12-05 19:12 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 18:41 [PATCH v7 00/13] HID: Add hid-plugin framework & convert hid-haptic into a generic plugin Rong Zhang
2026-12-05 18:41 ` [PATCH v7 01/13] HID: haptic: Get rid of input_ff_destroy() in error paths Rong Zhang
2026-12-05 18:58 ` sashiko-bot
2026-12-05 19:24 ` Rong Zhang
2026-12-05 18:41 ` [PATCH v7 02/13] HID: haptic: Fix use-after-free when draining workqueue Rong Zhang
2026-12-05 18:41 ` [PATCH v7 03/13] HID: haptic, multitouch: Check haptic prerequisite properly Rong Zhang
2026-12-05 19:03 ` sashiko-bot
2026-12-05 19:26 ` Rong Zhang
2026-12-05 18:41 ` [PATCH v7 04/13] HID: haptic: Postpone GET_REPORT to init Rong Zhang
2026-12-05 19:02 ` sashiko-bot
2026-12-05 18:41 ` [PATCH v7 05/13] HID: Add hid-plugin framework for loadable plugin modules Rong Zhang
2026-12-05 19:12 ` sashiko-bot [this message]
2026-12-05 18:41 ` [PATCH v7 06/13] HID: haptic: Convert to a loadable plugin module Rong Zhang
2026-12-05 19:11 ` sashiko-bot
2026-12-05 18:41 ` [PATCH v7 07/13] HID: haptic: Adopt pr_fmt, dev_fmt and hid_*() printk helpers Rong Zhang
2026-12-05 18:41 ` [PATCH v7 08/13] HID: Add Ordinal page defines Rong Zhang
2026-12-05 18:41 ` [PATCH v7 09/13] HID: haptic: Handle list reports separately and make auto trigger optional Rong Zhang
2026-12-05 18:41 ` [PATCH v7 10/13] HID: haptic: Decouple from hid-multitouch and support other devices Rong Zhang
2026-12-05 19:08 ` sashiko-bot
2026-12-05 18:42 ` [PATCH v7 11/13] HID: haptic: Add quirk table Rong Zhang
2026-12-05 18:42 ` [PATCH v7 12/13] HID: haptic: Add HID_HAPTIC_QUIRK_NO_RETRIGGER to disable retriggering Rong Zhang
2026-12-05 18:42 ` [PATCH v7 13/13] HID: haptic: Add quirk flag for Logitech MX Master 4 Rong Zhang
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-251852@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=i@rong.moe \
--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