]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
Input: synaptics-rmi4 - bound the F3A keymap to the GPIO count
authorBryam Vargas <hexlabsecurity@proton.me>
Sun, 14 Jun 2026 05:36:11 +0000 (00:36 -0500)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Fri, 26 Jun 2026 00:46:20 +0000 (17:46 -0700)
rmi_f3a_initialize() takes the GPIO count from the device query register
(f3a->gpio_count = buf & RMI_F3A_GPIO_COUNT, range 0..127).
rmi_f3a_map_gpios() then allocates gpio_key_map with
min(gpio_count, TRACKSTICK_RANGE_END) == at most 6 entries, but
rmi_f3a_attention() iterates the full gpio_count and dereferences
gpio_key_map[i], and input->keycodemax is set to the full gpio_count
while input->keycode points at the 6-entry allocation.

A device that reports gpio_count > 6 therefore causes an out-of-bounds
read of gpio_key_map[] on every attention interrupt, and out-of-bounds
accesses through the input core's default keymap ioctls: EVIOCGKEYCODE
reads past the buffer (leaking adjacent slab memory to user space) and
EVIOCSKEYCODE writes a caller-controlled value past it, for any process
able to open the evdev node, since input_default_getkeycode() and
input_default_setkeycode() only bound the index against keycodemax.

Size the keymap for the full gpio_count. The mapping loop is unchanged:
it still assigns only the first min(gpio_count, TRACKSTICK_RANGE_END)
entries; the remaining slots stay KEY_RESERVED (devm_kcalloc zero-fills)
and are skipped when reporting.

Fixes: 9e4c596bfd00 ("Input: synaptics-rmi4 - add support for F3A")
Cc: stable@vger.kernel.org
Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
Link: https://patch.msgid.link/20260614-b4-disp-818d6bda-v1-1-cf39a3615085@proton.me
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/rmi4/rmi_f3a.c

index 0e8baed84dbb5a0e4dc2821ba0eefeecaf9057d2..a0777644eef07876132a6a94dbd8d9947e8b32a0 100644 (file)
@@ -132,7 +132,7 @@ static int rmi_f3a_map_gpios(struct rmi_function *fn, struct f3a_data *f3a,
        int button_count = min_t(u8, f3a->gpio_count, TRACKSTICK_RANGE_END);
 
        f3a->gpio_key_map = devm_kcalloc(&fn->dev,
-                                               button_count,
+                                               f3a->gpio_count,
                                                sizeof(f3a->gpio_key_map[0]),
                                                GFP_KERNEL);
        if (!f3a->gpio_key_map) {