From 96c70d46f040bed4d58153ef94f6ea3382b197c4 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 14 Apr 2026 11:30:36 +1000 Subject: [PATCH] Refuse devices with more than 256 slots We already had a limitation on synching a max of 256 slots, regardless what the device reports, this just extends the check to refuse any device with >256 slots. The kernel already limits to 99 slots for uinput devices so anything 256 and higher will be a malicious/buggy real device. We can't add a test to this because the kernel refuses uinput devices with more than 99 slots. Part-of: --- libevdev/libevdev.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libevdev/libevdev.c b/libevdev/libevdev.c index bf601fa..9e0fec8 100644 --- a/libevdev/libevdev.c +++ b/libevdev/libevdev.c @@ -21,6 +21,7 @@ #include "event-names.h" #define MAXEVENTS 64 +#define MAX_SLOTS 256 enum event_filter_status { EVENT_FILTER_NONE, /**< Event untouched by filters */ @@ -359,6 +360,11 @@ init_slots(struct libevdev *dev) free_slots(dev); dev->num_slots = abs_info->maximum + 1; + if (dev->num_slots > MAX_SLOTS) { + rc = -ENOMEM; + goto out; + } + dev->mt_slot_vals = calloc(dev->num_slots * ABS_MT_CNT, sizeof(int)); if (!dev->mt_slot_vals) { rc = -ENOMEM; @@ -665,7 +671,6 @@ static int sync_mt_state(struct libevdev *dev, struct slot_change_state changes_out[dev->num_slots]) { -#define MAX_SLOTS 256 int rc = 0; struct slot_change_state changes[MAX_SLOTS] = {0}; unsigned int nslots = min(MAX_SLOTS, dev->num_slots);