Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1984953ybz; Sat, 18 Apr 2020 12:43:42 -0700 (PDT) X-Google-Smtp-Source: APiQypIfAzasTolsUWpQa7L+naOd04aVBRAgDPQeSja6V/2O+W8x7L/sRsDHAJ1d2OOMftjIt2EP X-Received: by 2002:a50:f693:: with SMTP id d19mr8536098edn.57.1587239021927; Sat, 18 Apr 2020 12:43:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587239021; cv=none; d=google.com; s=arc-20160816; b=kdyvVD99nQiu7HHvpwd7265hptgxHqHZSvekeotQsofroepkFeeCeyQOufsHRORXj7 VAdVQJJqE6bCCpMKw48pUM+OUDN7GFcfty8iQXQ6UZrOwgWIBeVXI6RWQGJOEWv4gBPb vfg4MEYJ+vjR/qmi9S+HSNQpzXRUihTTPdZ8/pHChD4sGxaeANw9DRYcASPaJxIeOvqa d1D4Uci3aNObcS8CsWTkj4VI5EFyT8kkoxgi4glznbg6wZhY7oX05wglai1HYfMdphJx JuR8DZUmdw5KLJh/0Ghyit4mfhpIyri4Xd2HMklzbW2x3vdF5Dm5qh8J9FyVP9rwPV39 6asg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=1m/gLEs2w4R5wx6AAN4YWh9KqM17Y3sY+Xm+p0Q7J4I=; b=ggdbMGLu5W5iYSygR9DfMM2dWI/SXkIiyQUF/Gy0LKJiOPqvGFLZadq4eV92BksOhW +j9SowW3QiuyvXWb02IjGT4l3llgWfnV8AVT1oQLw2z0GXbVW89vzxeemHS11Rw08ub+ tKeZ41SM8B+JUfW0FM5nbCa55W8gGLC/SKbC/Ns63wsWbXVvob2qCi3sjyzGGkiLeSHw So+dXYodxfJ92zB3/B381LfwVoQy3VumNxzlGfBrBYqCEug2bJrYTgEwWAE8+dSjyMUF NHclu0i+pYAQPn2I4UXazk0ojJj0J4n/gxl29BHorv4veRIHqQorOPp+3sp78YH0rRG/ heyg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j24si10455017ejb.58.2020.04.18.12.43.19; Sat, 18 Apr 2020 12:43:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728083AbgDRTju (ORCPT + 99 others); Sat, 18 Apr 2020 15:39:50 -0400 Received: from netrider.rowland.org ([192.131.102.5]:50591 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1727927AbgDRTju (ORCPT ); Sat, 18 Apr 2020 15:39:50 -0400 Received: (qmail 8637 invoked by uid 500); 18 Apr 2020 15:39:48 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 18 Apr 2020 15:39:48 -0400 Date: Sat, 18 Apr 2020 15:39:48 -0400 (EDT) From: Alan Stern X-X-Sender: stern@netrider.rowland.org To: syzbot cc: andreyknvl@google.com, , , , , Subject: Re: KASAN: use-after-free Read in usbhid_close (3) In-Reply-To: <0000000000003ef93005a386c2f9@google.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 17 Apr 2020, syzbot wrote: > Hello, > > syzbot has tested the proposed patch but the reproducer still triggered crash: > KASAN: use-after-free Read in __input_unregister_device > > wacom 0003:056A:0061.0002: Unknown device_type for 'HID 056a:0061'. Assuming pen. > input: Wacom PenStation2 Pen as /devices/platform/dummy_hcd.1/usb2/2-1/2-1:0.0/0003:056A:0061.0002/input/input8 > wacom 0003:056A:0061.0002: hidraw1: USB HID v0.00 Device [HID 056a:0061] on usb-dummy_hcd.1-1/input0 > usb 6-1: USB disconnect, device number 2 > ================================================================== > BUG: KASAN: use-after-free in __input_unregister_device+0x4a6/0x4c0 drivers/input/input.c:2089 > Read of size 4 at addr ffff8881cc1380e8 by task kworker/0:1/12 Oops. Wrong kind of error and in the wrong place. So I need to be a little more careful about the debugging code. Let's try again. Alan Stern #syz test: https://github.com/google/kasan.git 0fa84af8 Index: usb-devel/drivers/hid/usbhid/hid-core.c =================================================================== --- usb-devel.orig/drivers/hid/usbhid/hid-core.c +++ usb-devel/drivers/hid/usbhid/hid-core.c @@ -747,6 +747,7 @@ static void usbhid_close(struct hid_devi return; hid_cancel_delayed_stuff(usbhid); + --hid->alan_open; usb_kill_urb(usbhid->urbin); usbhid->intf->needs_remote_wakeup = 0; } @@ -1177,6 +1178,7 @@ static int usbhid_start(struct hid_devic usbhid_set_leds(hid); device_set_wakeup_enable(&dev->dev, 1); } + ++hid->alan_open; return 0; fail: @@ -1197,6 +1199,11 @@ static void usbhid_stop(struct hid_devic if (WARN_ON(!usbhid)) return; + dev_info(&usbhid->intf->dev, "Stop: %d %d %d\n", + hid->alan1, hid->alan2, hid->alan3); + if (hid->alan_open > 0) + dev_WARN(&usbhid->intf->dev, "Stop while open = %d\n", + hid->alan_open); if (hid->quirks & HID_QUIRK_ALWAYS_POLL) { clear_bit(HID_IN_POLLING, &usbhid->iofl); usbhid->intf->needs_remote_wakeup = 0; Index: usb-devel/drivers/hid/hid-input.c =================================================================== --- usb-devel.orig/drivers/hid/hid-input.c +++ usb-devel/drivers/hid/hid-input.c @@ -1960,6 +1960,7 @@ void hidinput_disconnect(struct hid_devi { struct hid_input *hidinput, *next; + ++hid->alan1; hidinput_cleanup_battery(hid); list_for_each_entry_safe(hidinput, next, &hid->inputs, list) { Index: usb-devel/drivers/input/evdev.c =================================================================== --- usb-devel.orig/drivers/input/evdev.c +++ usb-devel/drivers/input/evdev.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "input-compat.h" struct evdev { @@ -1329,6 +1330,11 @@ static void evdev_mark_dead(struct evdev static void evdev_cleanup(struct evdev *evdev) { struct input_handle *handle = &evdev->handle; + struct hid_device *hid; + + hid = evdev->handle.dev->hid; + if (hid) + ++hid->alan3; evdev_mark_dead(evdev); evdev_hangup(evdev); Index: usb-devel/drivers/input/input.c =================================================================== --- usb-devel.orig/drivers/input/input.c +++ usb-devel/drivers/input/input.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "input-compat.h" #include "input-poller.h" @@ -2081,7 +2082,11 @@ static void input_cleanse_bitmasks(struc static void __input_unregister_device(struct input_dev *dev) { struct input_handle *handle, *next; + struct hid_device *hid; + hid = dev->hid; + if (hid) + ++hid->alan2; input_disconnect_device(dev); mutex_lock(&input_mutex); Index: usb-devel/include/linux/hid.h =================================================================== --- usb-devel.orig/include/linux/hid.h +++ usb-devel/include/linux/hid.h @@ -618,6 +618,9 @@ struct hid_device { /* device repo struct list_head debug_list; spinlock_t debug_list_lock; wait_queue_head_t debug_wait; + + int alan_open; + int alan1, alan2, alan3; }; #define to_hid_device(pdev) \ Index: usb-devel/include/linux/input.h =================================================================== --- usb-devel.orig/include/linux/input.h +++ usb-devel/include/linux/input.h @@ -22,6 +22,7 @@ #include struct input_dev_poller; +struct hid_device; /** * struct input_value - input value representation @@ -129,6 +130,7 @@ enum input_clock_type { * by a driver */ struct input_dev { + struct hid_device *hid; const char *name; const char *phys; const char *uniq; Index: usb-devel/drivers/hid/wacom_sys.c =================================================================== --- usb-devel.orig/drivers/hid/wacom_sys.c +++ usb-devel/drivers/hid/wacom_sys.c @@ -2017,6 +2017,7 @@ static struct input_dev *wacom_allocate_ if (!input_dev) return NULL; + input_dev->hid = hdev; input_dev->name = wacom_wac->features.name; input_dev->phys = hdev->phys; input_dev->dev.parent = &hdev->dev;