Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp535483pxb; Wed, 27 Jan 2021 14:12:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJwVLvGkmkVgIkXmXjO4iFDU+uQD1UhNcIXzFk0GAdRMU3/MrivF1MjzGxtAI8+2Qlin38iR X-Received: by 2002:a50:d60f:: with SMTP id x15mr10718576edi.224.1611785577747; Wed, 27 Jan 2021 14:12:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611785577; cv=none; d=google.com; s=arc-20160816; b=S6eZhcZsGRdsfZzuZ9I/tfNLR1ROP6rfuWNacdlWdd/k1oA4EgyH/9X1jFREHbzuEV Y64EpunKf5UvsOk5P0LZfU/gy3DwBpf37VBa5o1NEN5pCIMoW62ADdoCFH4b5lcvym80 rX1z5Js+t9kU/ACtFHI0TREc7U0QuvYU26Zp1x1aJvzbmCeJ5ZOpo/vrOutt4ZOfg64y AES0lc8LXFy4MF33k8vSYIfc3dXJ8RRTZjmQSXnHw5mTX33BEZ15yyZVDhdXupotHZx8 4+d1VM6oqhj0E5F0giHZryMYwjhlDLOoKTZs9DkHaZCo6VK1ekaXwp93MDB0ye1PRCr0 u7qw== 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=UaDpwHQfjcRzGhB7RW1pGrqU7qgbZyi+lMzB3TUSp4c=; b=pZldoQsGPbUjSEnyRlSuGOw08DmypntImIUYCSAfHfWSWi12A++1yOQWN9WtKwFx1v DP4WGPtvxnLVkNo6WYJpadyyHKfcO32259zs35YDq62qSb26kB3WJ5rrjGgswX6TQm0n JDrQG7vti3GwOAmhqLLTC+rB58/buzTSzv0YDqGQbBkZbJigU6hqypEHOy5GET+AJLHw hzmVtpQwovQso4xdNs2k1fU3MuKJGl894hfXM1X3fU0T5vucmcnsOLSK/FcnZ0NPn3ZM dJKucbcKCyBsj2X0iM0Em+b09bT9heDVHtJcVIz1Sg0eJby+J+KUTkBk048TKs9Vt1ON dveA== 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 r21si1509565ejo.415.2021.01.27.14.12.32; Wed, 27 Jan 2021 14:12:57 -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 S236149AbhA0Kpu (ORCPT + 99 others); Wed, 27 Jan 2021 05:45:50 -0500 Received: from gloria.sntech.de ([185.11.138.130]:42116 "EHLO gloria.sntech.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235626AbhA0KlC (ORCPT ); Wed, 27 Jan 2021 05:41:02 -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 1l4iFD-0000l9-Kn; Wed, 27 Jan 2021 11:40:15 +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 v2] usb: dwc2: Fix endpoint direction check in ep_from_windex Date: Wed, 27 Jan 2021 11:40:14 +0100 Message-ID: <1943589.UkFFEUeh36@diego> In-Reply-To: <20210127085034.36397-1-heiko@sntech.de> References: <20210127085034.36397-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 Mittwoch, 27. Januar 2021, 09:50:34 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