Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp583771pxb; Wed, 27 Jan 2021 15:51:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJzkGR142TH/Irv6rYpfuxzaXI6Albb8OgNfqlgukOIUNKR/WlpZ6oWzlyGmyx/ycEGyJNxa X-Received: by 2002:a50:fc8c:: with SMTP id f12mr11219113edq.225.1611791514013; Wed, 27 Jan 2021 15:51:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611791514; cv=none; d=google.com; s=arc-20160816; b=Ir5eG+rQu6b+wfSuQewZ0lQCUmCMKmlqv9tUfRBvQ01rOrbZJkkLwi3kCCSBgwAyUW I7sH8EC0/BVwkC9pKVRlbX7UXmLwIffFntfuPAgmAyiGGyyGqFNOT0T9h2mNyEoUwogB MTycyJMUtIBZEre22FQiukgrqKld7GBBcAZPHUgbgO0ijUTFaEu2LcQnPw+Ps5kwalpl vmwZBuTx4X7xYY1F4G8QD1yyRYWj3uGwy7BlgFqlB48M79j7uKr4TYQZKUXI1iU2Ya5w SotF6jIfElwuGc98xJZv6aNA282s3J+vb87t3WHofiBbLQH4zJgqBWyDmR0dHHwrBIyA 6zDA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=/N5p6M/PBzxDKVjaYCeb+7LbqPWKq8s6jFvg+iK8Iy0=; b=ioh4iWu7MkoBb278kxZCZ466g4Xd9427debC5V9OYA0IjJ8vYckp5Vfb/PUTUITlBM I+4KF2JT7lH/qXR7d9Cq54X/iA/afZsNHOD/TAtCNyMdh66CgJZ7HVMfKEgAH62GpjVQ 7gfLzGJV9wKHdZHgg3Nq0ZL5bXoY66ivXx9qRxKXMI70yl5vUrecolsZWL1mGnGG5Mc6 cMritxU80dhB3jamGMl3MjAhccIRdad7SPyPSGQ4NBmUxiFUZqDbOygF0MAEdz2zVNr7 f6zGAR05SwiaQM6DZxlGjN0vw3348isStNTP8EyQNdv6Z3+lksx/pVNMDnxUO68Bx4Z5 d2aQ== 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 v14si1804904edc.56.2021.01.27.15.51.30; Wed, 27 Jan 2021 15:51:54 -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; 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 S235909AbhA0LUd (ORCPT + 99 others); Wed, 27 Jan 2021 06:20:33 -0500 Received: from gloria.sntech.de ([185.11.138.130]:42148 "EHLO gloria.sntech.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235466AbhA0Klg (ORCPT ); Wed, 27 Jan 2021 05:41:36 -0500 Received: from ip5f5aa64a.dynamic.kabel-deutschland.de ([95.90.166.74] helo=diego.localnet) by gloria.sntech.de with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l4iFm-0000lT-8T; Wed, 27 Jan 2021 11:40:50 +0100 From: Heiko =?ISO-8859-1?Q?St=FCbner?= To: hminas@synopsys.com, gregkh@linuxfoundation.org Cc: christoph.muellner@theobroma-systems.com, paulz@synopsys.com, yousaf.kaukab@intel.com, balbi@ti.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] usb: dwc2: Fix endpoint direction check in ep_from_windex Date: Wed, 27 Jan 2021 11:40:48 +0100 Message-ID: <8309688.OUTRe80PYV@diego> In-Reply-To: <20210125191324.1981199-1-heiko@sntech.de> References: <20210125191324.1981199-1-heiko@sntech.de> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am Montag, 25. Januar 2021, 20:13:24 CET schrieb Heiko Stuebner: > From: Heiko Stuebner > > dwc2_hsotg_process_req_status uses ep_from_windex() to retrieve > the endpoint for the index provided in the wIndex request param. > > In a test-case with a rndis gadget running and sending a malformed > packet to it like: > dev.ctrl_transfer( > 0x82, # bmRequestType > 0x00, # bRequest > 0x0000, # wValue > 0x0001, # wIndex > 0x00 # wLength > ) > it is possible to cause a crash: > > [ 217.533022] dwc2 ff300000.usb: dwc2_hsotg_process_req_status: USB_REQ_GET_STATUS > [ 217.559003] Unable to handle kernel read from unreadable memory at virtual address 0000000000000088 > ... > [ 218.313189] Call trace: > [ 218.330217] ep_from_windex+0x3c/0x54 > [ 218.348565] usb_gadget_giveback_request+0x10/0x20 > [ 218.368056] dwc2_hsotg_complete_request+0x144/0x184 > > This happens because ep_from_windex wants to compare the endpoint > direction even if index_to_ep() didn't return an endpoint due to > the direction not matching. > > The fix is easy insofar that the actual direction check is already > happening when calling index_to_ep() which will return NULL if there > is no endpoint for the targeted direction, so the offending check > can go away completely. > > Fixes: c6f5c050e2a7 ("usb: dwc2: gadget: add bi-directional endpoint support") > Signed-off-by: Heiko Stuebner > Cc: stable@vger.kernel.org superseeded by v3, which includes an appropriate Reported-by tag and removes an now unused variable (in v2).