Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp127831ybm; Tue, 26 May 2020 12:27:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1Z9fFmDgeYhtg3THpcH02QrB/6eJEPbhSqjpvsk85uR3N6E+opYkEIni8ytOtsg7vvWa2 X-Received: by 2002:a17:906:9719:: with SMTP id k25mr2536352ejx.411.1590521277547; Tue, 26 May 2020 12:27:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590521277; cv=none; d=google.com; s=arc-20160816; b=EOtzPthhPoMwBq6v63kal+JazWINGYRsdeDPj/0gJ1Co0XH2IsDMrDxgisNgtXPx3S 2ZRQv5qmUU9iwO5wCQBwN5pIj6yOnUGIHPjNsb0QSS6DF3TnW59QrbgSQlCU7DiluLGv HTudbQJYAtDuunPgtEnxxVslxU9n6t0vDCIc09LoB/hTzeVUuKGu/4/+vUKRZJArI0D9 kUtfKtziQRwtQCkvzVD7DFCfJtdRyluR+r7+zY1TMYhrNzS30dn42rskOnZqPs+RxXR7 kGi35czZlgjKoz/lu7HQkePo9Vdv2+7mJ1s6MIW565k7lu58sNPFqAjS40cqCQmzIKyx 6e4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=OyymmPT+RIFlJPLiPgbSCXdD8FOR6il/l6TqP04PAkU=; b=y0uvX3HYuJX2M/5o80lh1TT7HgLFzPVOVpBHzgKVdIC/gJJlng7ADnFha1yvu3fiKk gE5xGcHvBJgGP17HfS6MmxH/7/S26F09BW9SMnmneWKaCrerQDqvNTER/UgZ/dxptXrh r8ML3tw5QP0TKWmkRUtdRsh8VpKCJx5Uuun8nShx5NrLSeqGAOUJhYNrYc9cSHsvUZda rjqzQQkPs7L92POwXip2aU9LlN+CEh1s71UmvGsw+02+5xwOot/xj4wvAaovw3likPDh Uzly3tz6v6ikryU7FILTjNnNkTr6E9wP+OCc/78Vsr7x8AafKOTgLDfONPBQNhi3oD93 +CfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GewzSnvm; 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 dn20si609809ejc.319.2020.05.26.12.27.33; Tue, 26 May 2020 12:27:57 -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; dkim=pass header.i=@kernel.org header.s=default header.b=GewzSnvm; 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 S2392471AbgEZTYg (ORCPT + 99 others); Tue, 26 May 2020 15:24:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:36288 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391289AbgEZTHe (ORCPT ); Tue, 26 May 2020 15:07:34 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0E36820873; Tue, 26 May 2020 19:07:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590520053; bh=L9dEFwmMPW+AV5IScBr/9bkG1sG4655gjTPtCJQfpNQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GewzSnvm4cWRP71bYyVWcDUhco1aFKoVtA4sHwX1yGL9Mkc+nzUyl4p51IbNL11MM upCKfEL7N3+zWg3TDHtWOjlsRAzd7gyCkOxy4IyKOsfadA9m2C45d3txAPlcECkbS5 YgC76gqtxs/J50bOq6FVVeKvRmoyk3aKkzo4kwc4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alan Stern , Sasha Levin , syzbot+db339689b2101f6f6071@syzkaller.appspotmail.com Subject: [PATCH 5.4 041/111] USB: core: Fix misleading driver bug report Date: Tue, 26 May 2020 20:52:59 +0200 Message-Id: <20200526183936.834497087@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200526183932.245016380@linuxfoundation.org> References: <20200526183932.245016380@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alan Stern [ Upstream commit ac854131d9844f79e2fdcef67a7707227538d78a ] The syzbot fuzzer found a race between URB submission to endpoint 0 and device reset. Namely, during the reset we call usb_ep0_reinit() because the characteristics of ep0 may have changed (if the reset follows a firmware update, for example). While usb_ep0_reinit() is running there is a brief period during which the pointers stored in udev->ep_in[0] and udev->ep_out[0] are set to NULL, and if an URB is submitted to ep0 during that period, usb_urb_ep_type_check() will report it as a driver bug. In the absence of those pointers, the routine thinks that the endpoint doesn't exist. The log message looks like this: ------------[ cut here ]------------ usb 2-1: BOGUS urb xfer, pipe 2 != type 2 WARNING: CPU: 0 PID: 9241 at drivers/usb/core/urb.c:478 usb_submit_urb+0x1188/0x1460 drivers/usb/core/urb.c:478 Now, although submitting an URB while the device is being reset is a questionable thing to do, it shouldn't count as a driver bug as severe as submitting an URB for an endpoint that doesn't exist. Indeed, endpoint 0 always exists, even while the device is in its unconfigured state. To prevent these misleading driver bug reports, this patch updates usb_disable_endpoint() to avoid clearing the ep_in[] and ep_out[] pointers when the endpoint being disabled is ep0. There's no danger of leaving a stale pointer in place, because the usb_host_endpoint structure being pointed to is stored permanently in udev->ep0; it doesn't get deallocated until the entire usb_device structure does. Reported-and-tested-by: syzbot+db339689b2101f6f6071@syzkaller.appspotmail.com Signed-off-by: Alan Stern Link: https://lore.kernel.org/r/Pine.LNX.4.44L0.2005011558590.903-100000@netrider.rowland.org Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/core/message.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c index 02eaac7e1e34..a1ac2f0723b0 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c @@ -1143,11 +1143,11 @@ void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr, if (usb_endpoint_out(epaddr)) { ep = dev->ep_out[epnum]; - if (reset_hardware) + if (reset_hardware && epnum != 0) dev->ep_out[epnum] = NULL; } else { ep = dev->ep_in[epnum]; - if (reset_hardware) + if (reset_hardware && epnum != 0) dev->ep_in[epnum] = NULL; } if (ep) { -- 2.25.1