diff options
author | Peter Korsgaard <jacmet@sunsite.dk> | 2011-02-25 12:30:46 -0500 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2011-02-27 04:52:53 -0500 |
commit | 439581ec07fa9cf3f519dd461a2cf41cfd3adcb4 (patch) | |
tree | 204e640e88005bfcda1176d28ecc9325fbf57ad3 /drivers/input/evdev.c | |
parent | 5063511539bbb436ae8e4f75409561ef547f8516 (diff) |
Input: evdev - fix evdev_write return value on partial writes
As was recently brought up on the busybox list
(http://lists.busybox.net/pipermail/busybox/2011-January/074565.html),
evdev_write doesn't properly check the count argument, which will
lead to a return value > count on partial writes if the remaining bytes
are accessible - causing userspace confusion.
Fix it by only handling each full input_event structure and return -EINVAL
if less than 1 struct was written, similar to how it is done in evdev_read.
Reported-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Peter Korsgaard <jacmet@sunsite.dk>
Acked-by: Henrik Rydberg <rydberg@euromail.se>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers/input/evdev.c')
-rw-r--r-- | drivers/input/evdev.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c index c8471a2552e7..7f42d3a454d2 100644 --- a/drivers/input/evdev.c +++ b/drivers/input/evdev.c | |||
@@ -321,6 +321,9 @@ static ssize_t evdev_write(struct file *file, const char __user *buffer, | |||
321 | struct input_event event; | 321 | struct input_event event; |
322 | int retval; | 322 | int retval; |
323 | 323 | ||
324 | if (count < input_event_size()) | ||
325 | return -EINVAL; | ||
326 | |||
324 | retval = mutex_lock_interruptible(&evdev->mutex); | 327 | retval = mutex_lock_interruptible(&evdev->mutex); |
325 | if (retval) | 328 | if (retval) |
326 | return retval; | 329 | return retval; |
@@ -330,17 +333,16 @@ static ssize_t evdev_write(struct file *file, const char __user *buffer, | |||
330 | goto out; | 333 | goto out; |
331 | } | 334 | } |
332 | 335 | ||
333 | while (retval < count) { | 336 | do { |
334 | |||
335 | if (input_event_from_user(buffer + retval, &event)) { | 337 | if (input_event_from_user(buffer + retval, &event)) { |
336 | retval = -EFAULT; | 338 | retval = -EFAULT; |
337 | goto out; | 339 | goto out; |
338 | } | 340 | } |
341 | retval += input_event_size(); | ||
339 | 342 | ||
340 | input_inject_event(&evdev->handle, | 343 | input_inject_event(&evdev->handle, |
341 | event.type, event.code, event.value); | 344 | event.type, event.code, event.value); |
342 | retval += input_event_size(); | 345 | } while (retval + input_event_size() <= count); |
343 | } | ||
344 | 346 | ||
345 | out: | 347 | out: |
346 | mutex_unlock(&evdev->mutex); | 348 | mutex_unlock(&evdev->mutex); |