Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4130866pxb; Mon, 8 Feb 2021 08:38:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJz7nPBj8B3ee+SGWrcvmTadLW73wRaS/4w3ji3R86tVNr/SxeSnUNT/qL8zTmG/xDvuLY2X X-Received: by 2002:a17:906:1199:: with SMTP id n25mr17519428eja.431.1612802304224; Mon, 08 Feb 2021 08:38:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612802304; cv=none; d=google.com; s=arc-20160816; b=D0EqbjWDQpGywebH7VUGfr28wcrT7+KTMPYdN0p44oOdeGQ4q88nusEh1VGM3i/CTd QueBw4gHKuWy7FsZEqDrRs/MvhvZoKr8/mcEBd3dGcmk43zR2IgS8rf0Woex/M8KZSOu 1sYsIKnsmpwyjq6KRxEz6ryeD5pLgMAykVfnIHd5c3XtYREtCw3yEzhqw7SbRs8BVzmU WLpqcf23V2kcYWfRq+c9HfnrVijOapA0qO1uHlN3T77rwRJKXYmNWRR6U7LdIf9JPRYU ZPYHDNfF0Gd+obeVcThZEeGSLtpofMr+Rq3FfpiAmnEXtBOe2DDAiOHgnOgKxbzZg5qm rh9w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Vr8nRBFew+JS0ZsICCFGrTmWx1/J1UQpuhBODXd0AL8=; b=c6oZzi8Xxr7nyrtQ3iUaDaMUiD0FfdJBPmJ5aFSDlaacXyUtrPzMDIZwHewqixyi3X sPEYUyS41PmvEUPLf85zLWCFX7bV3UWUGKCrVSA7ENQX+6V6x4UzqLbiJDCd/mdx4kTI Uz8gY4vq9LQe9JN6eVLdyofqWr7ICsJtrx2xFRvUuhl5tjyEt9fN7fmUErr3eQd/gEh/ allXnoei1oMDQy4WFZ3W3GQzgDlCOXp8d7Z8ZMKQ0nOSu6g2MxDI8cRIrWuqBcGtF3dw vzmmNSe+OVIXiyWZl5MATHY0mtuS0hIdojAnGRRQWHY3F0sbppSB6SJizth7e/FZdKYY ETVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AU4wBGnR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z41si12152764ede.100.2021.02.08.08.38.00; Mon, 08 Feb 2021 08:38:24 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AU4wBGnR; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232521AbhBHQhM (ORCPT + 99 others); Mon, 8 Feb 2021 11:37:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:58890 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230499AbhBHPNs (ORCPT ); Mon, 8 Feb 2021 10:13:48 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id AE9D064E7C; Mon, 8 Feb 2021 15:10:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612797004; bh=zBBcl3AJJa0LHaxOzVHB5o2Lj1ynzAQfpbwmB8ozt8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AU4wBGnRaN+99ggGf/Z9k9YBPJodCDV04NmwXY+mK24W3jsmJmBluLTJgCvnLU5jt oXLkCENgFqIvr1IygLaKFXRNhknBgL2iEcdzM+PlnT9yTCptrApxaqphBfgbhdMumn 43Lf394LZNxWhvztgvHjbzQChyABI3qRKAjG7NTk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gerhard Klostermeier , Heiko Stuebner Subject: [PATCH 5.4 26/65] usb: dwc2: Fix endpoint direction check in ep_from_windex Date: Mon, 8 Feb 2021 16:00:58 +0100 Message-Id: <20210208145811.242400607@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208145810.230485165@linuxfoundation.org> References: <20210208145810.230485165@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Heiko Stuebner commit f670e9f9c8cac716c3506c6bac9e997b27ad441a upstream. 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") Cc: stable@vger.kernel.org Reported-by: Gerhard Klostermeier Signed-off-by: Heiko Stuebner Link: https://lore.kernel.org/r/20210127103919.58215-1-heiko@sntech.de Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc2/gadget.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -1543,7 +1543,6 @@ static void dwc2_hsotg_complete_oursetup static struct dwc2_hsotg_ep *ep_from_windex(struct dwc2_hsotg *hsotg, u32 windex) { - struct dwc2_hsotg_ep *ep; int dir = (windex & USB_DIR_IN) ? 1 : 0; int idx = windex & 0x7F; @@ -1553,12 +1552,7 @@ static struct dwc2_hsotg_ep *ep_from_win if (idx > hsotg->num_of_eps) return NULL; - ep = index_to_ep(hsotg, idx, dir); - - if (idx && ep->dir_in != dir) - return NULL; - - return ep; + return index_to_ep(hsotg, idx, dir); } /**