summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2024-08-15 11:41:53 -0700
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2024-08-23 23:51:14 -0700
commit6994d8b84bfd71431bfccb5baf84a827086d48a5 (patch)
tree9b6c1763d2a1d15abbfb60836dd3e15117ec354a
parent6c65914a40d33e96ceedc757be0129139cdf7852 (diff)
Input: evdev - limit amount of data for writes
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>
-rw-r--r--drivers/input/evdev.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index a8ce3d140722..eb4906552ac8 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -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;