From: sashiko-bot@kernel.org
To: "Guanglei Zhu" <zhugl3@xiaopeng.com>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH] Input: joydev - avoid signed overflow in the broken-axis correction
Date: Tue, 03 Nov 2026 08:48:42 +0000 [thread overview]
Message-ID: <sashiko-outbox-194881@kernel.org> (raw)
In-Reply-To: <20261103084135.426629-2-zhugl3@xiaopeng.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Input: joydev - 32-bit overflow in joydev_correct() subtraction
- [Medium] Input: joydev - s64 truncation before clamp() in joydev_correct()
--
commit 1426ece8bea8b467a9629c0559c54b6693b90b43
Author: Guanglei Zhu <zhugl3@xiaopeng.com>
Input: joydev - avoid signed overflow in the broken-axis correction
This commit casts the coefficient operands in the JS_CORR_BROKEN calculation
in joydev_correct() to s64 to avoid 32-bit signed integer overflow during
multiplication when user-controlled coefficients are set via JSIOCSCORR.
> diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
> index 32459fd8a7c18..947d7671a59f6 100644
> --- a/drivers/input/joydev.c
> +++ b/drivers/input/joydev.c
> @@ -74,8 +74,8 @@ static int joydev_correct(int value, struct js_corr *corr)
>
> case JS_CORR_BROKEN:
> value = value > corr->coef[0] ? (value < corr->coef[1] ? 0 :
> - ((corr->coef[3] * (value - corr->coef[1])) >> 14)) :
> - ((corr->coef[2] * (value - corr->coef[0])) >> 14);
> + (((s64)corr->coef[3] * (value - corr->coef[1])) >> 14)) :
> + (((s64)corr->coef[2] * (value - corr->coef[0])) >> 14);
[Severity: Medium]
Can the parenthesized subtractions (value - corr->coef[1]) and
(value - corr->coef[0]) in joydev_correct() in drivers/input/joydev.c still
overflow 32-bit signed arithmetic before being promoted to s64 for the
multiplication?
When joydev_ioctl_common() processes JSIOCSCORR or joydev_event() handles an
EV_ABS event and calls joydev_correct(), both value (int) and corr->coef[i]
(__s32) are 32-bit signed integers. In the first branch, where
value > corr->coef[0] and value >= corr->coef[1], if value >= 0 and
corr->coef[0] and corr->coef[1] are large negative values such as INT_MIN,
evaluating value - corr->coef[1] overflows a 32-bit signed int before
promoting to s64. Likewise, in the second branch where value <= corr->coef[0],
if value < 0 and corr->coef[0] is a large positive value such as INT_MAX,
value - corr->coef[0] underflows a 32-bit signed int.
Would casting value to s64 inside the subtraction, such as
(s64)value - corr->coef[1] and (s64)value - corr->coef[0], avoid this
overflow as well?
[Severity: Medium]
What happens in joydev_correct() in drivers/input/joydev.c when the shifted
64-bit product exceeds the 32-bit signed int range before reaching clamp()?
Because two 32-bit signed values multiplied in s64 can have a magnitude up to
roughly 2^62, the result after >> 14 can still have a magnitude up to roughly
2^48. Assigning that s64 expression back into the 32-bit int variable value:
drivers/input/joydev.c:joydev_correct() {
...
case JS_CORR_BROKEN:
value = value > corr->coef[0] ? (value < corr->coef[1] ? 0 :
(((s64)corr->coef[3] * (value - corr->coef[1])) >> 14)) :
(((s64)corr->coef[2] * (value - corr->coef[0])) >> 14);
break;
default:
return 0;
}
return clamp(value, -32767, 32767);
}
truncates the upper bits before clamp(value, -32767, 32767) is evaluated,
causing large positive or negative results to wrap around rather than saturate
to 32767 or -32767. Should value or the intermediate result be kept as s64
until clamp_val() or clamp_t(s64, ...) is applied?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261103084135.426629-2-zhugl3@xiaopeng.com?part=1
next prev parent reply other threads:[~2026-11-03 8:48 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 8:41 [PATCH] Input: joydev - avoid an undefined shift in the legacy 0x read Guanglei Zhu
2026-11-03 8:41 ` [PATCH] Input: joydev - avoid signed overflow in the broken-axis correction Guanglei Zhu
2026-11-03 8:48 ` sashiko-bot [this message]
2026-11-03 8:55 ` [PATCH v2] " Guanglei Zhu
2026-11-04 3:38 ` Dmitry Torokhov
2026-11-04 5:50 ` [PATCH v3] " Guanglei Zhu
2026-11-04 6:02 ` Guanglei Zhu
2026-11-03 8:41 ` [PATCH] Input: adi - bound the two-stream packet merge Guanglei Zhu
2026-11-03 8:55 ` sashiko-bot
2026-11-03 11:17 ` [PATCH v2] " Guanglei Zhu
2026-11-03 8:41 ` [PATCH] Input: db9 - enlarge the Saturn multitap packet buffer Guanglei Zhu
2026-11-03 8:41 ` [PATCH] Input: lpc32xx-keys - reject matrices bigger than the hardware has Guanglei Zhu
2026-11-03 18:54 ` Dmitry Torokhov
2026-11-04 3:07 ` [PATCH v2] " Guanglei Zhu
2026-11-04 6:25 ` Dmitry Torokhov
2026-11-03 8:41 ` [PATCH] Input: mt6779-keypad - check the reported row and column Guanglei Zhu
2026-11-03 8:41 ` [PATCH] Input: tegra-kbc - check the pin numbers from the device tree Guanglei Zhu
2026-11-04 17:08 ` Dmitry Torokhov
2026-11-03 8:41 ` [PATCH] Input: cyapa_gen3 - clamp the reported finger count to the array Guanglei Zhu
2026-11-04 20:09 ` Dmitry Torokhov
2026-11-03 18:45 ` [PATCH] Input: joydev - avoid an undefined shift in the legacy 0x read Dmitry Torokhov
2026-11-04 3:07 ` [PATCH v2] " Guanglei Zhu
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=sashiko-outbox-194881@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=zhugl3@xiaopeng.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.