]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
Input: evdev - limit amount of data for writes
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Thu, 15 Aug 2024 18:41:53 +0000 (11:41 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Sat, 24 Aug 2024 06:51:14 +0000 (23:51 -0700)
Limit amount of data that can be written into an evdev instance at
a given time to 4096 bytes (170 input events) to avoid holding
evdev->mutex for too long and starving other users.

Reviewed-by: Jeff LaBundy <jeff@labundy.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Link: https://lore.kernel.org/r/Zr5L8TUzkJcB9HcF@google.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/evdev.c

index a8ce3d140722331210a48701ca57bf36742f97fe..eb4906552ac8529fbb6768e9c1a29864b39d6d0e 100644 (file)
@@ -498,6 +498,13 @@ static ssize_t evdev_write(struct file *file, const char __user *buffer,
        struct input_event event;
        int retval = 0;
 
+       /*
+        * Limit amount of data we inject into the input subsystem so that
+        * we do not hold evdev->mutex for too long. 4096 bytes corresponds
+        * to 170 input events.
+        */
+       count = min(count, 4096);
+
        if (count != 0 && count < input_event_size())
                return -EINVAL;