From: Guangshuo Li <lgs201920130244@gmail.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Guangshuo Li <lgs201920130244@gmail.com>,
Kees Cook <kees@kernel.org>,
Peter Hutterer <peter.hutterer@who-t.net>,
Benjamin Tissoires <bentiss@kernel.org>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] Input: wacom_w8001 - avoid double release of pen input device
Date: Thu, 30 Apr 2026 15:13:11 +0800 [thread overview]
Message-ID: <20260430071311.451957-1-lgs201920130244@gmail.com> (raw)
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>
---
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
next reply other threads:[~2026-04-30 7:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-30 7:13 Guangshuo Li [this message]
2026-05-14 7:10 ` [PATCH] Input: wacom_w8001 - avoid double release of pen input device Peter Hutterer
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=20260430071311.451957-1-lgs201920130244@gmail.com \
--to=lgs201920130244@gmail.com \
--cc=bentiss@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=kees@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peter.hutterer@who-t.net \
/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