Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4328994rwl; Mon, 10 Apr 2023 09:22:26 -0700 (PDT) X-Google-Smtp-Source: AKy350ZpDL5X2K38hlUNVPqIX2s+pYvAVnH7s+DsXIbq9Z9+gpcMAD/mV8c8Ib2qw0t/ZZgZHS9d X-Received: by 2002:aa7:d452:0:b0:504:8b9a:39fa with SMTP id q18-20020aa7d452000000b005048b9a39famr6227870edr.19.1681143745871; Mon, 10 Apr 2023 09:22:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681143745; cv=none; d=google.com; s=arc-20160816; b=ZEo069V1WrPdlnMY4ZrBufedOwGa/YCaCYWfxWtyGKvVPUONXZfDBUSsVHVhI4bXEa GDEX9GRGwngFu9MOdwdGaWZKh3u6HGxOhgh9kxp4Ft5yXk8TezyN3AjISQOSvwlGIcry 3Vp/oofVwmdwMoA5DbOpfTgwo9dtmYoFxev3ovWujWOZlcGP2LSZzNKjbvSQGPpernOt Rk9aEkSArjFaQQiqSSY2Nkh05WgeUhkL/jIzyEZUSK6DTHhn8eouFAhHcTLExXzM4a9E lUA0RzCItDfArHuBF1f0tBJU3KgfMh37ESeLQAF8XLk8v6c6QF0E8XEL4YDwdlC1bqn6 7rAA== 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=qqp9o0BruY4/ZBPbV+UyBUYSBRSAIE4amYizc/dO3k8=; b=rem/owQScfy631oMONbjgAQSpDEYoQXyeLL9JqwQzfBC57omhALMIJada9HZjK3cS2 gM60oExdJHP3mSSEq20P+9zCygRaYdlDFF5DEefIVUnuvU3dRAoQbBeb3miZKBG62Ijg V20P66AXNq2tXPdGiP8ZzWMWwQ7974nP2b/hAwl+SgvgwimQBZ+LTJRz/Olvb7lw9nAu 9VEMyjQkEVLhcmWFxAqNiS5mGEk0DCAuVVAF2S2EOsAY14jhqDSB+X/ePVgL4dHEsZ57 22Tql41MzQEKfoNfXAeiiUB+MaLwNbTgYOEXeVhQDELSIS9YDZ+1xRYmDMiBluqjO8Ha IVxQ== 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 u4-20020a50eac4000000b004ad1256d8e3si71068edp.51.2023.04.10.09.22.01; Mon, 10 Apr 2023 09:22:25 -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 S230086AbjDJQMY (ORCPT + 99 others); Mon, 10 Apr 2023 12:12:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229703AbjDJQMX (ORCPT ); Mon, 10 Apr 2023 12:12:23 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 7E219120 for ; Mon, 10 Apr 2023 09:12:21 -0700 (PDT) Received: (qmail 139825 invoked by uid 1000); 10 Apr 2023 12:12:20 -0400 Date: Mon, 10 Apr 2023 12:12:20 -0400 From: Alan Stern To: syzbot Cc: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Subject: Re: [syzbot] WARNING in shark_write_reg/usb_submit_urb Message-ID: 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/media/radio/radio-shark.c =================================================================== --- usb-devel.orig/drivers/media/radio/radio-shark.c +++ usb-devel/drivers/media/radio/radio-shark.c @@ -316,6 +316,16 @@ static int usb_shark_probe(struct usb_in { struct shark_device *shark; int retval = -ENOMEM; + static const u8 ep_addresses[] = { + SHARK_IN_EP | USB_DIR_IN, + SHARK_OUT_EP | USB_DIR_OUT, + 0}; + + /* Are the expected endpoints present? */ + if (!usb_check_int_endpoints(intf, ep_addresses)) { + dev_err(&intf->dev, "Invalid radioSHARK device\n"); + return -EINVAL; + } shark = kzalloc(sizeof(struct shark_device), GFP_KERNEL); if (!shark) Index: usb-devel/drivers/media/radio/radio-shark2.c =================================================================== --- usb-devel.orig/drivers/media/radio/radio-shark2.c +++ usb-devel/drivers/media/radio/radio-shark2.c @@ -282,6 +282,16 @@ static int usb_shark_probe(struct usb_in { struct shark_device *shark; int retval = -ENOMEM; + static const u8 ep_addresses[] = { + SHARK_IN_EP | USB_DIR_IN, + SHARK_OUT_EP | USB_DIR_OUT, + 0}; + + /* Are the expected endpoints present? */ + if (!usb_check_int_endpoints(intf, ep_addresses)) { + dev_err(&intf->dev, "Invalid radioSHARK2 device\n"); + return -EINVAL; + } shark = kzalloc(sizeof(struct shark_device), GFP_KERNEL); if (!shark)