]>
Commit | Line | Data |
---|---|---|
69a513a2 GKH |
1 | From 7e10f14ebface44a48275c8d6dc1caae3668d5a9 Mon Sep 17 00:00:00 2001 |
2 | From: Ben Hutchings <ben.hutchings@codethink.co.uk> | |
3 | Date: Wed, 15 Aug 2018 21:44:25 +0100 | |
4 | Subject: USB: yurex: Fix buffer over-read in yurex_write() | |
5 | ||
6 | From: Ben Hutchings <ben.hutchings@codethink.co.uk> | |
7 | ||
8 | commit 7e10f14ebface44a48275c8d6dc1caae3668d5a9 upstream. | |
9 | ||
10 | If the written data starts with a digit, yurex_write() tries to parse | |
11 | it as an integer using simple_strtoull(). This requires a null- | |
12 | terminator, and currently there's no guarantee that there is one. | |
13 | ||
14 | (The sample program at | |
15 | https://github.com/NeoCat/YUREX-driver-for-Linux/blob/master/sample/yurex_clock.pl | |
16 | writes an integer without a null terminator. It seems like it must | |
17 | have worked by chance!) | |
18 | ||
19 | Always add a null byte after the written data. Enlarge the buffer | |
20 | to allow for this. | |
21 | ||
22 | Cc: stable@vger.kernel.org | |
23 | Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk> | |
24 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
25 | ||
26 | --- | |
27 | drivers/usb/misc/yurex.c | 5 +++-- | |
28 | 1 file changed, 3 insertions(+), 2 deletions(-) | |
29 | ||
30 | --- a/drivers/usb/misc/yurex.c | |
31 | +++ b/drivers/usb/misc/yurex.c | |
32 | @@ -431,13 +431,13 @@ static ssize_t yurex_write(struct file * | |
33 | { | |
34 | struct usb_yurex *dev; | |
35 | int i, set = 0, retval = 0; | |
36 | - char buffer[16]; | |
37 | + char buffer[16 + 1]; | |
38 | char *data = buffer; | |
39 | unsigned long long c, c2 = 0; | |
40 | signed long timeout = 0; | |
41 | DEFINE_WAIT(wait); | |
42 | ||
43 | - count = min(sizeof(buffer), count); | |
44 | + count = min(sizeof(buffer) - 1, count); | |
45 | dev = file->private_data; | |
46 | ||
47 | /* verify that we actually have some data to write */ | |
48 | @@ -456,6 +456,7 @@ static ssize_t yurex_write(struct file * | |
49 | retval = -EFAULT; | |
50 | goto error; | |
51 | } | |
52 | + buffer[count] = 0; | |
53 | memset(dev->cntl_buffer, CMD_PADDING, YUREX_BUF_SIZE); | |
54 | ||
55 | switch (buffer[0]) { |