* Re: [PATCH] Input: wacom_w8001 - avoid double release of pen input device
[not found] <20260430071311.451957-1-lgs201920130244@gmail.com>
@ 2026-05-14 7:10 ` Peter Hutterer
0 siblings, 0 replies; only message in thread
From: Peter Hutterer @ 2026-05-14 7:10 UTC (permalink / raw)
To: Guangshuo Li
Cc: Dmitry Torokhov, Kees Cook, Benjamin Tissoires, linux-input,
linux-kernel
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
>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-05-14 7:11 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260430071311.451957-1-lgs201920130244@gmail.com>
2026-05-14 7:10 ` [PATCH] Input: wacom_w8001 - avoid double release of pen input device Peter Hutterer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox