From patchwork Tue Jun 25 02:23:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ma Ke X-Patchwork-Id: 13710455 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DCA83C2BD09 for ; Tue, 25 Jun 2024 02:23:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=EXXFCRLOrPsaJKD88jqAUyZSbDRErDk5jKHdZwQtFpA=; b=VPe7PJxmxhzE3AhPFMx1/iTR8U KMlqUlvxNeQ7p+jKX+3KjDTKbAZudEQQRx8j4Z/VC6TTLLsPWCVFM1kRRRnej9Nb4MEaFo13tAsO5 A/8cmtiBxF7gIlnx3AYpBJq8MP2Wa9bGKe2G/KizexKOiLDpYhn/seAk0yINyxQzCKuiI6tRQWkvw pvFdOIUlBqsSYUtE+mIkJLlrhCXYPxnL30nc+q0ZJ0UosTp47ejxiheAed1tIQrTLPm/MCY2U10dI 7w1JJAxD6Zfjy3lFC1RgJ1gpKHX+xI1VDfcK4RDErRanYjGMxYr0QaAP9aPV6OyZOMM0DY7ZHpbgm ZJD5/pBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLvqA-00000001Jov-4BWy; Tue, 25 Jun 2024 02:23:27 +0000 Received: from smtp21.cstnet.cn ([159.226.251.21] helo=cstnet.cn) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLvq3-00000001JoA-351p for linux-arm-kernel@lists.infradead.org; Tue, 25 Jun 2024 02:23:22 +0000 Received: from icess-ProLiant-DL380-Gen10.. (unknown [183.174.60.14]) by APP-01 (Coremail) with SMTP id qwCowAC3vhIMKnpmXuiVDA--.13743S2; Tue, 25 Jun 2024 10:23:10 +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 v4] usb: gadget: aspeed_udc: validate endpoint index for ast udc Date: Tue, 25 Jun 2024 10:23:06 +0800 Message-Id: <20240625022306.2568122-1-make24@iscas.ac.cn> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: qwCowAC3vhIMKnpmXuiVDA--.13743S2 X-Coremail-Antispam: 1UD129KBjvdXoWruFy7urW5GFW7Kr4rtF1DWrg_yoWDKFXE9a 48ursxuw17KayI9r1UZ3W3Xr1j9a4kW3WDuF1DtFyay34UXF47XrykWrW8ta15ZFW7uF9x C398Kw13u34aqjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbx8FF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6r1F6r1fM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_ Gr1UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr 1j6F4UJwAac4AC62xK8xCEY4vEwIxC4wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40E FcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUGVWUXwAv7VC2z280aVAFwI0_Jr 0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8v x2IErcIFxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F4 0E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFyl IxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxV AFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j 6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUAku cUUUUU= X-Originating-IP: [183.174.60.14] X-CM-SenderInfo: ppdnvj2u6l2u1dvotugofq/ X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240624_192320_194313_BCD52B67 X-CRM114-Status: UNSURE ( 9.73 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org We should verify the bound of the array to assure that host may not manipulate the index to point past endpoint array. Found by static analysis. Signed-off-by: Ma Ke Reviewed-by: Andrew Jeffery --- Changes in v4: - used a consistent email address to send patches, sorry for my negligence. Changes in v3: - added the changelog as suggested. Changes in v2: - used the correct macro-defined constants as suggested; - explained the method for finding and testing vulnerabilities. --- 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..d972ef4644bc 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 >= AST_UDC_NUM_ENDPOINTS) + goto stall; status = udc->ep[epnum].stopped; break; default: