From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Lee Jones <lee@kernel.org>
Cc: Marek Vasut <marek.vasut@gmail.com>,
Arnd Bergmann <arnd@arndb.de>, Linus Walleij <linusw@kernel.org>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH 01/10] Input: matrix_keypad - validate GPIO counts against matrix limits
Date: Mon, 23 Nov 2026 12:12:58 -0800 [thread overview]
Message-ID: <awSdwBnT5bk_BS-G@google.com> (raw)
In-Reply-To: <20261123183200.3900004-2-lee@kernel.org>
On Mon, Nov 23, 2026 at 06:31:07PM +0000, Lee Jones wrote:
> matrix_keypad_init_gpio() obtains the row and column GPIO counts via
> gpiod_count() and only checks for negative error codes before storing
> them in keypad->num_row_gpios and keypad->num_col_gpios.
>
> If firmware supplies more than MATRIX_MAX_ROWS (32) row GPIOs or
> MATRIX_MAX_COLS (32) column GPIOs, the setup loops write past the fixed
> row_gpios, col_gpios, and row_irqs arrays inside struct matrix_keypad,
> and matrix_keypad_scan() overflows the stack-allocated new_state array.
> Conversely, a zero count causes get_count_order() to return -1, leading
> to an undefined shift when computing row_shift.
>
> Reject non-positive GPIO counts as well as counts exceeding
> MATRIX_MAX_ROWS or MATRIX_MAX_COLS, and size col_gpios with
> MATRIX_MAX_COLS for consistency.
>
> Fixes: 584bf366f8fa ("Input: matrix_keypad - switch to gpiod API and generic device properties")
> Closes: https://sashiko.dev/#/bug/linux-ed4b89af-6c76-4e5f-b140-fb2b107b12d0
> Cc: stable@vger.kernel.org
We trust DT somewhat so I do not think this needs to be in stable.
> Signed-off-by: Lee Jones <lee@kernel.org>
> ---
> drivers/input/keyboard/matrix_keypad.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
> index 11018382e84e..c2f839a3de90 100644
> --- a/drivers/input/keyboard/matrix_keypad.c
> +++ b/drivers/input/keyboard/matrix_keypad.c
> @@ -33,7 +33,7 @@ struct matrix_keypad {
> struct gpio_desc *row_gpios[MATRIX_MAX_ROWS];
> unsigned int num_row_gpios;
>
> - struct gpio_desc *col_gpios[MATRIX_MAX_ROWS];
> + struct gpio_desc *col_gpios[MATRIX_MAX_COLS];
Luckily they are the same...
> unsigned int num_col_gpios;
>
> unsigned int row_irqs[MATRIX_MAX_ROWS];
> @@ -302,11 +302,16 @@ static int matrix_keypad_init_gpio(struct platform_device *pdev,
>
> nrow = gpiod_count(&pdev->dev, "row");
> ncol = gpiod_count(&pdev->dev, "col");
> - if (nrow < 0 || ncol < 0) {
> + if (nrow <= 0 || ncol <= 0) {
gpiod_count() never returns 0. It's either positive, or -ENOENT.
> dev_err(&pdev->dev, "missing row or column GPIOs\n");
> return -EINVAL;
> }
>
> + if (nrow > MATRIX_MAX_ROWS || ncol > MATRIX_MAX_COLS) {
> + dev_err(&pdev->dev, "too many row or column GPIOs\n");
> + return -EINVAL;
> + }
> +
> keypad->num_row_gpios = nrow;
> keypad->num_col_gpios = ncol;
>
Thanks.
--
Dmitry
next prev parent reply other threads:[~2026-11-23 20:13 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 18:31 [PATCH 00/10] Input: assorted bug fixes across input drivers Lee Jones
2026-11-23 18:31 ` [PATCH 01/10] Input: matrix_keypad - validate GPIO counts against matrix limits Lee Jones
2026-11-23 20:12 ` Dmitry Torokhov [this message]
2026-11-23 18:31 ` [PATCH 02/10] Input: cyapa - validate firmware image size in cyapa_pip_check_fw() Lee Jones
2026-11-23 18:31 ` [PATCH 03/10] Input: applespi - cancel touchpad registration work on removal Lee Jones
2026-11-23 18:31 ` [PATCH 04/10] Input: matrix_keypad - only stop and start active device across sleep Lee Jones
2026-11-23 18:42 ` sashiko-bot
2026-11-23 18:31 ` [PATCH 05/10] Input: stinger - zero-initialise driver state in stinger_connect() Lee Jones
2026-11-23 18:31 ` [PATCH 06/10] Input: synaptics-rmi4 - check for NULL drvdata in rmi_set_attn_data() Lee Jones
2026-11-23 18:31 ` [PATCH 07/10] Input: axp20x-pek - skip IRQ handling during sleep without input device Lee Jones
2026-11-23 18:31 ` [PATCH 08/10] Input: mt6779-keypad - enable keypad clock before programming registers Lee Jones
2026-11-23 18:31 ` [PATCH 09/10] Input: pinephone-keyboard - request IRQ before registering input device Lee Jones
2026-11-23 18:31 ` [PATCH 10/10] Input: wacom_w8001 - use reinit_completion() in w8001_command() Lee Jones
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=awSdwBnT5bk_BS-G@google.com \
--to=dmitry.torokhov@gmail.com \
--cc=arnd@arndb.de \
--cc=lee@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marek.vasut@gmail.com \
--cc=stable@vger.kernel.org \
/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