public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: nardelli <jnardelli@infosciences.com>
To: Greg KH <greg@kroah.com>
Cc: Ian Abbott <abbotti@mev.co.uk>,
	linux-kernel@vger.kernel.org,
	linux-usb-devel@lists.sourceforge.net
Subject: Re: [PATCH] Memory leak in visor.c and ftdi_sio.c
Date: Mon, 07 Jun 2004 10:19:30 -0400	[thread overview]
Message-ID: <40C47972.8090703@infosciences.com> (raw)
In-Reply-To: <20040605001832.GA28502@kroah.com>

Greg KH wrote:
> On Fri, Jun 04, 2004 at 05:34:41PM +0100, Ian Abbott wrote:
> 
>>On 04/06/2004 15:59, nardelli wrote:
>>
>>A related problem with the current implementation is that is easy to 
>>run out of memory by running something similar to this:
>>
>> # cat /dev/zero > /dev/ttyUSB0
>>
>>That affects both the ftdi_sio and visor drivers.
> 
> 
> Care to try out the following (build test only) patch to the visor
> driver to see if it prevents this from happening?  I don't have a
> working visor right now to test it out myself :(
> 
> Oops, ignore the fact that we never free the structure on disconnect, I
> see that now...
> 
> thanks,
> 
> greg k-h
> 
> 
> ===== drivers/usb/serial/visor.c 1.114 vs edited =====
> --- 1.114/drivers/usb/serial/visor.c	Fri Jun  4 07:13:10 2004
> +++ edited/drivers/usb/serial/visor.c	Fri Jun  4 17:12:53 2004

...

Just curious - is there something special about 42?  Grepping wasn't
very useful, as numbers like this are scattered all over the place.

> +/* number of outstanding urbs to prevent userspace DoS from happening */
> +#define URB_UPPER_LIMIT	42

...

>  
>  static int visor_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count)
>  {
> +	struct visor_private *priv = usb_get_serial_port_data(port);
>  	struct usb_serial *serial = port->serial;
>  	struct urb *urb;
>  	unsigned char *buffer;
> +	unsigned long flags;
>  	int status;
>  
>  	dbg("%s - port %d", __FUNCTION__, port->number);
>  
> +	spin_lock_irqsave(&priv->lock, flags);
> +	if (priv->outstanding_urbs > URB_UPPER_LIMIT) {
> +		spin_unlock_irqrestore(&priv->lock, flags);
> +		dev_dbg(&port->dev, "write limit hit\n");
> +		return 0;
> +	}
> +	++priv->outstanding_urbs;
> +	spin_unlock_irqrestore(&priv->lock, flags);
> +
>  	buffer = kmalloc (count, GFP_ATOMIC);
>  	if (!buffer) {
>  		dev_err(&port->dev, "out of memory\n");
> @@ -520,7 +545,10 @@
>  		count = status;
>  		kfree (buffer);
>  	} else {
> -		bytes_out += count;
> +		spin_lock_irqsave(&priv->lock, flags);
> +		++priv->outstanding_urbs;
> +		priv->bytes_out += count;
> +		spin_unlock_irqrestore(&priv->lock, flags);
>  	}
>  
>  	/* we are done with this urb, so let the host driver


Removing the first of two priv->outstanding_urbs increments in
visor_write (I assume that was your intention) produced very nice
results ;-)

1) When being flooded, after the initial bunch of URBs were sent,
only 1 per second was sent, and it appeared that all of them were
being freed.
2) Even after the flood, the driver survived, and backups were
possible after the device was reconnected.


I'm fairly ignorant of most of the lower level usb infrastructure
(hcd, hub, ehci, etc), so I'm not sure what the root cause (ignoring
the patch above) of the completion handler not being called might be.
I would suspect overflow of some callback list, but that's just a
guess.  Do you have any ideas on what this might be, and could this
be a problem in other devices?


-- 
Joe Nardelli
jnardelli@infosciences.com

  parent reply	other threads:[~2004-06-07 14:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-04 14:59 [PATCH] Memory leak in visor.c and ftdi_sio.c nardelli
2004-06-04 16:34 ` Ian Abbott
2004-06-04 17:25   ` nardelli
2004-06-04 18:04   ` Pete Zaitcev
2004-06-04 23:16   ` [linux-usb-devel] " Peter Horton
2004-06-05  0:18   ` Greg KH
2004-06-07  9:58     ` Ian Abbott
2004-06-07 14:19     ` nardelli [this message]
2004-06-07 15:43       ` Richard B. Johnson
2004-06-07 15:56         ` nardelli
2004-06-04 18:12 ` Greg KH
2004-06-04 18:47   ` nardelli
2004-06-04 22:02     ` Greg KH

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=40C47972.8090703@infosciences.com \
    --to=jnardelli@infosciences.com \
    --cc=abbotti@mev.co.uk \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb-devel@lists.sourceforge.net \
    /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