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 06/13] HID: haptic: Convert to a loadable plugin module
Date: Sat, 05 Dec 2026 19:11:10 +0000 [thread overview]
Message-ID: <sashiko-outbox-251851@kernel.org> (raw)
In-Reply-To: <20261206-hid-haptic-kmod-v7-6-3eea47035836@rong.moe>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] HID: hidinput_connect() misses driver EV_FF registered on
non-first input
- [Medium] HID: haptic: deferred input_ff_destroy() races with
hid_plugin_cleanup()
- [Low] HID: hidinput_connect() checks >= 0 instead of > 0 on haptic
setup
- [Low] hid: undocumented struct hid_device plugins type fixup belongs
in prior commit
--
commit 12dbd9791931128158828d6e3e2e142a60955399
Author: Rong Zhang <i@rong.moe>
HID: haptic: Convert to a loadable plugin module
This commit converts hid-haptic into a loadable hid-plugin module and
moves its feature mapping, input mapping, and FF registration hooks into
hid-input.
Link: https://lore.kernel.org/linux-input/auypydfkhx2eg7vp764way4batdilzc35inqda3exwzs3tk3ff@oagat6g46zto/
> diff --git a/drivers/hid/hid-haptic.c b/drivers/hid/hid-haptic.c
> index 43e9aa60fca9d..ab2366a58de4b 100644
> --- a/drivers/hid/hid-haptic.c
> +++ b/drivers/hid/hid-haptic.c
[ ... ]
> +static bool hid_haptic_plugin_bound(struct hid_device *hdev, void *data)
> +{
> + struct hid_haptic_device *haptic = data;
> +
> + return !!haptic->wq;
> }
> -EXPORT_SYMBOL_GPL(hid_haptic_pressure_increase);
> +
> +static void hid_haptic_plugin_disconnect(struct hid_device *hdev, void *data)
> +{
> + /*
> + * The FF device must have been destroyed when we reach here, but if
> + * something goes wrong, leak our private data and pray...
> + */
> + if (!WARN_ON(hid_haptic_plugin_bound(hdev, data)))
> + kfree(data);
> +}
[Severity: Medium]
Can deferred input_ff_destroy() race with hid_plugin_cleanup() and cause a
use-after-free on haptic or on unloaded hid-haptic module text?
If hidinput_connect() fails after hid_haptic_init() (for example
input_register_device() fails with -EINTR after device_add()),
hidinput_disconnect() calls input_free_device() on the unregistered
hidinput->input without calling input_ff_destroy(). When a concurrent
device_for_each_child() iterator still holds a reference on &dev->dev (or
under CONFIG_DEBUG_KOBJECT_RELEASE), input_dev_release() and
hid_haptic_destroy() are deferred past hidinput_disconnect().
CPU0 CPU1
hidinput_disconnect()
input_free_device()
/* klist iter still holds ref */
put_device(&dev->dev)
input_dev_release()
hid_haptic_destroy()
destroy_workqueue(haptic->wq)
haptic->wq = NULL
hid_plugin_cleanup()
hid_haptic_plugin_disconnect()
!hid_haptic_plugin_bound()
kfree(haptic)
module_put(plugin->owner)
kfree(haptic->stop_effect...)
<-- use-after-free
If hid_plugin_cleanup() runs before haptic->wq is cleared,
hid_haptic_plugin_disconnect() hits the WARN_ON() and leaks haptic, while
hid_plugin_disconnect_with_err() still drops the module reference, allowing
hid-haptic to be unloaded before hid_haptic_destroy() executes.
Calling input_ff_destroy(hidinput->input) before
input_free_device(hidinput->input) in hidinput_disconnect(), and clearing
haptic->wq last in hid_haptic_destroy(), would avoid both races.
> diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
> index 80cdd2f2beffe..05025746c80e3 100644
> --- a/drivers/hid/hid-input.c
> +++ b/drivers/hid/hid-input.c
[ ... ]
> @@ -2409,21 +2424,43 @@ int hidinput_connect(struct hid_device *hid, unsigned int connect_mask)
>
> hidinput_change_resolution_multipliers(hid);
>
> + /*
> + * If the driver manages haptic, honor its choice and do not register
> + * any FF device ourselves.
> + */
> + driver_ff = hid_haptic_connected_to_input(hid, NULL);
> + haptic_ff = !driver_ff && hid_haptic_input_configured(hid, NULL) >= 0;
> +
> list_for_each_entry_safe(hidinput, next, &hid->inputs, list) {
> + bool first = list_is_first(&hidinput->list, &hid->inputs);
> +
> if (drv->input_configured &&
> drv->input_configured(hid, hidinput))
> goto out_unwind;
>
> + if (first && !driver_ff) {
> + driver_ff = hid_has_ff_input(hid) || !(connect_mask & HID_CONNECT_FF);
> + if (haptic_ff && driver_ff) {
> + hid_info(hid, "prefer driver's FF over haptic\n");
> + haptic_ff = false;
> + }
> + }
[Severity: Medium]
Can this clobber and leak a driver's ff_device when a multi-input HID
device registers EV_FF in drv->input_configured() on a non-first hidinput?
Because the hid_has_ff_input(hid) check is gated on first, driver_ff stays
false and haptic_ff stays true on later hidinput entries. If
hid_haptic_input_configured() then calls hid_haptic_init() ->
input_ff_create() on that same input_dev, input_ff_create() unconditionally
overwrites dev->ff without destroying the driver's existing ff_device.
Also, deferring !(connect_mask & HID_CONNECT_FF) until inside the loop runs
hid_haptic_input_configured(hid, NULL) unnecessarily and logs "prefer
driver's FF over haptic" when the driver simply omitted HID_CONNECT_FF.
Checking !(connect_mask & HID_CONNECT_FF) before the loop and checking
hid_has_ff_input(hid) on each iteration while !driver_ff would handle both.
> if (!hidinput_has_been_populated(hidinput)) {
> /* no need to register an input device not populated */
> hidinput_cleanup_hidinput(hid, hidinput);
> continue;
> }
>
> - if (list_is_first(&hidinput->list, &hid->inputs) &&
> - (connect_mask & HID_CONNECT_FF) && hid->ff_init &&
> - !hid_has_ff_input(hid))
> - hid->ff_init(hid);
> + if (first && !driver_ff && hid->ff_init)
> + driver_ff = !hid->ff_init(hid);
> +
> + if (haptic_ff && driver_ff) {
> + hid_info(hid, "prefer PIDFF over haptic\n");
> + haptic_ff = false;
> + } else if (haptic_ff) {
> + haptic_ff = hid_haptic_input_configured(hid, hidinput) >= 0;
> + }
[Severity: Low]
Should this check > 0 instead of >= 0?
__hid_haptic_input_configured() returns 0 once haptic FF is bound and 1
while still waiting for the target hidinput. Using >= 0 leaves haptic_ff
true after binding succeeds, so every remaining hidinput on a multi-input
device keeps calling hid_haptic_input_configured().
> diff --git a/include/linux/hid.h b/include/linux/hid.h
> index f881f5631cfe5..4ea9cb4b49f9a 100644
> --- a/include/linux/hid.h
> +++ b/include/linux/hid.h
[ ... ]
> @@ -765,7 +771,7 @@ struct hid_device {
> struct hid_bpf bpf; /* hid-bpf data */
> #endif /* CONFIG_HID_BPF */
>
> - struct hid_plugin_private *plugins[NR_HID_PLUGINS];
> + void *plugins[NR_HID_PLUGINS];
> };
[Severity: Low]
This type fixup isn't mentioned in the commit message and is unrelated to
converting hid-haptic. Should it be squashed into commit "HID: Add
hid-plugin framework for loadable plugin modules", which introduced struct
hid_plugin_private?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261206-hid-haptic-kmod-v7-0-3eea47035836@rong.moe?part=6
next prev parent reply other threads:[~2026-12-05 19:11 UTC|newest]
Thread overview: 23+ 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 19:55 ` Rong Zhang
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
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 [this message]
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-251851@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 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.