public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] staging: ft1000: add a range check in ft1000_ioctl()
@ 2013-05-03  7:17 Dan Carpenter
  2013-05-03  7:53 ` devendra.aaru
  2013-05-05 14:23 ` Dan Carpenter
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2013-05-03  7:17 UTC (permalink / raw)
  To: kernel-janitors

msglen comes from get_user() so we need to check that it's not too
large.

The first element of "pioctl_dpram" is a short which holds the size of
the data the user wants.  I have chosen a limit which lets us fill the
rest of the struct.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
msglen is also apparently network endian?  My guess is that we should
just delete this code instead of trying to fix it.

diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
index 3251d2e..e0056c9 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
@@ -703,6 +703,8 @@ static long ft1000_ioctl (struct file *file, unsigned int command,
 			break;
 		msglen = htons(msglen);
                 //DEBUG("FT1000:ft1000_ioctl:msg length = %x\n", msglen);
+		if (msglen > sizeof(*pioctl_dpram) - sizeof(short))
+			msglen = sizeof(*pioctl_dpram) - sizeof(short);
                 if(copy_to_user (&pioctl_dpram->pseudohdr, pdpram_blk->pbuffer, msglen))
 				{
 					DEBUG("FT1000:ft1000_ioctl: copy fault occurred\n");

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [patch] staging: ft1000: add a range check in ft1000_ioctl()
  2013-05-03  7:17 [patch] staging: ft1000: add a range check in ft1000_ioctl() Dan Carpenter
@ 2013-05-03  7:53 ` devendra.aaru
  2013-05-05 14:23 ` Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: devendra.aaru @ 2013-05-03  7:53 UTC (permalink / raw)
  To: kernel-janitors

On Fri, May 3, 2013 at 12:47 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> msglen comes from get_user() so we need to check that it's not too
> large.
>
> The first element of "pioctl_dpram" is a short which holds the size of
> the data the user wants.  I have chosen a limit which lets us fill the
> rest of the struct.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> msglen is also apparently network endian?  My guess is that we should
> just delete this code instead of trying to fix it.
>
> diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
> index 3251d2e..e0056c9 100644
> --- a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
> +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
> @@ -703,6 +703,8 @@ static long ft1000_ioctl (struct file *file, unsigned int command,
>                         break;
>                 msglen = htons(msglen);
>                  //DEBUG("FT1000:ft1000_ioctl:msg length = %x\n", msglen);
> +               if (msglen > sizeof(*pioctl_dpram) - sizeof(short))
> +                       msglen = sizeof(*pioctl_dpram) - sizeof(short);

doing this may be wrong too? because its in network endian format.
does deleting msglen = htons(msglen)
and adding your change makes sense?


>                  if(copy_to_user (&pioctl_dpram->pseudohdr, pdpram_blk->pbuffer, msglen))
>                                 {
>                                         DEBUG("FT1000:ft1000_ioctl: copy fault occurred\n");

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] staging: ft1000: add a range check in ft1000_ioctl()
  2013-05-03  7:17 [patch] staging: ft1000: add a range check in ft1000_ioctl() Dan Carpenter
  2013-05-03  7:53 ` devendra.aaru
@ 2013-05-05 14:23 ` Dan Carpenter
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2013-05-05 14:23 UTC (permalink / raw)
  To: kernel-janitors

On Fri, May 03, 2013 at 01:11:21PM +0530, devendra.aaru wrote:
> On Fri, May 3, 2013 at 12:47 PM, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> > msglen comes from get_user() so we need to check that it's not too
> > large.
> >
> > The first element of "pioctl_dpram" is a short which holds the size of
> > the data the user wants.  I have chosen a limit which lets us fill the
> > rest of the struct.
> >
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > msglen is also apparently network endian?  My guess is that we should
> > just delete this code instead of trying to fix it.
> >
> > diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
> > index 3251d2e..e0056c9 100644
> > --- a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
> > +++ b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
> > @@ -703,6 +703,8 @@ static long ft1000_ioctl (struct file *file, unsigned int command,
> >                         break;
> >                 msglen = htons(msglen);
> >                  //DEBUG("FT1000:ft1000_ioctl:msg length = %x\n", msglen);
> > +               if (msglen > sizeof(*pioctl_dpram) - sizeof(short))
> > +                       msglen = sizeof(*pioctl_dpram) - sizeof(short);
> 
> doing this may be wrong too? because its in network endian format.
> does deleting msglen = htons(msglen)
> and adding your change makes sense?

Yeah.  Probably my patch doesn't make sense by itself.

It's hard to say what the right thing is here without having a way
to test it or knowing what userspace does.

I do suspect that the right thing is to just delete this code.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-05-05 14:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-03  7:17 [patch] staging: ft1000: add a range check in ft1000_ioctl() Dan Carpenter
2013-05-03  7:53 ` devendra.aaru
2013-05-05 14:23 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox