Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp790019rwl; Wed, 5 Apr 2023 07:46:31 -0700 (PDT) X-Google-Smtp-Source: AKy350bXhpR7Mcxi5f4o/ES2A6zBIInChcvV48Oks0GQNTA5Aoq+iZwKVu+cJZrs9TZaFpsa8OA4 X-Received: by 2002:a17:902:9b8c:b0:1a1:e39c:d4d1 with SMTP id y12-20020a1709029b8c00b001a1e39cd4d1mr5373045plp.67.1680705991449; Wed, 05 Apr 2023 07:46:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680705991; cv=none; d=google.com; s=arc-20160816; b=ejqRhj7kcuGao4x/IUz5ti4HYU9oUO8h1u9msTE6IGy0RFFtFhCU9GVej0+gi+A9Tz jX1D7C0m0/66MpupQ7HTl0UOKqjo9QuWHdBCJSKG34W1QchI0+qPbObMBM/9tprc0zh8 jwYGyvEFy2m0Pkkjz40SlgFrxFVqTqoVKXJ9KdwfzqGuD/jB2xmtDlDINE3lNnBXnSL6 TesXfS/0ye94rMWuVzVsEkKsfB7JjB9TEToKg1kmLjXL28tebNfzzqhsVACMflC5PA3D lI9h2XgfSsYQsyX6vEX8WlPeTWrKDYoJy5s6ZZL7wPRdDPqwKogIUfvNdsGYMBkhrOUz iNCQ== 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:feedback-id :dkim-signature:dkim-signature; bh=E6DttPKIAkYtM9DtOnAsbVOxX0PkhYz8tu5+srYClwg=; b=nXgPMxAxHcXUWYjz4SBej5OWgWutiSmGbj6UI4GT1UZaNEWokxwaFUxj8PCtNgUxsh r1CIkRO5iZxxCijJJwWm3GHIZ93whGEdQTTAnwCmXU1rPw9q14qivlDlr/5AhnHNFfMV hhQCywA4X7eih81gn0Mr4LRZ5STSU/e08Vm2J/O8rCMCqUXGyDxatXQz/VA2nsV2Zztm Bx4dx4iSQp+Cjglq5wvUw1+QcaluC8t+g2aT7+9DShsaebAjeYHPy5LmJdLu7VX/N6qX 7uK8alV5Yiihmn4/X4U4F8ugF2jjT0ormAs8tDUQEAARmQSc6zTWTZKFgYucbddJxBl3 xTOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kroah.com header.s=fm2 header.b=m9lHysEQ; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=YkkZC8vO; 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 n16-20020a170903111000b0019647978087si3852306plh.364.2023.04.05.07.46.18; Wed, 05 Apr 2023 07:46:31 -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; dkim=pass header.i=@kroah.com header.s=fm2 header.b=m9lHysEQ; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=YkkZC8vO; 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 S238437AbjDEOoz (ORCPT + 99 others); Wed, 5 Apr 2023 10:44:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238532AbjDEOor (ORCPT ); Wed, 5 Apr 2023 10:44:47 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 403EFFB; Wed, 5 Apr 2023 07:44:43 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 7F8C85C020C; Wed, 5 Apr 2023 10:44:42 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 05 Apr 2023 10:44:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kroah.com; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1680705882; x=1680792282; bh=E6 DttPKIAkYtM9DtOnAsbVOxX0PkhYz8tu5+srYClwg=; b=m9lHysEQ5s/W4FDdkp UqmtjQ6Vk/FWndvjtjAbtr1aLYAEhKP2mD7OZZnu0/d7dqNpZuKwl/mIbdjEDmPZ 25AMo+i7LmPIfSSEASojMyUzXlX50D42qZVq+pxoEsoujb5hRZHiljm5LMXnGq+j wlpS5Z8a0WCCoPHcZCBXt+v7eaiMvx1oUs/SjJFYNn/Ftaip8JhLFB/gGLDMYosO XGc1vAuse002hKJqgkHc9UMvdqufuk63Vb/iJYL08SpzqEvMz5aMy5h8r36bC7xs 9xKtw9Le6NVuOx7Pq0WCfPHeOHsxILRFjxTPQqDQ4H4yhIwW7dT13SNTB9WfKth8 C3Ww== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1680705882; x=1680792282; bh=E6DttPKIAkYtM 9DtOnAsbVOxX0PkhYz8tu5+srYClwg=; b=YkkZC8vOTPAiljHleKVuwZwtRjBxN ywaQSRS2bcKyXhRoPg7omfSnnhLihLTHEZwXGVuJpWPVPriX5kGxD0EouYUD0/ne zpDz894PuWpHeHXHGeSWHi8jhSzP5pf+HmDu0ragIv6HYM/MKvyhvqpqE04M20cR a9Egr7MZmPm1tXQmuFITrghcRtM5aZot4rjtMBoqbrU8/mjtwJvdWrQMl/ku6dYC jO0vjtjQTC45SyTMfvoeKnbs0r+/r1wqsXcbYGPt/aOB4vn5K/Hvm+1hZv1xnm4Q ij2WNXKsxyksnUxf12BB2Je4D7Zq7n7gjJ/zup3gFXKMbwIxqWnPihkkw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdejuddgkeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepifhrvghg ucfmjfcuoehgrhgvgheskhhrohgrhhdrtghomheqnecuggftrfgrthhtvghrnhepleevve dtvdfhheefuddvffdthedutddvfeektdekvedvueegudfffefhieetfeevnecuffhomhgr ihhnpehshiiikhgrlhhlvghrrdgrphhpshhpohhtrdgtohhmpdhkvghrnhgvlhdrohhrgh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehgrhgv gheskhhrohgrhhdrtghomh X-ME-Proxy: Feedback-ID: i787e41f1:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 5 Apr 2023 10:44:41 -0400 (EDT) Date: Wed, 5 Apr 2023 16:44:37 +0200 From: Greg KH To: Alan Stern Cc: Hans de Goede , syzbot , syzbot , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, syzkaller-bugs@googlegroups.com Subject: Re: [syzbot] WARNING in shark_write_reg/usb_submit_urb, WARNING in shark_write_val/usb_submit_urb Message-ID: <2023040544-cuddly-glancing-f577@gregkh> References: <00000000000096e4f905f81b2702@google.com> <8896f261-9602-4663-aa87-1feb9bf3ec0f@redhat.com> <2023040148-aground-cornbread-84e2@gregkh> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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 On Sat, Apr 01, 2023 at 02:38:39PM -0400, Alan Stern wrote: > On Sat, Apr 01, 2023 at 04:53:17PM +0200, Greg KH wrote: > > On Sat, Apr 01, 2023 at 12:48:07PM +0200, Hans de Goede wrote: > > > Hi Alan, > > > > > > On 3/30/23 22:10, Alan Stern wrote: > > > > Reference: https://syzkaller.appspot.com/bug?extid=4b3f8190f6e13b3efd74 > > > > Reference: https://syzkaller.appspot.com/bug?extid=1cb937c125adb93fad2d > > > > > > > > The radio-shark driver just assumes that the endpoints it uses will be > > > > present, without checking. This adds an appropriate check. > > > > > > > > Alan Stern > > > > > > > > #syz test: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ v6.2 > > > > > > Thank you for working on this! > > > > > > Both the core changes and the 2 radio-shark driver changes look good to me. > > > > > > Please add my: > > > > > > Reviewed-by: Hans de Goede > > > > > > When submitting these upstream. > > > > > > Regards, > > > > > > Hans > > > > > > > > > > > > > > > > > > > > > > > drivers/usb/core/usb.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ > > > > include/linux/usb.h | 7 ++++ > > > > 2 files changed, 77 insertions(+) > > > > > > > > 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,76 @@ 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. > > > > + */ > > > > +struct usb_host_endpoint __must_check *usb_find_endpoint( > > > > + const struct usb_interface *intf, unsigned int ep_addr) > > > > +{ > > > > + int n; > > > > + 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; > > > > +} > > > > +EXPORT_SYMBOL_GPL(usb_find_endpoint); > > > > + > > > > +/** > > > > + * usb_check_bulk_endpoint - Check whether an interface's current altsetting > > > > + * contains a bulk endpoint with the given address. > > > > + * @intf: the interface whose current altsetting should be searched > > > > + * @ep_addr: the endpoint address (number and direction) to look for > > > > + * > > > > + * Search for an endpoint with the specified address and check its type. > > > > + * > > > > + * Return: %true if the endpoint is found and is bulk, %false otherwise. > > > > + */ > > > > +bool usb_check_bulk_endpoint( > > > > + const struct usb_interface *intf, unsigned int ep_addr) > > > > +{ > > > > + const struct usb_host_endpoint *ep; > > > > + > > > > + ep = usb_find_endpoint(intf, ep_addr); > > > > + if (!ep) > > > > + return false; > > > > + return usb_endpoint_xfer_bulk(&ep->desc); > > > > +} > > > > +EXPORT_SYMBOL_GPL(usb_check_bulk_endpoint); > > > > + > > > > +/** > > > > + * usb_check_int_endpoint - Check whether an interface's current altsetting > > > > + * contains an interrupt endpoint with the given address. > > > > + * @intf: the interface whose current altsetting should be searched > > > > + * @ep_addr: the endpoint address (number and direction) to look for > > > > + * > > > > + * Search for an endpoint with the specified address and check its type. > > > > + * > > > > + * Return: %true if the endpoint is found and is interrupt, %false otherwise. > > > > + */ > > > > +bool usb_check_int_endpoint( > > > > + const struct usb_interface *intf, unsigned int ep_addr) > > > > +{ > > > > + const struct usb_host_endpoint *ep; > > > > + > > > > + ep = usb_find_endpoint(intf, ep_addr); > > > > + if (!ep) > > > > + return false; > > > > + return usb_endpoint_xfer_int(&ep->desc); > > > > +} > > > > +EXPORT_SYMBOL_GPL(usb_check_int_endpoint); > > > > Shouldn't you use the usb_find_bulk_in_endpoint() and friends functions > > instead of these? Many drivers hard-coded their "I know this endpoint > > is this type" which breaks in fuzzing as you know (and see here), which > > is why those functions were created to be used. > > It's true, we could use the existing functions in this case. I'm not sure > which approach would be better; it's probably mostly a matter of taste. > > Using the existing functions, the probe function would get additional code > something like this: > > struct usb_endpoint_descriptor *ep; > > if (!(usb_find_int_in_endpoint(intf->cur_altsetting, &ep) == 0 && > usb_endpoint_num(&ep->desc) == SHARK_IN_EP) || > !(usb_find_int_out_endpoint(intf->cur_altsetting, &ep) == 0 && > usb_endpoint_num(&ep->desc) == SHARK_OUT_EP)) { > dev_err(... > > Using the new functions (with a revised API, see the patch below) we would > instead add this: > > static const u8 ep_addresses[] = { > SHARK_IN_EP | USB_DIR_IN, > SHARK_OUT_EP | USB_DIR_OUT, > 0}; > > if (!usb_check_int_endpoints(intf, ep_addresses)) { > dev_err(... > > In this case the difference is not particularly meaningful. With the new > functions, the amount of code added to the driver is smaller, but of > course that's offset by adding the new functions themselves to the core. > (On the other hand there's probably a bunch of drivers that could stand > to be fixed up this way, which would amortize the cost to the core.) > > The difference becomes a lot more noticeable with the sisusbvga driver > [1]. It has six endpoints that need to be checked: four bulk-OUT and two > bulk-IN. While usb_find_common_endpoints() would be able to find them, > it's not well suited for checking that they have the expected addresses. > With the new functions, all the work can be done with a single call. > > > I think just using them in the probe function would fix this issue > > instead of these functions which would only be used by that one driver. > > It wouldn't be used just by these two drivers. The new routines are > ideally suited for doing the checking in old drivers that have their > endpoint numbers and directions built-in, like these do. While I haven't > looked to see, there must be quite a few of them. Ok, fair enough, let's take this and see what other drivers can be fixed up this way. thanks, greg k-h