Commit 25ed287b authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] mdc800 usercopy fix

From: Dipankar Sarma <dipankar@in.ibm.com>

Use copy_to_user/get_char with user buffers.
parent 1e320d10
...@@ -748,8 +748,12 @@ static ssize_t mdc800_device_read (struct file *file, char *buf, size_t len, lof ...@@ -748,8 +748,12 @@ static ssize_t mdc800_device_read (struct file *file, char *buf, size_t len, lof
} }
else else
{ {
/* memcpy Bytes */ /* Copy Bytes */
memcpy (ptr, &mdc800->out [mdc800->out_ptr], sts); if (copy_to_user(ptr, &mdc800->out [mdc800->out_ptr],
sts)) {
up(&mdc800->io_lock);
return -EFAULT;
}
ptr+=sts; ptr+=sts;
left-=sts; left-=sts;
mdc800->out_ptr+=sts; mdc800->out_ptr+=sts;
...@@ -786,14 +790,21 @@ static ssize_t mdc800_device_write (struct file *file, const char *buf, size_t l ...@@ -786,14 +790,21 @@ static ssize_t mdc800_device_write (struct file *file, const char *buf, size_t l
while (i<len) while (i<len)
{ {
unsigned char c;
if (signal_pending (current)) if (signal_pending (current))
{ {
up (&mdc800->io_lock); up (&mdc800->io_lock);
return -EINTR; return -EINTR;
} }
if(get_user(c, buf+i))
{
up(&mdc800->io_lock);
return -EFAULT;
}
/* check for command start */ /* check for command start */
if (buf [i] == (char) 0x55) if (c == 0x55)
{ {
mdc800->in_count=0; mdc800->in_count=0;
mdc800->out_count=0; mdc800->out_count=0;
...@@ -804,12 +815,11 @@ static ssize_t mdc800_device_write (struct file *file, const char *buf, size_t l ...@@ -804,12 +815,11 @@ static ssize_t mdc800_device_write (struct file *file, const char *buf, size_t l
/* save command byte */ /* save command byte */
if (mdc800->in_count < 8) if (mdc800->in_count < 8)
{ {
mdc800->in[mdc800->in_count]=buf[i]; mdc800->in[mdc800->in_count] = c;
mdc800->in_count++; mdc800->in_count++;
} }
else else
{ {
err ("Command is too long !\n");
up (&mdc800->io_lock); up (&mdc800->io_lock);
return -EIO; return -EIO;
} }
...@@ -884,8 +894,8 @@ static ssize_t mdc800_device_write (struct file *file, const char *buf, size_t l ...@@ -884,8 +894,8 @@ static ssize_t mdc800_device_write (struct file *file, const char *buf, size_t l
return -EIO; return -EIO;
} }
/* Write dummy data, (this is ugly but part of the USB Protokoll */ /* Write dummy data, (this is ugly but part of the USB Protocol */
/* if you use endpoint 1 as bulk and not as irq */ /* if you use endpoint 1 as bulk and not as irq) */
memcpy (mdc800->out, mdc800->camera_response,8); memcpy (mdc800->out, mdc800->camera_response,8);
/* This is the interpreted answer */ /* This is the interpreted answer */
......
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