From patchwork Thu Oct 10 14:47:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Zengkai X-Patchwork-Id: 13830276 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 51680CF11F5 for ; Thu, 10 Oct 2024 14:14:59 +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-Type: Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=I9cml9n2aVszt68ZSPeaAFyimrOmH+GIpm1PxghuIgY=; b=ULf1Hj9RIHIrGkgJ1RS2ea3r8N xcUN9U3lptIBzO2iYtbKz0s1B3F2s+krzGDlm/Tg3UrCGrOJP+w26UXaSv8XKwnLLi9iQNmqHgGbt OXBKnwAVaDVztGCMTsY/lDTsO/SzB1pT99kEEUog++2yzPzoSw5nXUa9culkNfW7MHVxRbf4u+rCJ OO/63rcbUpsOFm7BDLn+oBP83f6yobcrsHtUF1k5t/UhzIWYY76Kj0NTzyGhlk6RQUUZZ5Oo0kPDA n7WC19reK+xv4qNdBxBDsV0E0AEHN4pbl6RW5hkdDBPTPlkus2nEgcg6sYneqbZUhoRNAX0qWaJ9W mHQc4vgA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sytwC-0000000D3QH-1bKa; Thu, 10 Oct 2024 14:14:44 +0000 Received: from szxga05-in.huawei.com ([45.249.212.191]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sytuo-0000000D39a-2Hi2 for linux-arm-kernel@lists.infradead.org; Thu, 10 Oct 2024 14:13:20 +0000 Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4XPWsj3RVDz1j9ND; Thu, 10 Oct 2024 22:12:09 +0800 (CST) Received: from kwepemd200010.china.huawei.com (unknown [7.221.188.124]) by mail.maildlp.com (Postfix) with ESMTPS id 04708140120; Thu, 10 Oct 2024 22:13:16 +0800 (CST) Received: from huawei.com (10.175.113.25) by kwepemd200010.china.huawei.com (7.221.188.124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Thu, 10 Oct 2024 22:13:14 +0800 From: Zheng Zengkai To: , , , , , , CC: , , , , , Subject: [PATCH] ACPI: GTDT: Tighten the check for the first platform timer entry Date: Thu, 10 Oct 2024 22:47:03 +0800 Message-ID: <20241010144703.113728-1-zhengzengkai@huawei.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemd200010.china.huawei.com (7.221.188.124) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241010_071319_448633_A940B310 X-CRM114-Status: GOOD ( 10.90 ) 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 As suggested by Marc and Lorenzo, first we need to check whether the platform_timer pointer is within gtdt bounds (< gtdt_end) before de-referencing what it points at to detect the (first) platform timer entry length and check that next platform_timer pointer is within gtdt_end too. Now we do that only in next_platform_timer() for subsequent platform timers. So add check against table length (gtdt_end) for the first platform timer entry. Suggested-by: Marc Zyngier Suggested-by: Lorenzo Pieralisi Signed-off-by: Zheng Zengkai --- drivers/acpi/arm64/gtdt.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/arm64/gtdt.c b/drivers/acpi/arm64/gtdt.c index c0e77c1c8e09..f249af1ed1cd 100644 --- a/drivers/acpi/arm64/gtdt.c +++ b/drivers/acpi/arm64/gtdt.c @@ -177,7 +177,8 @@ int __init acpi_gtdt_init(struct acpi_table_header *table, } platform_timer = (void *)gtdt + gtdt->platform_timer_offset; - if (platform_timer < (void *)table + sizeof(struct acpi_table_gtdt)) { + if (platform_timer < (void *)table + sizeof(struct acpi_table_gtdt) || + platform_timer >= acpi_gtdt_desc.gtdt_end) { pr_err(FW_BUG "invalid timer data.\n"); return -EINVAL; }