Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2340919ybz; Thu, 23 Apr 2020 16:20:59 -0700 (PDT) X-Google-Smtp-Source: APiQypLpxLvGk1WClP9iMJS7T6pHoDB974tFXcSCUJgmmtLcp0tXU1HTFRNOVlcko4B2IzkvyHaS X-Received: by 2002:a05:6402:1d38:: with SMTP id dh24mr5133929edb.9.1587684058897; Thu, 23 Apr 2020 16:20:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587684058; cv=none; d=google.com; s=arc-20160816; b=FsDK/hB2FfuyUgSqWU2QVKZ9WjyhlNf0LCtncXyO0mNju3zjpkDSnlnVHHtE+3H0EZ 4tDLq3wMaXCb658cXg5Fib6H8bWrBHqgssAJncpgXgamgOaPhNgszzlUkZPSq7RnHINQ N1KwyXu0SvzK5rzPAkBFNEqkuxdOGu25KDnqY+7q9e28Woo10QKA1y3O64r55+mRzZuV Pfx6vSuxt5oGq55Xhdj7mWZoCTO62ew3AehWmkXvAnpc1eFctwVE7oxbX857jjTM6ZNL eo6E6xiEiI4PcUYk7H6SYuA/t3iFIwv0ibRxIEP6RrqK8kqCXeluFGu1sd0SZHCRRS5+ +ibw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=rqh+g/yay4DALge8Ct+BhpcSidoxDgMy+0Cohxhy49c=; b=ET3f6IzLG173eVyGJ+wMDB4jSJt6smIX7Jcxx8fHrms9nVe2acvjuHDBRhkIbTfTws W8MYgv+8jGpdHWOyDQQHxadS2YlFkJ4BVIAyfaWTlP7SgJm8Q7946VUDcPO0eHpgaUHk mshTVpW+eKhspHiVR7gL1CnCl1KqGY5RAG9n82Vwe1DHoBvMvgQerjVD+7U4BVgi2noj bOLV2+A/ZkXf/10IyQ5y8FnBB+t2zNRKDDNiRZCdtGWZnarqguxocEnIfW3RexMQx2fj rxHS2wV739zZm0iXLYboywi9yzuMrJS+PpF6mo4K4wQC9InETqdx4L+KwqwPOOd/nhHz t5Fg== 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 i7si2086990edj.520.2020.04.23.16.20.34; Thu, 23 Apr 2020 16:20:58 -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 S1729405AbgDWXQf (ORCPT + 99 others); Thu, 23 Apr 2020 19:16:35 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:49540 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728377AbgDWXGp (ORCPT ); Thu, 23 Apr 2020 19:06:45 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1jRkvT-0004hN-Kk; Fri, 24 Apr 2020 00:06:35 +0100 Received: from ben by deadeye with local (Exim 4.93) (envelope-from ) id 1jRkvS-00E6qm-52; Fri, 24 Apr 2020 00:06:34 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Greg Kroah-Hartman" , "edes" , "Johan Hovold" Date: Fri, 24 Apr 2020 00:06:13 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 146/245] USB: core: add endpoint-blacklist quirk In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.83-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Johan Hovold commit 73f8bda9b5dc1c69df2bc55c0cbb24461a6391a9 upstream. Add a new device quirk that can be used to blacklist endpoints. Since commit 3e4f8e21c4f2 ("USB: core: fix check for duplicate endpoints") USB core ignores any duplicate endpoints found during descriptor parsing. In order to handle devices where the first interfaces with duplicate endpoints are the ones that should have their endpoints ignored, we need to add a blacklist. Tested-by: edes Signed-off-by: Johan Hovold Link: https://lore.kernel.org/r/20200203153830.26394-2-johan@kernel.org Signed-off-by: Greg Kroah-Hartman [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- drivers/usb/core/config.c | 11 +++++++++++ drivers/usb/core/quirks.c | 32 ++++++++++++++++++++++++++++++++ drivers/usb/core/usb.h | 3 +++ include/linux/usb/quirks.h | 3 +++ 4 files changed, 49 insertions(+) --- a/drivers/usb/core/config.c +++ b/drivers/usb/core/config.c @@ -222,6 +222,7 @@ static int usb_parse_endpoint(struct dev struct usb_host_interface *ifp, int num_ep, unsigned char *buffer, int size) { + struct usb_device *udev = to_usb_device(ddev); unsigned char *buffer0 = buffer; struct usb_endpoint_descriptor *d; struct usb_host_endpoint *endpoint; @@ -263,6 +264,16 @@ static int usb_parse_endpoint(struct dev goto skip_to_next_endpoint_or_interface_descriptor; } + /* Ignore blacklisted endpoints */ + if (udev->quirks & USB_QUIRK_ENDPOINT_BLACKLIST) { + if (usb_endpoint_is_blacklisted(udev, ifp, d)) { + dev_warn(ddev, "config %d interface %d altsetting %d has a blacklisted endpoint with address 0x%X, skipping\n", + cfgno, inum, asnum, + d->bEndpointAddress); + goto skip_to_next_endpoint_or_interface_descriptor; + } + } + endpoint = &ifp->endpoint[ifp->desc.bNumEndpoints]; ++ifp->desc.bNumEndpoints; --- a/drivers/usb/core/quirks.c +++ b/drivers/usb/core/quirks.c @@ -318,6 +318,38 @@ static const struct usb_device_id usb_am { } /* terminating entry must be last */ }; +/* + * Entries for blacklisted endpoints that should be ignored when parsing + * configuration descriptors. + * + * Matched for devices with USB_QUIRK_ENDPOINT_BLACKLIST. + */ +static const struct usb_device_id usb_endpoint_blacklist[] = { + { } +}; + +bool usb_endpoint_is_blacklisted(struct usb_device *udev, + struct usb_host_interface *intf, + struct usb_endpoint_descriptor *epd) +{ + const struct usb_device_id *id; + unsigned int address; + + for (id = usb_endpoint_blacklist; id->match_flags; ++id) { + if (!usb_match_device(udev, id)) + continue; + + if (!usb_match_one_id_intf(udev, intf, id)) + continue; + + address = id->driver_info; + if (address == epd->bEndpointAddress) + return true; + } + + return false; +} + static bool usb_match_any_interface(struct usb_device *udev, const struct usb_device_id *id) { --- a/drivers/usb/core/usb.h +++ b/drivers/usb/core/usb.h @@ -29,6 +29,9 @@ extern int usb_deauthorize_device(struct extern int usb_authorize_device(struct usb_device *); extern void usb_detect_quirks(struct usb_device *udev); extern void usb_detect_interface_quirks(struct usb_device *udev); +extern bool usb_endpoint_is_blacklisted(struct usb_device *udev, + struct usb_host_interface *intf, + struct usb_endpoint_descriptor *epd); extern int usb_remove_device(struct usb_device *udev); extern int usb_get_device_descriptor(struct usb_device *dev, --- a/include/linux/usb/quirks.h +++ b/include/linux/usb/quirks.h @@ -62,4 +62,7 @@ /* Hub needs extra delay after resetting its port. */ #define USB_QUIRK_HUB_SLOW_RESET BIT(14) +/* device has blacklisted endpoints */ +#define USB_QUIRK_ENDPOINT_BLACKLIST BIT(15) + #endif /* __LINUX_USB_QUIRKS_H */