Skip to contentSkip to conversation

Input: evdev - limit amount of data for writes

PATCH In review Dmitry Torokhov 3 participants 4 messages Aug 15, 2024 – Aug 18, 2024

Subsystems (2)
lore
Share & tools
lore

Dmitry Torokhov

author maintainer
#0 lore raw

PATCH 1/1 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.

---
 drivers/input/evdev.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/input/evdev.c +7 -0
index a8ce3d140722..eb4906552ac8 100644
@@ -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;
 
Signature · 5 lines
2.46.0.184.g6999bdac58-goog


-- 
Dmitry
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Dmitry Torokhov

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.

I'd expect anything coming near 170 input events is going to trigger SYN_DROPPED anyway, so:

thanks.

Cheers,
Peter

Quoted 28 lines
---
 drivers/input/evdev.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/input/evdev.c +7 -0
index a8ce3d140722..eb4906552ac8 100644
@@ -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;
 
Signature · 5 lines
2.46.0.184.g6999bdac58-goog


-- 
Dmitry
author maintainer
#2 lore raw
Quoted 9 lines · Peter Hutterer
Quoted 5 lines · Dmitry Torokhov

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.

I'd expect anything coming near 170 input events is going to trigger SYN_DROPPED anyway, so:

This actually going the other direction (userspace -> kernel) so there will be no SYN_DROPPED, at least on the way in.

Quoted 2 lines

Thanks for the review!

Signature · 1 line
Dmitry
Reviewed-by on v1 1/1
#3 lore raw
In reply to Dmitry Torokhov

Hi Dmitry,

Quoted 5 lines · Dmitry Torokhov

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.

Quoted 28 lines
---
 drivers/input/evdev.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/input/evdev.c +7 -0
index a8ce3d140722..eb4906552ac8 100644
@@ -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;
 
Signature · 5 lines
2.46.0.184.g6999bdac58-goog


-- 
Dmitry

Kind regards,
Jeff LaBundy