From: Peter Hutterer <peter.hutterer@who-t.net>
To: Guangshuo Li <lgs201920130244@gmail.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Kees Cook <kees@kernel.org>,
Benjamin Tissoires <bentiss@kernel.org>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Input: wacom_w8001 - avoid double release of pen input device
Date: Thu, 14 May 2026 17:10:54 +1000 [thread overview]
Message-ID: <20260514071054.GA66370@tassie> (raw)
In-Reply-To: <20260430071311.451957-1-lgs201920130244@gmail.com>
On Thu, Apr 30, 2026 at 03:13:11PM +0800, Guangshuo Li wrote:
> When registering the touch input device fails after the pen input device
> has already been registered, w8001_connect() jumps to fail4 and
> unregisters w8001->pen_dev. It then falls through to fail1 where
> input_dev_pen is passed to input_free_device().
>
> Once input_register_device() has succeeded, the device must be released
> with input_unregister_device(), and input_free_device() must not be used
> on the same object afterwards. Since input_dev_pen still aliases
> w8001->pen_dev, this can result in a use-after-free or kref underflow.
>
> Clear the local and container aliases after unregistering the pen device
> so that the common cleanup path does not try to free it again.
>
> This issue was found by a static analysis tool I am developing.
>
> Fixes: e0361b70175f0 ("Input: wacom_w8001 - split the touch and pen devices into two devices")
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
thanks
Cheers,
Peter
> ---
> drivers/input/touchscreen/wacom_w8001.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/input/touchscreen/wacom_w8001.c b/drivers/input/touchscreen/wacom_w8001.c
> index 45930d731873..a3b283c59cdd 100644
> --- a/drivers/input/touchscreen/wacom_w8001.c
> +++ b/drivers/input/touchscreen/wacom_w8001.c
> @@ -665,8 +665,11 @@ static int w8001_connect(struct serio *serio, struct serio_driver *drv)
> return 0;
>
> fail4:
> - if (w8001->pen_dev)
> + if (w8001->pen_dev) {
> input_unregister_device(w8001->pen_dev);
> + input_dev_pen = NULL;
> + w8001->pen_dev = NULL;
> + }
> fail3:
> serio_close(serio);
> fail2:
> --
> 2.43.0
>
parent reply other threads:[~2026-05-14 7:11 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20260430071311.451957-1-lgs201920130244@gmail.com>]
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=20260514071054.GA66370@tassie \
--to=peter.hutterer@who-t.net \
--cc=bentiss@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=kees@kernel.org \
--cc=lgs201920130244@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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