Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4293623pxu; Tue, 1 Dec 2020 01:03:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxeGxBkTtabxPTKLli7tEWOUM3QJqLp9ybw4bdC4U9BDF2icOMMWFvzfDf36/C/y/dxf3m+ X-Received: by 2002:a17:906:7f19:: with SMTP id d25mr2060160ejr.0.1606813389357; Tue, 01 Dec 2020 01:03:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606813389; cv=none; d=google.com; s=arc-20160816; b=0SpvA4N5wXRMx59M6YQonj5EW+MZWQkwq474pbadWz+sADYUQY03W/9N9G5ib5K6kp ymEC0z0TJCDVYks/x4uaFEokdIqhIOdErgpvP+SaNeWZ45PSxVykAr3RSrqxirdlTKMs G8QXgEtZ8BaPU3lH5lRqBMSZEdYxKdR2nL2mecsIOfew68sK5QfieP6sskdxRcgSNp4N HJpnydeSSmc2wuRoHwZR7CncXITZYfRsIm3XCsaKZ4Ar2rVOQ3Cee00tbMlOlVqyE5X1 2vOFEvYyLQ4MaugHVQhIpMdEay6TldlQ0tRXjSuu3K6fMth0c8RDITCYJAxz6OKez5o+ /aEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qTCVHfcytquQHyIg7QUItXXtS+mlD9oDwiLTXUVmsFw=; b=NOPMTl2K82xCXDhk8x9RR4cpN6ax7/nlPU3schO748FH2ylpKnBpuAFmbU/YJOtdKh 93nz/j7lZxUSvbmGP+OUJbrpa2QWXWRIoJhUWFlvvgVpvYpQer2RJkT3Fre2Tjdverp0 naBT9l1hd1cXxH1ctwnMk05mpBEulw/JPl7HKXCSDQsCQb2lc6l4PeiDFm8UXOgxdOFT BZD54Z+XDIo65vOSOPL+8mZw+T6WEf6v2MG/twcbrY4FmT1PYZe7cnJDz+XMMhEwFope fWpksqx0m1JSfIOSNp3gMd3sQyIDk2pUFO16KdGgeuHHOAiVgpsFigsrB0JruqzCRGxD CjZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=h+2gs0i7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h6si688566edj.146.2020.12.01.01.02.46; Tue, 01 Dec 2020 01:03:09 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=h+2gs0i7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387755AbgLAI5A (ORCPT + 99 others); Tue, 1 Dec 2020 03:57:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:60366 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387749AbgLAI47 (ORCPT ); Tue, 1 Dec 2020 03:56:59 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 69BBC2222E; Tue, 1 Dec 2020 08:56:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606812978; bh=72mt7MPFu0qBMAIVe2v5dXiPDj1Dh1bCsRL5rPqWPSA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h+2gs0i7XqdgvMo9HQHbfVfpDGg6GcwXeLx94jrzw6UzmJ9sBfmSoNyb49N+3F3qd 7JCb/Csw2gwsJK04E4nkkx5QU+vxZfCHuTRTkn4gmP90hcVZJkuVT569+SmzmbcfIb MtpWYFwDbWYQRA5B6HuBOBSnl3XqtKxWyTYGUef0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, edes , Johan Hovold , Sudip Mukherjee Subject: [PATCH 4.9 41/42] USB: core: add endpoint-blacklist quirk Date: Tue, 1 Dec 2020 09:53:39 +0100 Message-Id: <20201201084646.006741628@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084642.194933793@linuxfoundation.org> References: <20201201084642.194933793@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: stable Signed-off-by: Johan Hovold Link: https://lore.kernel.org/r/20200203153830.26394-2-johan@kernel.org Signed-off-by: Greg Kroah-Hartman [sudip: adjust context] Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- 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 @@ -251,6 +251,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; @@ -292,6 +293,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 @@ -344,6 +344,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 @@ -31,6 +31,9 @@ extern void usb_deauthorize_interface(st extern void usb_authorize_interface(struct usb_interface *); 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 @@ -59,4 +59,7 @@ /* Device needs a pause after every control message. */ #define USB_QUIRK_DELAY_CTRL_MSG BIT(13) +/* device has blacklisted endpoints */ +#define USB_QUIRK_ENDPOINT_BLACKLIST BIT(15) + #endif /* __LINUX_USB_QUIRKS_H */