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: adi - bound the two-stream packet merge
Date: Tue, 03 Nov 2026 08:55:51 +0000 [thread overview]
Message-ID: <sashiko-outbox-194899@kernel.org> (raw)
In-Reply-To: <20261103084135.426629-3-zhugl3@xiaopeng.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Input: adi: off-by-one check and uninvalidated streams in adi_move_bits()
--
commit 72de23854de8740c131cf08cbda4e0025c231b6c
Author: Guanglei Zhu <zhugl3@xiaopeng.com>
Input: adi - bound the two-stream packet merge
This commit adds bounds checks in adi_move_bits() before merging the
second ADI stream into adi[0].data to prevent out-of-bounds reads and
writes when the packet length is oversized.
> diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
> index e07b71978509b..03535e58d6a60 100644
> --- a/drivers/input/joystick/adi.c
> +++ b/drivers/input/joystick/adi.c
> @@ -168,6 +168,9 @@ static void adi_move_bits(struct adi_port *port, int length)
>
> if (adi[0].ret <= 0 || adi[1].ret <= 0) return;
> if (adi[0].data[0] & 0x20 || ~adi[1].data[0] & 0x20) return;
> + if (adi[0].ret + adi[1].ret > ADI_MAX_LENGTH ||
> + ((length - 1) >> 1) + adi[1].ret + 1 >= ADI_MAX_LENGTH)
> + return;
[Severity: Medium]
Should the first check here use >= ADI_MAX_LENGTH instead of > ADI_MAX_LENGTH,
and should adi[0].ret and adi[1].ret be invalidated before returning?
In struct adi, data is declared as unsigned char data[ADI_MAX_LENGTH], with
index 0 storing the start bit and payload bits stored at 1-based indices
1..ret. In adi_get_bits(), the index is incremented before checking against
adi->ret:
if ((adi->idx += count) > adi->ret) return 0;
for (i = 0; i < count; i++)
bits |= ((adi->data[adi->idx - i] >> 5) & 1) << i;
Because adi[0].ret + adi[1].ret > ADI_MAX_LENGTH allows adi[0].ret to reach
ADI_MAX_LENGTH (256), if adi_decode() consumes 256 bits, adi_get_bits() will
reach adi->idx == adi->ret == 256 and read adi[0].data[256] one byte past the
end of adi[0].data[].
In addition, once adi_move_bits() has verified that the packet is in 2-stream
mode (!(adi[0].data[0] & 0x20) && (adi[1].data[0] & 0x20)), returning early
without setting adi[0].ret = adi[1].ret = -1 leaves both unmerged half-streams
marked valid (ret > 0). Wouldn't that cause adi_connect() and adi_read() to
decode the unmerged half-streams in adi[0] and adi[1] as if they were valid
standalone packets instead of rejecting the malformed 2-stream read?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261103084135.426629-3-zhugl3@xiaopeng.com?part=1
next prev parent reply other threads:[~2026-11-03 8:55 UTC|newest]
Thread overview: 14+ 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
2026-11-03 8:55 ` [PATCH v2] " 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 [this message]
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-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-03 8:41 ` [PATCH] Input: cyapa_gen3 - clamp the reported finger count to the array Guanglei Zhu
2026-11-03 18:45 ` [PATCH] Input: joydev - avoid an undefined shift in the legacy 0x read Dmitry Torokhov
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-194899@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox