lkml.org 
[lkml]   [2019]   [Aug]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Date
    SubjectRe: KASAN: use-after-free Read in device_release_driver_internal
    On Wed, Aug 7, 2019 at 3:44 PM Andrey Konovalov <andreyknvl@google.com> wrote:
    >
    > On Wed, Aug 7, 2019 at 3:44 PM Andrey Konovalov <andreyknvl@google.com> wrote:
    > >
    > > On Wed, Aug 7, 2019 at 3:38 PM Oliver Neukum <oneukum@suse.com> wrote:
    > > >
    > > > Am Dienstag, den 06.08.2019, 14:50 +0200 schrieb Andrey Konovalov:
    > > > > On Tue, Aug 6, 2019 at 2:36 PM Oliver Neukum <oneukum@suse.com> wrote:
    > > > > >
    > > > > > Am Donnerstag, den 01.08.2019, 14:47 -0400 schrieb Alan Stern:
    > > > > > >
    > > > > > > I think this must be caused by an unbalanced refcount. That is,
    > > > > > > something must drop one more reference to the device than it takes.
    > > > > > > That would explain why the invalid access occurs inside a single
    > > > > > > bus_remove_device() call, between the klist_del() and
    > > > > > > device_release_driver().
    > > > > > >
    > > > > > > The kernel log indicates that the device was probed by rndis_wlan,
    > > > > > > rndis_host, and cdc_acm, all of which got errors because of the
    > > > > > > device's bogus descriptors. Probably one of them is messing up the
    > > > > > > refcount.
    > > > > >
    > > > > > Hi,
    > > > > >
    > > > > > you made me look at cdc-acm. I suspect
    > > > > >
    > > > > > cae2bc768d176bfbdad7035bbcc3cdc973eb7984 ("usb: cdc-acm: Decrement tty port's refcount if probe() fail")
    > > > > >
    > > > > > is buggy decrementing the refcount on the interface in destroy()
    > > > > > even before the refcount is increased.
    > > > > >
    > > > > > Unfortunately I cannot tell from the bug report how many and which
    > > > > > interfaces the emulated test device has. Hence it is unclear to me,
    > > > > > when exactly probe() would fail cdc-acm.
    > > > > >
    > > > > > If you agree. I am attaching a putative fix.
    > > > >
    > > > > Let's see if it fixes the issue.
    > > > >
    > > > > #syz fix: https://github.com/google/kasan.git 6a3599ce
    > > >
    > > > Hi,
    > > >
    > > > did this ever produce a result? I saw none.
    > >
    > > Hm, that's weird, maybe that's caused by putting the bot into CC. Let
    > > me try that again.
    > >
    > > #syz fix: https://github.com/google/kasan.git 6a3599ce
    >
    > Oh, wait, it should be syz test =)
    >
    > #syz test: https://github.com/google/kasan.git 6a3599ce

    And now I forgot the patch :(

    #syz test: https://github.com/google/kasan.git 6a3599ce

    >
    > >
    > > >
    > > > Regards
    > > > Oliver
    > > >
    > > > --
    > > > You received this message because you are subscribed to the Google Groups "syzkaller-bugs" group.
    > > > To unsubscribe from this group and stop receiving emails from it, send an email to syzkaller-bugs+unsubscribe@googlegroups.com.
    > > > To view this discussion on the web visit https://groups.google.com/d/msgid/syzkaller-bugs/1565185131.15973.1.camel%40suse.com.
    From 6b31904e6cf75f89441e308b9e428a1de7728fd8 Mon Sep 17 00:00:00 2001
    From: Oliver Neukum <oneukum@suse.com>
    Date: Tue, 6 Aug 2019 14:34:27 +0200
    Subject: [PATCH] usb: cdc-acm: make sure a refcount is taken early enough

    destroy() will decrement the refcount on the interface, so that
    it needs to be taken so early that it never undercounts.

    Signed-off-by: Oliver Neukum <oneukum@suse.com>
    ---
    drivers/usb/class/cdc-acm.c | 12 +++++++-----
    1 file changed, 7 insertions(+), 5 deletions(-)

    diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
    index 183b41753c98..28e3de775ada 100644
    --- a/drivers/usb/class/cdc-acm.c
    +++ b/drivers/usb/class/cdc-acm.c
    @@ -1301,10 +1301,6 @@ static int acm_probe(struct usb_interface *intf,
    tty_port_init(&acm->port);
    acm->port.ops = &acm_port_ops;

    - minor = acm_alloc_minor(acm);
    - if (minor < 0)
    - goto alloc_fail1;
    -
    ctrlsize = usb_endpoint_maxp(epctrl);
    readsize = usb_endpoint_maxp(epread) *
    (quirks == SINGLE_RX_URB ? 1 : 2);
    @@ -1312,6 +1308,13 @@ static int acm_probe(struct usb_interface *intf,
    acm->writesize = usb_endpoint_maxp(epwrite) * 20;
    acm->control = control_interface;
    acm->data = data_interface;
    +
    + usb_get_intf(acm->control); /* undone in destroy() */
    +
    + minor = acm_alloc_minor(acm);
    + if (minor < 0)
    + goto alloc_fail1;
    +
    acm->minor = minor;
    acm->dev = usb_dev;
    if (h.usb_cdc_acm_descriptor)
    @@ -1458,7 +1461,6 @@ static int acm_probe(struct usb_interface *intf,
    usb_driver_claim_interface(&acm_driver, data_interface, acm);
    usb_set_intfdata(data_interface, acm);

    - usb_get_intf(control_interface);
    tty_dev = tty_port_register_device(&acm->port, acm_tty_driver, minor,
    &control_interface->dev);
    if (IS_ERR(tty_dev)) {
    --
    2.16.4
    \
     
     \ /
      Last update: 2019-08-07 15:47    [W:2.673 / U:0.004 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site