Re: [PATCH] staging: nvec: kbd: bound keycode table lookups

From: Greg Kroah-Hartman

Date: Fri Nov 20 2026 - 02:22:45 EST


On Thu, Nov 12, 2026 at 01:01:34AM +0200, Mohamed Anis Ben Azza wrote:
> nvec_keys_notifier() indexes code_tabs[_size][code] using values taken
> directly from the embedded controller's event message without checking
> them against the tables:
>
> - _size is a 2-bit field (0..3) from the message header, but code_tabs[]
> only has entries for NVEC_2BYTES and NVEC_3BYTES. NVEC_VAR_SIZE is
> rejected, but the reserved encoding 3 is not, so code_tabs[3] reads a
> pointer past the end of the array and then dereferences it.
>
> - code is msg[1] & 0x7f (0..127), but code_tab_102us[] has only 126
> entries and extcode_tab_us102[] only 110, so scancodes at or above
> those sizes read past the end of the tables.
>
> Reject any size encoding without a table and any scancode beyond the
> end of the selected table, dropping the event as is already done for
> the power button.
>
> This only matters for an EC that sends malformed or out-of-spec
> events, so it is a robustness fix rather than a security issue.
>
> The issue was found and the fix drafted with the help of an AI coding
> assistant (Claude). It was compile-tested with
> ARCH=arm LLVM=1 tegra_defconfig + MFD_NVEC/KEYBOARD_NVEC at W=1 with no
> new warnings, and the lookup logic was exercised in a userspace harness
> under AddressSanitizer for all 4 size encodings x 256 scancodes: the old
> code reports a global-buffer-overflow, the new code none. It has not
> been tested on real Tegra/AC100 hardware.
>
> Fixes: 32890b983086 ("Staging: initial version of the nvec driver")
> Signed-off-by: Mohamed Anis Ben Azza <benazzaanis783@xxxxxxxxx>
> ---
> drivers/staging/nvec/nvec_kbd.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)

Please read:
https://lore.kernel.org/r/2026080354-skater-urgent-31b2@gregkh