From: "Günther Noack" <gnoack@google.com>
To: "Derek J. Clark" <derekjohn.clark@gmail.com>
Cc: Manish Khadka <maskmemanish@gmail.com>,
dmitry.torokhov@gmail.com, linux-input@vger.kernel.org,
sashiko-reviews@lists.linux.dev, Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <bentiss@kernel.org>,
Lee Jones <joneslee@google.com>,
Mark Pearson <mpearson-lenovo@squebb.ca>
Subject: Re: [PATCH v2] HID: hid-lenovo-go: cancel cfg_setup work in hid_go_cfg_remove()
Date: Tue, 7 Jul 2026 11:06:12 +0200 [thread overview]
Message-ID: <akzBhKTOVpaTb4nT@google.com> (raw)
In-Reply-To: <20260515182347.6C82FC2BCB0@smtp.kernel.org>
Hello Derek and Mark!
May I please draw your attention to this issue in the hid-lenovo drivers,
which was pointed out by Sashiko:
On Fri, May 15, 2026 at 06:23:46PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
> - [Critical] Hardware state corruption and crashes due to use of a static global struct for device data.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > diff --git a/drivers/hid/hid-lenovo-go.c b/drivers/hid/hid-lenovo-go.c
> > index d4d26c7833563..b9d8cde531365 100644
> > --- a/drivers/hid/hid-lenovo-go.c
> > +++ b/drivers/hid/hid-lenovo-go.c
> > @@ -2408,6 +2408,15 @@ static int hid_go_cfg_probe(struct hid_device *hdev,
> >
> > static void hid_go_cfg_remove(struct hid_device *hdev)
> > {
> > + /*
> > + * cfg_setup is scheduled from hid_go_cfg_probe() with a 2 ms delay
> > + * and dereferences drvdata.hdev. Drain it here before tearing
> > + * down so the workqueue cannot run after hid_destroy_device()'s
> > + * put_device() has released the underlying hdev and dereference
> > + * a stale drvdata.hdev pointer.
> > + */
> > + cancel_delayed_work_sync(&drvdata.go_cfg_setup);
>
> This isn't a bug introduced by this patch, but does the driver use a global
> static variable (static struct hid_go_cfg drvdata) to store device state?
>
> A second device probe would unconditionally overwrite drvdata.hdev and
> re-initialize both drvdata.cfg_mutex and drvdata.go_cfg_setup.
>
> Re-initializing an active mutex destroys its wait lists, and re-initializing
> an active delayed work overwrites its linked list pointers, leading to
> immediate memory corruption and kernel panics.
>
> Should the device state be dynamically allocated per-instance instead?
This is the same issue which was also introduced in hid-oxp, which I
pointed out in [1]. As the review-bot points out above, while the data in
your static drvdata variable is maybe only necessary once (but that
also seems questionable?), I think the mutex and workqueue shouldn't
just get re-initialized in the middle of being used, when a second device is
plugged in and the probe() hook runs again.
This pattern is used in both the drivers hid-lenovo-go.c, hid-lenovo-go-s.c,
as well as in the newer hid-oxp discussed in [1].
Shouldn't the drvdata just be allocated with one of the devm_*alloc() variants
as in the other drivers?
—Günther
[1] https://lore.kernel.org/all/akfGTjId84EjV141@google.com/
next prev parent reply other threads:[~2026-07-07 9:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-15 15:36 [PATCH] HID: hid-lenovo-go: cancel cfg_setup work in hid_go_cfg_remove() Manish Khadka
2026-05-15 16:18 ` sashiko-bot
2026-05-15 17:45 ` [PATCH v2] " Manish Khadka
2026-05-15 18:23 ` sashiko-bot
2026-07-07 9:06 ` Günther Noack [this message]
2026-07-07 15:19 ` Derek J. Clark
2026-05-25 3:09 ` [PATCH] " Derek J. Clark
2026-06-03 12:19 ` Jiri Kosina
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=akzBhKTOVpaTb4nT@google.com \
--to=gnoack@google.com \
--cc=bentiss@kernel.org \
--cc=derekjohn.clark@gmail.com \
--cc=dmitry.torokhov@gmail.com \
--cc=jikos@kernel.org \
--cc=joneslee@google.com \
--cc=linux-input@vger.kernel.org \
--cc=maskmemanish@gmail.com \
--cc=mpearson-lenovo@squebb.ca \
--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