* [PATCH 5.15.y] Input: aiptek - validate raw macro indices before updating state
@ 2026-09-07 18:49 Miguel Garcia
2026-09-07 19:00 ` sashiko-bot
2026-09-08 22:39 ` Sasha Levin
0 siblings, 2 replies; 3+ messages in thread
From: Miguel Garcia @ 2026-09-07 18:49 UTC (permalink / raw)
To: stable; +Cc: dmitry.torokhov, gregkh, pengpeng, linux-input, linux-kernel
From: Pengpeng Hou <pengpeng@iscas.ac.cn>
aiptek_irq() derives macro key indices directly from tablet reports and
then uses them to index macroKeyEvents[]. Report types 4 and 5 also save
the derived value in aiptek->lastMacro and later use that state to
release the previous key.
Validate the raw macro index once before it enters that state machine, so
lastMacro only ever stores an in-range macro key. Keep direct bounds
checks for report type 6, which reads the macro number from the packet
body and uses it immediately.
Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn>
Link: https://patch.msgid.link/20260329001711.88076-1-pengpeng@iscas.ac.cn
[dtor: fix macro fallback in report 5s to use -1]
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
(cherry picked from commit 95dffe32a66cbed07fbfa7afed39d56d5014e04f)
Signed-off-by: Miguel Garcia <miguelgarciaroman8@gmail.com>
---
drivers/input/tablet/aiptek.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/input/tablet/aiptek.c b/drivers/input/tablet/aiptek.c
index 1581f6ef09279..64113810e16dc 100644
--- a/drivers/input/tablet/aiptek.c
+++ b/drivers/input/tablet/aiptek.c
@@ -658,6 +658,8 @@ static void aiptek_irq(struct urb *urb)
pck = (data[1] & aiptek->curSetting.stylusButtonUpper) != 0 ? 1 : 0;
macro = dv && p && tip && !(data[3] & 1) ? (data[3] >> 1) : -1;
+ if (macro >= ARRAY_SIZE(macroKeyEvents))
+ macro = -1;
z = get_unaligned_le16(data + 4);
if (dv) {
@@ -699,7 +701,9 @@ static void aiptek_irq(struct urb *urb)
left = (data[1]& aiptek->curSetting.mouseButtonLeft) != 0 ? 1 : 0;
right = (data[1] & aiptek->curSetting.mouseButtonRight) != 0 ? 1 : 0;
middle = (data[1] & aiptek->curSetting.mouseButtonMiddle) != 0 ? 1 : 0;
- macro = dv && p && left && !(data[3] & 1) ? (data[3] >> 1) : 0;
+ macro = dv && p && left && !(data[3] & 1) ? (data[3] >> 1) : -1;
+ if (macro >= ARRAY_SIZE(macroKeyEvents))
+ macro = -1;
if (dv) {
/* If the selected tool changed, reset the old
@@ -737,11 +741,11 @@ static void aiptek_irq(struct urb *urb)
*/
else if (data[0] == 6) {
macro = get_unaligned_le16(data + 1);
- if (macro > 0) {
+ if (macro > 0 && macro - 1 < ARRAY_SIZE(macroKeyEvents)) {
input_report_key(inputdev, macroKeyEvents[macro - 1],
0);
}
- if (macro < 25) {
+ if (macro + 1 < ARRAY_SIZE(macroKeyEvents)) {
input_report_key(inputdev, macroKeyEvents[macro + 1],
0);
}
@@ -760,7 +764,8 @@ static void aiptek_irq(struct urb *urb)
aiptek->curSetting.toolMode;
}
- input_report_key(inputdev, macroKeyEvents[macro], 1);
+ if (macro < ARRAY_SIZE(macroKeyEvents))
+ input_report_key(inputdev, macroKeyEvents[macro], 1);
input_report_abs(inputdev, ABS_MISC,
1 | AIPTEK_REPORT_TOOL_UNKNOWN);
input_sync(inputdev);
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 5.15.y] Input: aiptek - validate raw macro indices before updating state
2026-09-07 18:49 [PATCH 5.15.y] Input: aiptek - validate raw macro indices before updating state Miguel Garcia
@ 2026-09-07 19:00 ` sashiko-bot
2026-09-08 22:39 ` Sasha Levin
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-09-07 19:00 UTC (permalink / raw)
To: Miguel Garcia; +Cc: linux-input, dmitry.torokhov
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] A race condition between sysfs attribute accesses and `aiptek_disconnect()` can lead to a NULL pointer dereference, causing an unprivileged local Denial of Service.
--
commit a32cea658c5c9deb2bbaf0f172438e8f70443904
Author: Pengpeng Hou <pengpeng@iscas.ac.cn>
Input: aiptek - validate raw macro indices before updating state
aiptek_irq() derives macro key indices directly from tablet reports and
then uses them to index macroKeyEvents[]. Report types 4 and 5 also save
the derived value in aiptek->lastMacro and later use that state to
release the previous key.
Validate the raw macro index once before it enters that state machine, so
lastMacro only ever stores an in-range macro key. Keep direct bounds
checks for report type 6, which reads the macro number from the packet
body and uses it immediately.
Link: https://patch.msgid.link/20260329001711.88076-1-pengpeng@iscas.ac.cn
> diff --git a/drivers/input/tablet/aiptek.c b/drivers/input/tablet/aiptek.c
> index 1581f6ef09279..64113810e16dc 100644
> --- a/drivers/input/tablet/aiptek.c
> +++ b/drivers/input/tablet/aiptek.c
[ ... ]
[Severity: High]
This isn't a bug introduced by this patch, but while reviewing the driver I
noticed a pre-existing issue in the sysfs removal path during disconnect:
drivers/input/tablet/aiptek.c:aiptek_disconnect() {
...
usb_set_intfdata(intf, NULL);
if (aiptek != NULL) {
/* Free & unhook everything from the system.
*/
usb_kill_urb(aiptek->urb);
input_unregister_device(aiptek->inputdev);
sysfs_remove_group(&intf->dev.kobj, &aiptek_attribute_group);
...
}
Does clearing the driver data with usb_set_intfdata() before removing the
sysfs group create a race window?
If a concurrent read accesses the sysfs file during this window:
drivers/input/tablet/aiptek.c:show_tabletSize() {
struct aiptek *aiptek = dev_get_drvdata(dev);
return sysfs_emit(buf, "%dx%d\n",
input_abs_get_max(aiptek->inputdev, ABS_X) + 1,
input_abs_get_max(aiptek->inputdev, ABS_Y) + 1);
}
Could dev_get_drvdata() return NULL here and cause a kernel panic when
aiptek is dereferenced?
Similarly, if a sysfs write occurs in the same window:
drivers/input/tablet/aiptek.c:store_tabletExecute() {
struct aiptek *aiptek = dev_get_drvdata(dev);
/* We do not care what you write to this file. Merely the action
* of writing to this file triggers a tablet reprogramming.
*/
memcpy(&aiptek->curSetting, &aiptek->newSetting,
sizeof(struct aiptek_settings));
...
}
Can a concurrent sysfs write also fetch a NULL pointer and use it as the
destination for the memcpy()?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260907184956.1567815-1-miguelgarciaroman8@gmail.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 5.15.y] Input: aiptek - validate raw macro indices before updating state
2026-09-07 18:49 [PATCH 5.15.y] Input: aiptek - validate raw macro indices before updating state Miguel Garcia
2026-09-07 19:00 ` sashiko-bot
@ 2026-09-08 22:39 ` Sasha Levin
1 sibling, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2026-09-08 22:39 UTC (permalink / raw)
To: stable
Cc: Sasha Levin, dmitry.torokhov, gregkh, pengpeng, linux-input,
linux-kernel, Miguel Garcia
> aiptek_irq() derives macro key indices directly from tablet reports and
> then uses them to index macroKeyEvents[]. Report types 4 and 5 also save
> the derived value in aiptek->lastMacro and later use that state to
> release the previous key.
Queued for 5.15, thanks.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-08 22:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-07 18:49 [PATCH 5.15.y] Input: aiptek - validate raw macro indices before updating state Miguel Garcia
2026-09-07 19:00 ` sashiko-bot
2026-09-08 22:39 ` Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox