Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp107499ybm; Tue, 26 May 2020 11:59:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwiHLQ9wCR6FpwrXwb8VXNiRtqf0c4vm3aTc6Wa779RRqsN0akf04xZuAe7fI772+OpH12a X-Received: by 2002:a17:907:b11:: with SMTP id h17mr2388991ejl.430.1590519570205; Tue, 26 May 2020 11:59:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590519570; cv=none; d=google.com; s=arc-20160816; b=FcJ3vr41TOXAwF3HfyDAch/4XKOEAlvMgRQmQrbsTU2yGJLgL0HsZhZdvDvaJy0Uz2 /z+uWSp6RQIZRAxYxWDorup5xo8w15EhmbOAXP1+tBA0wBokJkL+CXthKw75ZTy/sP6y aBuHqu3sz5n13XJdDr8U3EBkf8owU0ERF7OjP2+b1kRCif67008ZgIgY/N5sNbgxS/eE CMn3s44CatD5NSaiJCi8ZS8S7wln4uvqPLqN5Ntc0LG/UeA+ugkhe+06oVb76h2SJTVh DJqRy5p40rhet9YUtisFEH/acZYqnoBLpmZ0Pi1ITvYsYV9Px3savux+dZY2u3bAOxjR zeAQ== 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=j4FJS3zuyC4UH72jmEqZnnLkcZpHpYgeb6bSK+MknoQ=; b=g9LPZhdhIQCCiqF8JY+lXNCeKxWuqzOYzQmjiVn0EEIA2N5S9czbajUlxdF3fd9lc+ ybAH9N+f052bbjj0ex+/mRz9GCo/dwAGzIqzfUaa9eM64cD6hDnfzjJ+sI0sEIs//HBB usAfgNuLYHraSfo1Cb3wu8q/h4i2b7AOSuG/JXJjYJ81It0TSpFjWQ6j/nQDv4/ZUGmx WB9egsQXT3vVlcRbIPoilTrVAKGwF05YpJpvfhkCByUsKsbyxBj5yCGDaEhMJZtIKmxK kqjSoyK+BppzV01N0EpLulyyEDTqqaorXaCdk/gmGl3npgug2RU6f2pp4+ieW2lgY7LV ytsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uZECACFX; 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 u27si423179edb.377.2020.05.26.11.59.06; Tue, 26 May 2020 11:59:30 -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=uZECACFX; 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 S2389879AbgEZS4g (ORCPT + 99 others); Tue, 26 May 2020 14:56:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:49426 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389868AbgEZS4d (ORCPT ); Tue, 26 May 2020 14:56:33 -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 D7C0521501; Tue, 26 May 2020 18:56:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590519393; bh=yxPt5RtTF67o4Bq8gMPe8OYSr0m+EJyUcIQGpD7elm4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uZECACFXyMpzGM+1eb06Xtzy6bB1NPb+oaPAohfFAVUsyUdm9IolS4qr1bCgikSEb wTQJkUIWcGJ0ZLT9NK7SXeJPt6bjRiC9HYNDcwLdtuz1FnIPOlqEAJC529eSphvThG y6pSczg2himKXOfvxFXi/+8VhaFeFy6Guo0Dkv3Q= 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 4.4 10/65] USB: core: Fix misleading driver bug report Date: Tue, 26 May 2020 20:52:29 +0200 Message-Id: <20200526183910.004128091@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200526183905.988782958@linuxfoundation.org> References: <20200526183905.988782958@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 747343c61398..f083ecfddd1b 100644 --- a/drivers/usb/core/message.c +++ b/drivers/usb/core/message.c @@ -1080,11 +1080,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