Commit 4be36bcc authored by Ben Hutchings's avatar Ben Hutchings Committed by Greg Kroah-Hartman

USB: yurex: Fix buffer over-read in yurex_write()

commit 7e10f14e upstream.

If the written data starts with a digit, yurex_write() tries to parse
it as an integer using simple_strtoull().  This requires a null-
terminator, and currently there's no guarantee that there is one.

(The sample program at
https://github.com/NeoCat/YUREX-driver-for-Linux/blob/master/sample/yurex_clock.pl
writes an integer without a null terminator.  It seems like it must
have worked by chance!)

Always add a null byte after the written data.  Enlarge the buffer
to allow for this.

Cc: stable@vger.kernel.org
Signed-off-by: default avatarBen Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent b214cde7
...@@ -439,13 +439,13 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer, ...@@ -439,13 +439,13 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
{ {
struct usb_yurex *dev; struct usb_yurex *dev;
int i, set = 0, retval = 0; int i, set = 0, retval = 0;
char buffer[16]; char buffer[16 + 1];
char *data = buffer; char *data = buffer;
unsigned long long c, c2 = 0; unsigned long long c, c2 = 0;
signed long timeout = 0; signed long timeout = 0;
DEFINE_WAIT(wait); DEFINE_WAIT(wait);
count = min(sizeof(buffer), count); count = min(sizeof(buffer) - 1, count);
dev = file->private_data; dev = file->private_data;
/* verify that we actually have some data to write */ /* verify that we actually have some data to write */
...@@ -464,6 +464,7 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer, ...@@ -464,6 +464,7 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
retval = -EFAULT; retval = -EFAULT;
goto error; goto error;
} }
buffer[count] = 0;
memset(dev->cntl_buffer, CMD_PADDING, YUREX_BUF_SIZE); memset(dev->cntl_buffer, CMD_PADDING, YUREX_BUF_SIZE);
switch (buffer[0]) { switch (buffer[0]) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment