* [1/2] USB: yurex: Fix buffer over-read in yurex_write()
@ 2018-08-16 8:19 Ben Hutchings
0 siblings, 0 replies; 3+ messages in thread
From: Ben Hutchings @ 2018-08-16 8:19 UTC (permalink / raw)
To: Jann Horn; +Cc: Greg Kroah-Hartman, linux-usb
On Thu, 2018-08-16 at 04:15 +0200, Jann Horn wrote:
> On Wed, Aug 15, 2018 at 10:44 PM Ben Hutchings
> <ben.hutchings@codethink.co.uk> wrote:
[...]
> > @@ -446,6 +446,7 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
> > retval = -EFAULT;
> > goto error;
> > }
> > + buffer[count] = 0;
> > memset(dev->cntl_buffer, CMD_PADDING, YUREX_BUF_SIZE);
> >
> > switch (buffer[0]) {
>
> By the way: A little bit below here, there's some other line that looks bogus:
>
> > buffer[6] = CMD_EOF;
>
> AFAICS that should probably go into ->cntl_buffer; `buffer` and `data`
> aren't used below that point. But that'd just be a functional bug, not
> security-relevant, so I'm not sure whether anyone cares.
Yes I noticed that too. Since I can't test with the actual hardware, I
left it alone. For all I know, the firmware actually expects
CMD_PADDING and not CMD_EOF at the end of this command.
Ben.
^ permalink raw reply [flat|nested] 3+ messages in thread* [1/2] USB: yurex: Fix buffer over-read in yurex_write()
@ 2018-08-16 2:15 Jann Horn
0 siblings, 0 replies; 3+ messages in thread
From: Jann Horn @ 2018-08-16 2:15 UTC (permalink / raw)
To: ben.hutchings; +Cc: Greg Kroah-Hartman, linux-usb
On Wed, Aug 15, 2018 at 10:44 PM Ben Hutchings
<ben.hutchings@codethink.co.uk> wrote:
>
> 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.
Oh, good catch.
> (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: Ben Hutchings <ben.hutchings@codethink.co.uk>
> ---
> drivers/usb/misc/yurex.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/misc/yurex.c b/drivers/usb/misc/yurex.c
> index 3be40eaa1ac9..1232dd49556d 100644
> --- a/drivers/usb/misc/yurex.c
> +++ b/drivers/usb/misc/yurex.c
> @@ -421,13 +421,13 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
> {
> struct usb_yurex *dev;
> int i, set = 0, retval = 0;
> - char buffer[16];
> + char buffer[16 + 1];
> char *data = buffer;
> unsigned long long c, c2 = 0;
> signed long timeout = 0;
> DEFINE_WAIT(wait);
>
> - count = min(sizeof(buffer), count);
> + count = min(sizeof(buffer) - 1, count);
> dev = file->private_data;
>
> /* verify that we actually have some data to write */
> @@ -446,6 +446,7 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
> retval = -EFAULT;
> goto error;
> }
> + buffer[count] = 0;
> memset(dev->cntl_buffer, CMD_PADDING, YUREX_BUF_SIZE);
>
> switch (buffer[0]) {
By the way: A little bit below here, there's some other line that looks bogus:
> buffer[6] = CMD_EOF;
AFAICS that should probably go into ->cntl_buffer; `buffer` and `data`
aren't used below that point. But that'd just be a functional bug, not
security-relevant, so I'm not sure whether anyone cares.
^ permalink raw reply [flat|nested] 3+ messages in thread* [1/2] USB: yurex: Fix buffer over-read in yurex_write()
@ 2018-08-15 20:44 Ben Hutchings
0 siblings, 0 replies; 3+ messages in thread
From: Ben Hutchings @ 2018-08-15 20:44 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb, Jann Horn
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: Ben Hutchings <ben.hutchings@codethink.co.uk>
---
drivers/usb/misc/yurex.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/misc/yurex.c b/drivers/usb/misc/yurex.c
index 3be40eaa1ac9..1232dd49556d 100644
--- a/drivers/usb/misc/yurex.c
+++ b/drivers/usb/misc/yurex.c
@@ -421,13 +421,13 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
{
struct usb_yurex *dev;
int i, set = 0, retval = 0;
- char buffer[16];
+ char buffer[16 + 1];
char *data = buffer;
unsigned long long c, c2 = 0;
signed long timeout = 0;
DEFINE_WAIT(wait);
- count = min(sizeof(buffer), count);
+ count = min(sizeof(buffer) - 1, count);
dev = file->private_data;
/* verify that we actually have some data to write */
@@ -446,6 +446,7 @@ static ssize_t yurex_write(struct file *file, const char __user *user_buffer,
retval = -EFAULT;
goto error;
}
+ buffer[count] = 0;
memset(dev->cntl_buffer, CMD_PADDING, YUREX_BUF_SIZE);
switch (buffer[0]) {
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-08-16 8:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-16 8:19 [1/2] USB: yurex: Fix buffer over-read in yurex_write() Ben Hutchings
-- strict thread matches above, loose matches on Subject: below --
2018-08-16 2:15 Jann Horn
2018-08-15 20:44 Ben Hutchings
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).