public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp>
Cc: stable@vger.kernel.org, sashal@kernel.org,
	Eddie Hung <eddie.hung@mediatek.com>,
	Macpaul Lin <macpaul.lin@mediatek.com>,
	Peter Chen <peter.chen@nxp.com>
Subject: Re: [RFC/PATCH for 4.4.y] usb: gadget: configfs: Fix use-after-free issue with udc_name
Date: Mon, 27 Dec 2021 14:10:54 +0100	[thread overview]
Message-ID: <Ycm7Xh2oBEGqSZPi@kroah.com> (raw)
In-Reply-To: <Ycm151MQzlAC0tC3@kroah.com>

On Mon, Dec 27, 2021 at 01:47:35PM +0100, Greg KH wrote:
> On Thu, Dec 23, 2021 at 02:26:26PM +0900, Nobuhiro Iwamatsu wrote:
> > From: Eddie Hung <eddie.hung@mediatek.com>
> > 
> > commit 64e6bbfff52db4bf6785fab9cffab850b2de6870 upstream.
> > 
> > There is a use-after-free issue, if access udc_name
> > in function gadget_dev_desc_UDC_store after another context
> > free udc_name in function unregister_gadget.
> > 
> > Context 1:
> > gadget_dev_desc_UDC_store()->unregister_gadget()->
> > free udc_name->set udc_name to NULL
> > 
> > Context 2:
> > gadget_dev_desc_UDC_show()-> access udc_name
> > 
> > Call trace:
> > dump_backtrace+0x0/0x340
> > show_stack+0x14/0x1c
> > dump_stack+0xe4/0x134
> > print_address_description+0x78/0x478
> > __kasan_report+0x270/0x2ec
> > kasan_report+0x10/0x18
> > __asan_report_load1_noabort+0x18/0x20
> > string+0xf4/0x138
> > vsnprintf+0x428/0x14d0
> > sprintf+0xe4/0x12c
> > gadget_dev_desc_UDC_show+0x54/0x64
> > configfs_read_file+0x210/0x3a0
> > __vfs_read+0xf0/0x49c
> > vfs_read+0x130/0x2b4
> > SyS_read+0x114/0x208
> > el0_svc_naked+0x34/0x38
> > 
> > Add mutex_lock to protect this kind of scenario.
> > 
> > Signed-off-by: Eddie Hung <eddie.hung@mediatek.com>
> > Signed-off-by: Macpaul Lin <macpaul.lin@mediatek.com>
> > Reviewed-by: Peter Chen <peter.chen@nxp.com>
> > Cc: stable@vger.kernel.org
> > Link: https://lore.kernel.org/r/1609239215-21819-1-git-send-email-macpaul.lin@mediatek.com
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > [Reference: CVE-2021-39648]
> > [iwamatsu: struct usb_gadget_driver does not have udc_name variable.
> >            Change struct gadget_info's udc_name.]
> > Signed-off-by: Nobuhiro Iwamatsu (CIP) <nobuhiro1.iwamatsu@toshiba.co.jp>
> > ---
> >  drivers/usb/gadget/configfs.c | 11 ++++++++++-
> >  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> Now queued up, thanks.
> 
> greg k-h

Oops, nope, this gives me a build warning, something is wrong with this
change:

  CC [M]  drivers/usb/gadget/configfs.o
drivers/usb/gadget/configfs.c: In function ‘gadget_dev_desc_UDC_show’:
drivers/usb/gadget/configfs.c:249:18: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  249 |         udc_name = gi->udc_name;
      |                  ^

Please always test-build your patches :(

thanks,

greg k-h

      reply	other threads:[~2021-12-27 13:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-23  5:26 [RFC/PATCH for 4.4.y] usb: gadget: configfs: Fix use-after-free issue with udc_name Nobuhiro Iwamatsu
2021-12-27 12:47 ` Greg KH
2021-12-27 13:10   ` Greg KH [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=Ycm7Xh2oBEGqSZPi@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=eddie.hung@mediatek.com \
    --cc=macpaul.lin@mediatek.com \
    --cc=nobuhiro1.iwamatsu@toshiba.co.jp \
    --cc=peter.chen@nxp.com \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    /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