* [PATCH] Input: evdev - limit amount of data for writes
@ 2024-08-15 18:41 Dmitry Torokhov
2024-08-16 0:18 ` Peter Hutterer
2024-08-18 5:47 ` Jeff LaBundy
0 siblings, 2 replies; 4+ messages in thread
From: Dmitry Torokhov @ 2024-08-15 18:41 UTC (permalink / raw)
To: linux-input
Cc: Jeff LaBundy, Benjamin Tissoires, linux-kernel, Hans de Goede,
Peter Hutterer
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.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
drivers/input/evdev.c | 7 +++++++
1 file changed, 7 insertions(+)
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;
--
2.46.0.184.g6999bdac58-goog
--
Dmitry
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] Input: evdev - limit amount of data for writes
2024-08-15 18:41 [PATCH] Input: evdev - limit amount of data for writes Dmitry Torokhov
@ 2024-08-16 0:18 ` Peter Hutterer
2024-08-16 6:17 ` Dmitry Torokhov
2024-08-18 5:47 ` Jeff LaBundy
1 sibling, 1 reply; 4+ messages in thread
From: Peter Hutterer @ 2024-08-16 0:18 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: linux-input, Jeff LaBundy, Benjamin Tissoires, linux-kernel,
Hans de Goede
On Thu, Aug 15, 2024 at 11:41:53AM -0700, Dmitry Torokhov wrote:
> 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.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
I'd expect anything coming near 170 input events is going to trigger
SYN_DROPPED anyway, so:
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
thanks.
Cheers,
Peter
> ---
> drivers/input/evdev.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> 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;
>
> --
> 2.46.0.184.g6999bdac58-goog
>
>
> --
> Dmitry
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Input: evdev - limit amount of data for writes
2024-08-16 0:18 ` Peter Hutterer
@ 2024-08-16 6:17 ` Dmitry Torokhov
0 siblings, 0 replies; 4+ messages in thread
From: Dmitry Torokhov @ 2024-08-16 6:17 UTC (permalink / raw)
To: Peter Hutterer
Cc: linux-input, Jeff LaBundy, Benjamin Tissoires, linux-kernel,
Hans de Goede
On Fri, Aug 16, 2024 at 10:18:05AM +1000, Peter Hutterer wrote:
> On Thu, Aug 15, 2024 at 11:41:53AM -0700, Dmitry Torokhov wrote:
> > 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.
> >
> > Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>
> 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.
>
> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Thanks for the review!
--
Dmitry
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Input: evdev - limit amount of data for writes
2024-08-15 18:41 [PATCH] Input: evdev - limit amount of data for writes Dmitry Torokhov
2024-08-16 0:18 ` Peter Hutterer
@ 2024-08-18 5:47 ` Jeff LaBundy
1 sibling, 0 replies; 4+ messages in thread
From: Jeff LaBundy @ 2024-08-18 5:47 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: linux-input, Benjamin Tissoires, linux-kernel, Hans de Goede,
Peter Hutterer
Hi Dmitry,
On Thu, Aug 15, 2024 at 11:41:53AM -0700, Dmitry Torokhov wrote:
> 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.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Reviewed-by: Jeff LaBundy <jeff@labundy.com>
> ---
> drivers/input/evdev.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> 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;
>
> --
> 2.46.0.184.g6999bdac58-goog
>
>
> --
> Dmitry
Kind regards,
Jeff LaBundy
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-08-18 5:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-15 18:41 [PATCH] Input: evdev - limit amount of data for writes Dmitry Torokhov
2024-08-16 0:18 ` Peter Hutterer
2024-08-16 6:17 ` Dmitry Torokhov
2024-08-18 5:47 ` Jeff LaBundy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).