Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4334417rwl; Mon, 10 Apr 2023 09:27:21 -0700 (PDT) X-Google-Smtp-Source: AKy350ard9e130PUHolrA4E9UZTCVv9gaVidfXV8moJNaZk1Gpzus4rnkJVWRH9k7YWMsPzNtkDB X-Received: by 2002:a17:906:4c48:b0:94a:86dc:3a13 with SMTP id d8-20020a1709064c4800b0094a86dc3a13mr3744154ejw.75.1681144041214; Mon, 10 Apr 2023 09:27:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681144041; cv=none; d=google.com; s=arc-20160816; b=E67bBpN1YB6I3bCCOdM59cCOxH7xgFX8VQmPAA1/irgGjU09wkctiIlN7s+g195Z1K ZDmP+oWYA0cm1tD92YjqvTjPSQtzIYUJE51DkIhuRhfrVyXgYXlwN41a5UjBxIvP+ZuU tMGEn+TU9k9t6rDzjP8/YXyL18+DLh83Gq4HAuUcLr+lKjOQ+UIvifecK/hlxxKtsen8 lNezScvr5GyXCPhVNGLyo8sYssmXyZlAWLNX7MwTJ3hT+hSiOimXKaRUJF248P4FIG+9 r1HsWehtLYzfEMpIrAFsK1jKYgnl5hmyCjz1RJQ1MYPUZfoO2KbmN7koU7MjiiuE4vlK V6Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=jC+katkipntbvIhkLRCLTcPO7FIgvPLGXdYtxr1uMDQ=; b=Ps0NISx32AHpE04FeMMbx45yFN6jxwEMEkBuYNMHMUp1WJu7wGPnmuTfwaK8wdb9/J X/YRJw90rMAxj/YUEjJ5dAwnu5/9g71/u8hgW5zxIUY5RWVJXnO1HpAe0k2y0rLfbTAI tiytL5ujrZupWHLemCGddRzx94J0rusGwIiQRE0dm89dqkMQjCY5XfNB3jjOUa3s15Iz tTDA6myqvVgfdvXeE0m1yURKMUPCLlohbYmmLtAaNYIys+Kros+Vn4sTZqqj1HK73mQO IwncKx8KVuF3fWzVDAmEJO3URstI2FbxxRGiFsB8S0WTNMcFD0kyOnW4JRwOcr9T+YLX T3Mg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hf11-20020a1709072c4b00b00933f276be3fsi8365433ejc.656.2023.04.10.09.26.56; Mon, 10 Apr 2023 09:27:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230113AbjDJQJh (ORCPT + 99 others); Mon, 10 Apr 2023 12:09:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229703AbjDJQJf (ORCPT ); Mon, 10 Apr 2023 12:09:35 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 64D84171D for ; Mon, 10 Apr 2023 09:09:32 -0700 (PDT) Received: (qmail 139685 invoked by uid 1000); 10 Apr 2023 12:09:31 -0400 Date: Mon, 10 Apr 2023 12:09:31 -0400 From: Alan Stern To: syzbot , Thomas Winischhofer Cc: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Subject: Re: [syzbot] WARNING in sisusb_send_bulk_msg/usb_submit_urb Message-ID: <1d74e8db-682e-4d9a-af69-3ec56835021e@rowland.harvard.edu> References: <00000000000096e4f905f81b2702@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=0.2 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The patch has been revised. Make sure it still works right. Alan Stern #syz test: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ v6.2 Index: usb-devel/drivers/usb/core/usb.c =================================================================== --- usb-devel.orig/drivers/usb/core/usb.c +++ usb-devel/drivers/usb/core/usb.c @@ -207,6 +207,82 @@ int usb_find_common_endpoints_reverse(st EXPORT_SYMBOL_GPL(usb_find_common_endpoints_reverse); /** + * usb_find_endpoint() - Given an endpoint address, search for the endpoint's + * usb_host_endpoint structure in an interface's current altsetting. + * @intf: the interface whose current altsetting should be searched + * @ep_addr: the endpoint address (number and direction) to find + * + * Search the altsetting's list of endpoints for one with the specified address. + * + * Return: Pointer to the usb_host_endpoint if found, %NULL otherwise. + */ +static const struct usb_host_endpoint *usb_find_endpoint( + const struct usb_interface *intf, unsigned int ep_addr) +{ + int n; + const struct usb_host_endpoint *ep; + + n = intf->cur_altsetting->desc.bNumEndpoints; + ep = intf->cur_altsetting->endpoint; + for (; n > 0; (--n, ++ep)) { + if (ep->desc.bEndpointAddress == ep_addr) + return ep; + } + return NULL; +} + +/** + * usb_check_bulk_endpoints - Check whether an interface's current altsetting + * contains a set of bulk endpoints with the given addresses. + * @intf: the interface whose current altsetting should be searched + * @ep_addrs: 0-terminated array of the endpoint addresses (number and + * direction) to look for + * + * Search for endpoints with the specified addresses and check their types. + * + * Return: %true if all the endpoints are found and are bulk, %false otherwise. + */ +bool usb_check_bulk_endpoints( + const struct usb_interface *intf, const u8 *ep_addrs) +{ + const struct usb_host_endpoint *ep; + + for (; *ep_addrs; ++ep_addrs) { + ep = usb_find_endpoint(intf, *ep_addrs); + if (!ep || !usb_endpoint_xfer_bulk(&ep->desc)) + return false; + } + return true; +} +EXPORT_SYMBOL_GPL(usb_check_bulk_endpoints); + +/** + * usb_check_int_endpoints - Check whether an interface's current altsetting + * contains a set of interrupt endpoints with the given addresses. + * @intf: the interface whose current altsetting should be searched + * @ep_addrs: 0-terminated array of the endpoint addresses (number and + * direction) to look for + * + * Search for endpoints with the specified addresses and check their types. + * + * Return: %true if all the endpoints are found and are interrupt, + * %false otherwise. + */ +bool usb_check_int_endpoints( + const struct usb_interface *intf, const u8 *ep_addrs) +{ + const struct usb_host_endpoint *ep; + + for (; *ep_addrs; ++ep_addrs) { + ep = usb_find_endpoint(intf, *ep_addrs); + if (!ep || !usb_endpoint_xfer_int(&ep->desc)) + return false; + } + return true; +} +EXPORT_SYMBOL_GPL(usb_check_int_endpoints); + +/** * usb_find_alt_setting() - Given a configuration, find the alternate setting * for the given interface. * @config: the configuration to search (not necessarily the current config). Index: usb-devel/include/linux/usb.h =================================================================== --- usb-devel.orig/include/linux/usb.h +++ usb-devel/include/linux/usb.h @@ -292,6 +292,11 @@ void usb_put_intf(struct usb_interface * #define USB_MAXINTERFACES 32 #define USB_MAXIADS (USB_MAXINTERFACES/2) +bool usb_check_bulk_endpoints( + const struct usb_interface *intf, const u8 *ep_addrs); +bool usb_check_int_endpoints( + const struct usb_interface *intf, const u8 *ep_addrs); + /* * USB Resume Timer: Every Host controller driver should drive the resume * signalling on the bus for the amount of time defined by this macro. Index: usb-devel/drivers/usb/misc/sisusbvga/sisusbvga.c =================================================================== --- usb-devel.orig/drivers/usb/misc/sisusbvga/sisusbvga.c +++ usb-devel/drivers/usb/misc/sisusbvga/sisusbvga.c @@ -2778,6 +2778,20 @@ static int sisusb_probe(struct usb_inter struct usb_device *dev = interface_to_usbdev(intf); struct sisusb_usb_data *sisusb; int retval = 0, i; + static const u8 ep_addresses[] = { + SISUSB_EP_GFX_IN | USB_DIR_IN, + SISUSB_EP_GFX_OUT | USB_DIR_OUT, + SISUSB_EP_GFX_BULK_OUT | USB_DIR_OUT, + SISUSB_EP_GFX_LBULK_OUT | USB_DIR_OUT, + SISUSB_EP_BRIDGE_IN | USB_DIR_IN, + SISUSB_EP_BRIDGE_OUT | USB_DIR_OUT, + 0}; + + /* Are the expected endpoints present? */ + if (!usb_check_bulk_endpoints(intf, ep_addresses)) { + dev_err(&intf->dev, "Invalid USB2VGA device\n"); + return -EINVAL; + } dev_info(&dev->dev, "USB2VGA dongle found at address %d\n", dev->devnum);