Skip to content

Commit 439581e

Browse files
jacmetdtor
authored andcommitted
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>
1 parent 5063511 commit 439581e

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎drivers/input/evdev.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ static ssize_t evdev_write(struct file *file, const char __user *buffer,
321321
struct input_event event;
322322
int retval;
323323

324+
if (count < input_event_size())
325+
return -EINVAL;
326+
324327
retval = mutex_lock_interruptible(&evdev->mutex);
325328
if (retval)
326329
return retval;
@@ -330,17 +333,16 @@ static ssize_t evdev_write(struct file *file, const char __user *buffer,
330333
goto out;
331334
}
332335

333-
while (retval < count) {
334-
336+
do {
335337
if (input_event_from_user(buffer + retval, &event)) {
336338
retval = -EFAULT;
337339
goto out;
338340
}
341+
retval += input_event_size();
339342

340343
input_inject_event(&evdev->handle,
341344
event.type, event.code, event.value);
342-
retval += input_event_size();
343-
}
345+
} while (retval + input_event_size() <= count);
344346

345347
out:
346348
mutex_unlock(&evdev->mutex);

0 commit comments

Comments
 (0)