linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Peter Chen <peter.chen@nxp.com>
Cc: Alan Stern <stern@rowland.harvard.edu>,
	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 07:19:04 +0200	[thread overview]
Message-ID: <20200730051904.GA3859261@kroah.com> (raw)
In-Reply-To: <20200730032744.GC26224@b29397-desktop>

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.

So please, never "recycle" memory structures like this.  The
documentation for the kernel explicitly says "do not do this!"

thanks,

greg k-h

  reply	other threads:[~2020-07-30  5:19 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 [this message]
2020-07-30  7:31     ` Peter Chen
2020-07-30 15:07     ` 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=20200730051904.GA3859261@kroah.com \
    --to=greg@kroah.com \
    --cc=benh@kernel.crashing.org \
    --cc=felipe.balbi@linux.intel.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=novikov@ispras.ru \
    --cc=peter.chen@nxp.com \
    --cc=rogerq@ti.com \
    --cc=stern@rowland.harvard.edu \
    --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).