mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: return the right length in ffs_epfile_io()
@ 2014-02-27  6:49 Chuansheng Liu
  2014-02-27 12:15 ` Michal Nazarewicz
  2014-03-03 16:30 ` Felipe Balbi
  0 siblings, 2 replies; 5+ messages in thread
From: Chuansheng Liu @ 2014-02-27  6:49 UTC (permalink / raw)
  To: balbi, gregkh, mina86
  Cc: linux-usb, linux-kernel, david.a.cohen, jin.can.zhuang,
	yu.y.wang, Chuansheng Liu

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 <chuansheng.liu@intel.com>
---
 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


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

* Re: [PATCH] usb: gadget: return the right length in ffs_epfile_io()
  2014-02-27  6:49 [PATCH] usb: gadget: return the right length in ffs_epfile_io() Chuansheng Liu
@ 2014-02-27 12:15 ` Michal Nazarewicz
  2014-02-27 23:45   ` David Cohen
  2014-03-03 16:30 ` Felipe Balbi
  1 sibling, 1 reply; 5+ messages in thread
From: Michal Nazarewicz @ 2014-02-27 12:15 UTC (permalink / raw)
  To: Chuansheng Liu, balbi, gregkh
  Cc: linux-usb, linux-kernel, david.a.cohen, jin.can.zhuang,
	yu.y.wang, Chuansheng Liu

[-- Attachment #1: Type: text/plain, Size: 1535 bytes --]

On Thu, Feb 27 2014, Chuansheng Liu <chuansheng.liu@intel.com> 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 <chuansheng.liu@intel.com>

Acked-by: Michal Nazarewicz <mina86@mina86.com>

> ---
>  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 +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--

[-- Attachment #2.1: Type: text/plain, Size: 0 bytes --]



[-- Attachment #2.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 835 bytes --]

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

* Re: [PATCH] usb: gadget: return the right length in ffs_epfile_io()
  2014-02-27 12:15 ` Michal Nazarewicz
@ 2014-02-27 23:45   ` David Cohen
  0 siblings, 0 replies; 5+ messages in thread
From: David Cohen @ 2014-02-27 23:45 UTC (permalink / raw)
  To: Michal Nazarewicz
  Cc: Chuansheng Liu, balbi, gregkh, linux-usb, linux-kernel,
	david.a.cohen, jin.can.zhuang, yu.y.wang

On Thu, Feb 27, 2014 at 01:15:25PM +0100, Michal Nazarewicz wrote:
> On Thu, Feb 27 2014, Chuansheng Liu <chuansheng.liu@intel.com> 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 <chuansheng.liu@intel.com>
> 
> Acked-by: Michal Nazarewicz <mina86@mina86.com>

Reviewed-by: David Cohen <david.a.cohen@linux.intel.com>

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

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

* Re: [PATCH] usb: gadget: return the right length in ffs_epfile_io()
  2014-02-27  6:49 [PATCH] usb: gadget: return the right length in ffs_epfile_io() Chuansheng Liu
  2014-02-27 12:15 ` Michal Nazarewicz
@ 2014-03-03 16:30 ` Felipe Balbi
  2014-03-04  7:47   ` Liu, Chuansheng
  1 sibling, 1 reply; 5+ messages in thread
From: Felipe Balbi @ 2014-03-03 16:30 UTC (permalink / raw)
  To: Chuansheng Liu
  Cc: balbi, gregkh, mina86, linux-usb, linux-kernel, david.a.cohen,
	jin.can.zhuang, yu.y.wang

[-- Attachment #1: Type: text/plain, Size: 1235 bytes --]

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 <chuansheng.liu@intel.com>
> ---
>  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

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* RE: [PATCH] usb: gadget: return the right length in ffs_epfile_io()
  2014-03-03 16:30 ` Felipe Balbi
@ 2014-03-04  7:47   ` Liu, Chuansheng
  0 siblings, 0 replies; 5+ messages in thread
From: Liu, Chuansheng @ 2014-03-04  7:47 UTC (permalink / raw)
  To: balbi
  Cc: gregkh, mina86, linux-usb, linux-kernel, Cohen, David A, Zhuang,
	Jin Can, Wang, Yu Y

Hello Balbi,

> -----Original Message-----
> From: Felipe Balbi [mailto:balbi@ti.com]
> Sent: Tuesday, March 04, 2014 12:30 AM
> To: Liu, Chuansheng
> Cc: balbi@ti.com; gregkh@linuxfoundation.org; mina86@mina86.com;
> linux-usb@vger.kernel.org; linux-kernel@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 <chuansheng.liu@intel.com>

> 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


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

end of thread, other threads:[~2014-03-04  7:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-27  6:49 [PATCH] usb: gadget: return the right length in ffs_epfile_io() Chuansheng Liu
2014-02-27 12:15 ` Michal Nazarewicz
2014-02-27 23:45   ` David Cohen
2014-03-03 16:30 ` Felipe Balbi
2014-03-04  7:47   ` Liu, Chuansheng

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

Powered by JetHome