linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: Greg KH <greg@kroah.com>
Cc: Peter Chen <peter.chen@nxp.com>,
	Felipe Balbi <felipe.balbi@linux.intel.com>,
	Roger Quadros <rogerq@ti.com>,
	Anton Vasilyev <vasilyev@ispras.ru>,
	Evgeny Novikov <novikov@ispras.ru>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	USB mailing list <linux-usb@vger.kernel.org>
Subject: Re: [PATCH RFC 1/4] USB: UDC: Don't wipe deallocated memory
Date: Thu, 30 Jul 2020 11:07:15 -0400	[thread overview]
Message-ID: <20200730150715.GA6332@rowland.harvard.edu> (raw)
In-Reply-To: <20200730051904.GA3859261@kroah.com>

On Thu, Jul 30, 2020 at 07:19:04AM +0200, Greg KH wrote:
> On Thu, Jul 30, 2020 at 03:28:09AM +0000, Peter Chen wrote:
> > On 20-07-29 16:22:31, Alan Stern wrote:
> > > Abusing the kernel's device model, some UDC drivers (including
> > > dwc3 and cdns3) register and unregister their gadget structures
> > > multiple times.  This is strictly forbidden; device structures may not
> > > be reused.
> > 
> > Register and unregister gadget structures multiple times should be
> > allowed if we pass a clean (zeroed) gadget device structure. I checked
> > the cdns3 code (cdns3_gadget_start), it always zeroed struct usb_gadget
> > before calling usb_add_gadget_udc when start device mode.
> 
> How do you "know" that the structure really was properly freed/released
> by the driver core at that point in time?
> 
> That's the issue, even if you do unregister it, the driver core, or any
> other part of the kernel, can hold on to the memory for an unbounded
> amount of time, due to the fact that this is a reference counted
> pointer.

In theory, you can know that the driver core is done using a structure 
if you wait for the release routine to run.  But of course, that can 
mean you have to wait an indefinitely long time.

Alan Stern

> So please, never "recycle" memory structures like this.  The
> documentation for the kernel explicitly says "do not do this!"
> 
> thanks,
> 
> greg k-h

      parent reply	other threads:[~2020-07-30 15:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-29 20:22 [PATCH RFC 1/4] USB: UDC: Don't wipe deallocated memory Alan Stern
2020-07-30  3:28 ` Peter Chen
2020-07-30  5:19   ` Greg KH
2020-07-30  7:31     ` Peter Chen
2020-07-30 15:07     ` Alan Stern [this message]

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=20200730150715.GA6332@rowland.harvard.edu \
    --to=stern@rowland.harvard.edu \
    --cc=benh@kernel.crashing.org \
    --cc=felipe.balbi@linux.intel.com \
    --cc=greg@kroah.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=novikov@ispras.ru \
    --cc=peter.chen@nxp.com \
    --cc=rogerq@ti.com \
    --cc=vasilyev@ispras.ru \
    /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;
as well as URLs for NNTP newsgroup(s).