On Tue, Nov 03, 2026 at 04:41:32PM +0800, Guanglei Zhu wrote:
quoted hunk ↗ jump to hunk
The scanner state array holds the last state of eight matrix
columns, and the interrupt handler walks the matrix size that the
device tree declared:
u8 lastkeystates[8];
...
for (i = 0; i < kscandat->matrix_sz; i++)
lpc32xx_mod_states(kscandat, i);
The probe path only checks that rows and columns match; the
hardware supports square matrices from 1x1 up to 8x8, but nothing
stops a device tree from declaring more, which makes the state
array index run past the field into the rest of the driver data -
including the keymap pointer the same code dereferences.
Reject matrices larger than the hardware supports.
Fixes: 69690bec400e ("Input: add support for key scan interface of the LPC32xx SoC")
Cc: <redacted>
Signed-off-by: Guanglei Zhu <redacted>
---
drivers/input/keyboard/lpc32xx-keys.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/input/keyboard/lpc32xx-keys.c b/drivers/input/keyboard/lpc32xx-keys.c
index 285d5c32fe70..1d0b082e7881 100644
--- a/drivers/input/keyboard/lpc32xx-keys.c
+++ b/drivers/input/keyboard/lpc32xx-keys.c
@@ -142,6 +142,11 @@ static int lpc32xx_parse_dt(struct device *dev,
return -EINVAL;
}
+ if (rows > 8) {
This should be a constant/#define.
quoted hunk ↗ jump to hunk
+ dev_err(dev, "rows and columns must be at most 8!\n");
+ return -EINVAL;
+ }
+
kscandat->matrix_sz = rows;
kscandat->row_shift = get_count_order(columns);
Thanks.
--
Dmitry