From patchwork Sat Jun 22 09:56:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ma Ke X-Patchwork-Id: 13708265 Received: from cstnet.cn (smtp84.cstnet.cn [159.226.251.84]) (using TLSv1.2 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25A10818; Sat, 22 Jun 2024 09:56:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.226.251.84 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719050208; cv=none; b=auOQsiPNzXFCfe5vMGu/pZP0bQ5Du2vSlL+ClcU0kcCIysPvMo0YelCZZt0q/fQ4hDLLsEIP/AkuS9TSFWN6jTBTnKRgfLMdVIxQJyRAZlrnJ5VCZZtV1iSTbMXXzqKvk20DlbHwPGRLILKOetNxJuZPT7iHpiPDDfR4tff6NQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719050208; c=relaxed/simple; bh=PXvZUv63wE+rNiBZe+zRYXmlyGWiebS3Xnu/l4ljR2w=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=NdcXAl07mirMs4N6IjwFiFV6yLWK/XRWzKCXfj6q+THNyPbGwIpoVzKIndvLNY2rnesn6s02wjLRjV5JMCyWp/Cd15KbqrHowuXIT8gNls5f2drgKUTmtU/7LF3NhmCLdjf445xXz10bVVYraOsl5C10mB2lynEOtVs/Z+QNiK4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn; spf=pass smtp.mailfrom=iscas.ac.cn; arc=none smtp.client-ip=159.226.251.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iscas.ac.cn Received: from icess-ProLiant-DL380-Gen10.. (unknown [183.174.60.14]) by APP-05 (Coremail) with SMTP id zQCowADXfRDDn3ZmYecdEg--.42420S2; Sat, 22 Jun 2024 17:56:30 +0800 (CST) From: Ma Ke To: neal_liu@aspeedtech.com, gregkh@linuxfoundation.org, joel@jms.id.au, andrew@codeconstruct.com.au Cc: linux-aspeed@lists.ozlabs.org, linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Ma Ke Subject: [PATCH] usb: gadget: aspeed_udc: validate endpoint index for ast udc Date: Sat, 22 Jun 2024 17:56:18 +0800 Message-Id: <20240622095618.1890093-1-make24@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: zQCowADXfRDDn3ZmYecdEg--.42420S2 X-Coremail-Antispam: 1UD129KBjvdXoWrur1rtFyrCw4kCr4rWw45ZFb_yoW3WFcE93 WUuF4fWr17W3yqqr1UZa4fCryj9a4ku3WkuFnFyryavFyUWa4xJ34UWFWkAa15uF47uF9x A3yDK34ak34SgjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUb4AFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6r106r1rM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr0_ Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AKxVW8Jr 0_Cr1UM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVAC Y4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJV W8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI2 0VAGYxC7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrV AFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCI c40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267 AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_ Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbHa0D UUUUU== X-CM-SenderInfo: ppdnvj2u6l2u1dvotugofq/ We should verify the bound of the array to assure that host may not manipulate the index to point past endpoint array. Signed-off-by: Ma Ke --- drivers/usb/gadget/udc/aspeed_udc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/gadget/udc/aspeed_udc.c b/drivers/usb/gadget/udc/aspeed_udc.c index 3916c8e2ba01..95060592c231 100644 --- a/drivers/usb/gadget/udc/aspeed_udc.c +++ b/drivers/usb/gadget/udc/aspeed_udc.c @@ -1009,6 +1009,8 @@ static void ast_udc_getstatus(struct ast_udc_dev *udc) break; case USB_RECIP_ENDPOINT: epnum = crq.wIndex & USB_ENDPOINT_NUMBER_MASK; + if (epnum >= USB_MAX_ENDPOINTS) + goto stall; status = udc->ep[epnum].stopped; break; default: