[PATCH] usb: gadget: return the right length in ffs_epfile_io()
When the request length is aligned to maxpacketsize, sometimes the return length ret > the user space requested len. At that time, we will use min_t(size_t, ret, len) to limit the size in case of user data buffer overflow. But we need return the min_t(size_t, ret, len) to tell the user space rightly also. Signed-off-by: Chuansheng Liu --- drivers/usb/gadget/f_fs.c | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c index 2b43343..31ee7af 100644 --- a/drivers/usb/gadget/f_fs.c +++ b/drivers/usb/gadget/f_fs.c @@ -687,10 +687,12 @@ static ssize_t ffs_epfile_io(struct file *file, * space for. */ ret = ep->status; - if (read && ret > 0 && - unlikely(copy_to_user(buf, data, - min_t(size_t, ret, len - ret = -EFAULT; + if (read && ret > 0) { + ret = min_t(size_t, ret, len); + + if (unlikely(copy_to_user(buf, data, ret))) + ret = -EFAULT; + } } } -- 1.9.rc0 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] usb: gadget: return the right length in ffs_epfile_io()
On Thu, Feb 27 2014, Chuansheng Liu wrote: > When the request length is aligned to maxpacketsize, sometimes > the return length ret > the user space requested len. > > At that time, we will use min_t(size_t, ret, len) to limit the > size in case of user data buffer overflow. > > But we need return the min_t(size_t, ret, len) to tell the user > space rightly also. > > Signed-off-by: Chuansheng Liu Acked-by: Michal Nazarewicz > --- > drivers/usb/gadget/f_fs.c | 10 ++ > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c > index 2b43343..31ee7af 100644 > --- a/drivers/usb/gadget/f_fs.c > +++ b/drivers/usb/gadget/f_fs.c > @@ -687,10 +687,12 @@ static ssize_t ffs_epfile_io(struct file *file, >* space for. >*/ > ret = ep->status; > - if (read && ret > 0 && > - unlikely(copy_to_user(buf, data, > - min_t(size_t, ret, len > - ret = -EFAULT; > + if (read && ret > 0) { > + ret = min_t(size_t, ret, len); > + > + if (unlikely(copy_to_user(buf, data, ret))) > + ret = -EFAULT; > + } > } > } > > -- > 1.9.rc0 > -- Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz(o o) ooo +--ooO--(_)--Ooo-- signature.asc Description: PGP signature
Re: [PATCH] usb: gadget: return the right length in ffs_epfile_io()
On Thu, Feb 27, 2014 at 01:15:25PM +0100, Michal Nazarewicz wrote: > On Thu, Feb 27 2014, Chuansheng Liu wrote: > > When the request length is aligned to maxpacketsize, sometimes > > the return length ret > the user space requested len. > > > > At that time, we will use min_t(size_t, ret, len) to limit the > > size in case of user data buffer overflow. > > > > But we need return the min_t(size_t, ret, len) to tell the user > > space rightly also. > > > > Signed-off-by: Chuansheng Liu > > Acked-by: Michal Nazarewicz Reviewed-by: David Cohen IMHO it makes sense to push this patch to 3.14-rc since it is an extension of usb gadget's quick_ep_out_aligned_size merged on 3.14-rc1 Br, David Cohen -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH] usb: gadget: return the right length in ffs_epfile_io()
Hi, On Thu, Feb 27, 2014 at 02:49:31PM +0800, Chuansheng Liu wrote: > When the request length is aligned to maxpacketsize, sometimes > the return length ret > the user space requested len. > > At that time, we will use min_t(size_t, ret, len) to limit the > size in case of user data buffer overflow. > > But we need return the min_t(size_t, ret, len) to tell the user > space rightly also. > > Signed-off-by: Chuansheng Liu > --- > drivers/usb/gadget/f_fs.c | 10 ++ > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c > index 2b43343..31ee7af 100644 > --- a/drivers/usb/gadget/f_fs.c > +++ b/drivers/usb/gadget/f_fs.c > @@ -687,10 +687,12 @@ static ssize_t ffs_epfile_io(struct file *file, >* space for. >*/ > ret = ep->status; > - if (read && ret > 0 && > - unlikely(copy_to_user(buf, data, > - min_t(size_t, ret, len > - ret = -EFAULT; > + if (read && ret > 0) { > + ret = min_t(size_t, ret, len); > + > + if (unlikely(copy_to_user(buf, data, ret))) > + ret = -EFAULT; > + } please rebase on my "testing/next" branch -- balbi signature.asc Description: Digital signature
RE: [PATCH] usb: gadget: return the right length in ffs_epfile_io()
Hello Balbi, > -Original Message- > From: Felipe Balbi [mailto:ba...@ti.com] > Sent: Tuesday, March 04, 2014 12:30 AM > To: Liu, Chuansheng > Cc: ba...@ti.com; gre...@linuxfoundation.org; min...@mina86.com; > linux-usb@vger.kernel.org; linux-ker...@vger.kernel.org; Cohen, David A; > Zhuang, Jin Can; Wang, Yu Y > Subject: Re: [PATCH] usb: gadget: return the right length in ffs_epfile_io() > > Hi, > > On Thu, Feb 27, 2014 at 02:49:31PM +0800, Chuansheng Liu wrote: > > When the request length is aligned to maxpacketsize, sometimes > > the return length ret > the user space requested len. > > > > At that time, we will use min_t(size_t, ret, len) to limit the > > size in case of user data buffer overflow. > > > > But we need return the min_t(size_t, ret, len) to tell the user > > space rightly also. > > > > Signed-off-by: Chuansheng Liu > please rebase on my "testing/next" branch Based on your branch "testing/next", I have sent patch v2 with some ack and reviewing, thanks. [PATCH v2] usb: gadget: return the right length in ffs_epfile_io() Best Regards Chuansheng -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html