Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1003829ybz; Wed, 29 Apr 2020 13:15:32 -0700 (PDT) X-Google-Smtp-Source: APiQypJwZ0VYBX6Fxf3XtTtcY9MCCMFJyrgmYpBUU2xtVTlK1csTVpedYcH+2a/ok6EHhQlCK50h X-Received: by 2002:a17:906:4a94:: with SMTP id x20mr4352823eju.306.1588191332420; Wed, 29 Apr 2020 13:15:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588191332; cv=none; d=google.com; s=arc-20160816; b=M8jQ4dGFeOtEo9nNaAVznO8D5TnrCXLVGLjq0BHz/anh75CrpLwGWHPsMcUP3zUAjV aJ83lu1JvwAWfRw/gdMcRPjnFEJsxB9bw8or/PeDoxE+C9eY+C4R2TITrPg2mpHQeapB xFBRR2BpcmqRWpA/bm4iqLsrSLUNADArBPHGg3bbi4XVNTk8lew9N3V2QokD6OCrWcUP Z7P8xKki+xKowKuwOIFgj815pgDa+b2VHuVqfEdZ9GvDYAmJFM+SPJwYQ1LwqmpIbprF LEUqGVfXknunzAa9UGkC+E28zuXJBcB+cLxaVkX8H7Ewsm+EZT0i9bJv2ylIQMUrmsjW 1xjA== 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=/keVv4rqqE2Q4EqqK9G3DC2c1jhg/HsLtdjF/pgLukg=; b=aGOqXNy5rR80461XHYbt/l42cFU7Vz0CruUFg5i8SHTVxCLkxuXfqQyz7RWzKnLokB F4WPC2AV6OWNxL6MMWieMX8A5KpUkRoTYd0wxTeaolm3vrwx4gZXk6Z9BaPIPoBZtP7R a75jLHUtp9jlSdM4i1P3Lje7rGoYOD0dsAseXPdWaXtYHgQMGwkT8GRg22oCqqwCwkrq OTb7bDPyHIhc1OVueb1PN1Dy4xO5o25l5g7bM2hDqHMAdcdDDBctIDJygVWR7JQ0oWUp RBMZfO9tEIT5kPwixpgnT1AoaUShoM28uDcsyruCZBG3XKTuaKbNSEe+WKaGcHwQbXqi i7LQ== 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 nh5si4370340ejb.352.2020.04.29.13.15.08; Wed, 29 Apr 2020 13:15:32 -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 S1726893AbgD2ULl (ORCPT + 99 others); Wed, 29 Apr 2020 16:11:41 -0400 Received: from netrider.rowland.org ([192.131.102.5]:44851 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726456AbgD2ULk (ORCPT ); Wed, 29 Apr 2020 16:11:40 -0400 Received: (qmail 25214 invoked by uid 500); 29 Apr 2020 16:11:39 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 29 Apr 2020 16:11:39 -0400 Date: Wed, 29 Apr 2020 16:11:39 -0400 (EDT) From: Alan Stern X-X-Sender: stern@netrider.rowland.org To: syzbot cc: andreyknvl@google.com, , , , , Subject: Re: WARNING in usbhid_raw_request/usb_submit_urb (3) In-Reply-To: <000000000000357dce05a4240f67@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 Sat, 25 Apr 2020, syzbot wrote: > Hello, > > syzbot has tested the proposed patch and the reproducer did not trigger crash: > > Reported-and-tested-by: syzbot+db339689b2101f6f6071@syzkaller.appspotmail.com This is a two-pronged issue. The first problem is that usbhid does something it shouldn't (it submits an URB while a device reset is in progress). The second problem is that the USB core reports a driver bug if a an URB is submitted for ep0 at the wrong time during a reset. The patch tested above fixes the second issue but not the first. This patch attempts to fix the first issue; it makes usbhid check for a pending reset before submitting its URBs. 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 @@ -87,6 +87,7 @@ static int hid_start_in(struct hid_devic if (test_bit(HID_IN_POLLING, &usbhid->iofl) && !test_bit(HID_DISCONNECTED, &usbhid->iofl) && !test_bit(HID_SUSPENDED, &usbhid->iofl) && + !test_bit(HID_RESET_PENDING, &usbhid->iofl) && !test_and_set_bit(HID_IN_RUNNING, &usbhid->iofl)) { rc = usb_submit_urb(usbhid->urbin, GFP_ATOMIC); if (rc != 0) { @@ -273,6 +274,7 @@ static void hid_irq_in(struct urb *urb) struct hid_device *hid = urb->context; struct usbhid_device *usbhid = hid->driver_data; int status; + unsigned long flags; switch (urb->status) { case 0: /* success */ @@ -319,7 +321,12 @@ static void hid_irq_in(struct urb *urb) urb->status); } - status = usb_submit_urb(urb, GFP_ATOMIC); + spin_lock_irqsave(&usbhid->lock, flags); + if (test_bit(HID_RESET_PENDING, &usbhid->iofl)) + status = -EPERM; + else + status = usb_submit_urb(urb, GFP_ATOMIC); + spin_unlock_irqrestore(&usbhid->lock, flags); if (status) { clear_bit(HID_IN_RUNNING, &usbhid->iofl); if (status != -EPERM) { @@ -339,6 +346,9 @@ static int hid_submit_out(struct hid_dev struct usbhid_device *usbhid = hid->driver_data; int r; + if (test_bit(HID_RESET_PENDING, &usbhid->iofl)) + return -EAGAIN; + report = usbhid->out[usbhid->outtail].report; raw_report = usbhid->out[usbhid->outtail].raw_report; @@ -370,6 +380,9 @@ static int hid_submit_ctrl(struct hid_de int len, r; struct usbhid_device *usbhid = hid->driver_data; + if (test_bit(HID_RESET_PENDING, &usbhid->iofl)) + return -EAGAIN; + report = usbhid->ctrl[usbhid->ctrltail].report; raw_report = usbhid->ctrl[usbhid->ctrltail].raw_report; dir = usbhid->ctrl[usbhid->ctrltail].dir;