From: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
To: Felipe Balbi <balbi@kernel.org>
Cc: Jim Lin <jilin@nvidia.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] usb: gadget: configfs: Fix KASAN use-after-free
Date: Mon, 22 Feb 2021 20:47:26 -0300 [thread overview]
Message-ID: <20210222234726.GA166848@mussarela> (raw)
In-Reply-To: <878tqakmiy.fsf@linux.intel.com>
On Tue, Jan 17, 2017 at 12:29:09PM +0200, Felipe Balbi wrote:
>
> Hi,
>
> Jim Lin <jilin@nvidia.com> writes:
> > When gadget is disconnected, running sequence is like this.
> > . composite_disconnect
> > . Call trace:
> > usb_string_copy+0xd0/0x128
> > gadget_config_name_configuration_store+0x4
> > gadget_config_name_attr_store+0x40/0x50
> > configfs_write_file+0x198/0x1f4
> > vfs_write+0x100/0x220
> > SyS_write+0x58/0xa8
> > . configfs_composite_unbind
> > . configfs_composite_bind
> >
> > In configfs_composite_bind, it has
> > "cn->strings.s = cn->configuration;"
> >
> > When usb_string_copy is invoked. it would
> > allocate memory, copy input string, release previous pointed memory space,
> > and use new allocated memory.
> >
> > When gadget is connected, host sends down request to get information.
> > Call trace:
> > usb_gadget_get_string+0xec/0x168
> > lookup_string+0x64/0x98
> > composite_setup+0xa34/0x1ee8
> >
> > If gadget is disconnected and connected quickly, in the failed case,
> > cn->configuration memory has been released by usb_string_copy kfree but
> > configfs_composite_bind hasn't been run in time to assign new allocated
> > "cn->configuration" pointer to "cn->strings.s".
> >
> > When "strlen(s->s) of usb_gadget_get_string is being executed, the dangling
> > memory is accessed, "BUG: KASAN: use-after-free" error occurs.
> >
> > Signed-off-by: Jim Lin <jilin@nvidia.com>
> > ---
> > Changes in v2:
> > Changes in v3:
> > Change commit description
>
> well, I need to be sure you tested this with Linus' tree. The reason I'm
> asking is because this could be a bug caused by Android changes. From
> your previous patch, the problem started with android_setup().
>
> Please test with v4.10-rc4 and any configfs-based gadget.
>
> --
> balbi
I tested this with dummy_hcd on top of a 5.8 kernel and I got lsusb to respond
with an error instead of the right manufacturer string, after overwriting such
a string after binding.
With the patch applied, after the string is overwritten, lsusb will show the
updated string.
Because of commit 81c7462883b0cc0a4eeef0687f80ad5b5baee5f6 ("USB: replace
hardcode maximum usb string length by definition"), the patch will need a
fixup. Should I send a v2 with my sign-off?
Thanks.
Cascardo.
next prev parent reply other threads:[~2021-02-22 23:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-17 9:59 [PATCH v3] usb: gadget: configfs: Fix KASAN use-after-free Jim Lin
2017-01-17 10:29 ` Felipe Balbi
2017-02-10 6:44 ` Macpaul Lin
2021-02-22 23:47 ` Thadeu Lima de Souza Cascardo [this message]
2021-03-11 6:42 ` [PATCH v4] " Macpaul Lin
2021-03-11 6:53 ` Macpaul Lin
2021-03-11 10:52 ` Thadeu Lima de Souza Cascardo
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=20210222234726.GA166848@mussarela \
--to=cascardo@canonical.com \
--cc=balbi@kernel.org \
--cc=jilin@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@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;
as well as URLs for NNTP newsgroup(s).