public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Florian Fainelli <f.fainelli@gmail.com>,
	linux-kernel@vger.kernel.org, arnd@arndb.de,
	maksim.salau@gmail.com, David Mosberger <davidm@egauge.net>,
	Roger Quadros <rogerq@ti.com>,
	Wolfram Sang <wsa-dev@sang-engineering.com>,
	Oliver Neukum <oneukum@suse.com>,
	Jaejoong Kim <climbbb.kim@gmail.com>,
	"open list:USB SUBSYSTEM" <linux-usb@vger.kernel.org>
Subject: Re: [PATCH] usb: core: Warn if an URB's transfer_buffer is on stack
Date: Sun, 23 Apr 2017 08:35:18 +0200	[thread overview]
Message-ID: <20170423063518.GA9827@kroah.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1704221728230.31762-100000@netrider.rowland.org>

On Sat, Apr 22, 2017 at 05:31:27PM -0400, Alan Stern wrote:
> On Sat, 22 Apr 2017, Florian Fainelli wrote:
> 
> > We see a large number of fixes to several drivers to remove the usage of
> > on-stack buffers feeding into USB transfer functions. Make it easier to spot
> > the offenders by adding a warning in usb_start_wait_urb() for
> > urb->transfer_buffer to be located on the stack.
> > 
> > Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> > ---
> >  drivers/usb/core/message.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
> > index 2184ef40a82a..abefddbe9243 100644
> > --- a/drivers/usb/core/message.c
> > +++ b/drivers/usb/core/message.c
> > @@ -8,6 +8,7 @@
> >  #include <linux/pci.h>	/* for scatterlist macros */
> >  #include <linux/usb.h>
> >  #include <linux/module.h>
> > +#include <linux/sched/task_stack.h> /* for object_is_on_stack */
> >  #include <linux/slab.h>
> >  #include <linux/mm.h>
> >  #include <linux/timer.h>
> > @@ -50,6 +51,8 @@ static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length)
> >  	unsigned long expire;
> >  	int retval;
> >  
> > +	WARN_ON(object_is_on_stack(urb->transfer_buffer));
> > +
> >  	init_completion(&ctx.done);
> >  	urb->context = &ctx;
> >  	urb->actual_length = 0;
> 
> Does this really help?  I mean, don't we already get warnings when 
> the host controller drivers try to map on-stack buffers for DMA?
> 
> The only difference is that one wouldn't have to read as far back into
> the stack trace.  But that hardly seems like an important
> consideration.

I don't think this will show up if you don't have the VMALLOC_STACKS
option enabled (or whatever it is), so this warning is good to have.  I
didn't know we had that macro, as the USB stack has always required this
due to some platforms needing it, just not the "mainstream" ones...

I'll take this for the next kernel (after 4.12-rc1) and see what shakes
out in linux-next...

thanks,

greg k-h

  reply	other threads:[~2017-04-23  6:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-22 18:37 [PATCH] usb: core: Warn if an URB's transfer_buffer is on stack Florian Fainelli
2017-04-22 21:31 ` Alan Stern
2017-04-23  6:35   ` Greg Kroah-Hartman [this message]
2017-04-23 16:01     ` Alan Stern
2017-04-23 16:54       ` Florian Fainelli
2017-04-24  0:03         ` Alan Stern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170423063518.GA9827@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=arnd@arndb.de \
    --cc=climbbb.kim@gmail.com \
    --cc=davidm@egauge.net \
    --cc=f.fainelli@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=maksim.salau@gmail.com \
    --cc=oneukum@suse.com \
    --cc=rogerq@ti.com \
    --cc=stern@rowland.harvard.edu \
    --cc=wsa-dev@sang-engineering.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox