Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp50437pxb; Mon, 8 Feb 2021 14:56:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJwCZWd6LhrJFuW/5F5Lk5Ep9k6ZPk1soZyK9Fgz7S/OUippW8Fi6mEJoEftXyVJ38lxJWSZ X-Received: by 2002:a05:6402:1589:: with SMTP id c9mr20097031edv.282.1612824979882; Mon, 08 Feb 2021 14:56:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612824979; cv=none; d=google.com; s=arc-20160816; b=dyyz/2qLshjGgvUmqorL9u8hkeQnqLvCeI+M8CtQcmHpF0nnpPr+wfLntH3S6weSNr 6YTwKo2kru1l2NlU9YcEg9SuivKvLlI7rAf2AUKMahXl82MAKLU+Ch2CXyRshja1Hjy8 tZtLvRKWhRurmUfs+K+BB6sDRJuA92T8SpHYLD75HegPKx9WQA7+UhBAb0ddlti0tUST SxqXMfq7xXadS3f8jCbmGtaActeYbDGXajcg8MVj1PaH5VHyNNWgWopcbadvmpRkkya4 uaRmJDdflEjfxHbonvhBXXmOJeHhAwwcA0la39XkW2H963zXljio/Nq1psgvyIPEefiX VYEw== 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=zuVrES1FRgVjiulbJa8HYEJW0l16k0eNFYngXssfuZ8=; b=O5yb4Y1SJvqgH5C9dRtYdUpOv1fr3CbhX/F6XlllSMUAJkpqTeX34qHbbm6JDIlzvD MS2gXkkYqRbJnBhn86ePM6a9BfAfPHovdO9pKMgfy2Rm2gvbuk32KH39roTgGACk0dks BZaNWIO4vzmUCqAw8+fxoNUVqEgj7IY5eW1i39rrf32LJmEa2NLclMo4mqEVIH97j0Qz L6EfWDvSnt8QYLPmw0EOBQCUAbeQID9MVpIRu2KdZ2ntBVqPmeHPvp9RUrK2a+p21v8l 0CqjxG3klz3imuyGl0qyRmKozjqFV1GBhnxYWA0pZ4aX02tYdSQSEwktGySCy5d9i8zR zH7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gIVjqqBr; 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 d17si12983052ejw.435.2021.02.08.14.55.42; Mon, 08 Feb 2021 14:56:19 -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=gIVjqqBr; 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 S232132AbhBHQGa (ORCPT + 99 others); Mon, 8 Feb 2021 11:06:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:55764 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233161AbhBHPKt (ORCPT ); Mon, 8 Feb 2021 10:10:49 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id BB56464E8A; Mon, 8 Feb 2021 15:07:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612796857; bh=K1gzxVXqGoGNDBjPE883pZK+9sakuF76mYnc/0In93U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gIVjqqBrsiwhvYvf6l2XZL1A5qwjMntk1SHHeRyE8wS31cOTGO+LH6496MbNredJO 4rXI/0M4V5TqvWOAHuPFPycYMmv/8iXlzHMSIB3EC8sNIcPTh9rH3N/l5035LiYpLw ihJDhrEk9J10+L9YKeOEsoSRquFrs2xxj1M+ofXQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gerhard Klostermeier , Heiko Stuebner Subject: [PATCH 4.19 14/38] usb: dwc2: Fix endpoint direction check in ep_from_windex Date: Mon, 8 Feb 2021 16:01:01 +0100 Message-Id: <20210208145806.700903899@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208145806.141056364@linuxfoundation.org> References: <20210208145806.141056364@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 @@ -1453,7 +1453,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; @@ -1463,12 +1462,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); } /**