From patchwork Tue Mar 7 14:05:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13163870 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 43896C678D4 for ; Tue, 7 Mar 2023 14:53:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: 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: List-Owner; bh=rGhA8XwNKTU0tRntgCKcfREXqHNewodJucZJLWHc17U=; b=GtVHHO5EKcYT+K 2KdHeJ3KJLQA1rptwtTnP0C8AbLvijND/Djox7gesmAdakMW96pnRM3/1YMy1kLakqY3g4HnhgeaV W2tK+q/Bjt5uQ6HcTmmqTYEWkHpgHpSHJB/9OAIhL46VxRBIlRo1irPebpnxbsdqESweS63lsKWwr 7ksFPBPWMv/5yOBzlaPhCG6HI1Nez4AHcI6npBK1BT6ozlqhBivtO0w5sDcWIEbnWmnH/hwdZDj4A ViBmiTHElL/gTUeitWcgvfgOeREIS6Qyn6A2YMqgQpn3OySbrtF0K73Usj62sB5oN2BMeqWRqTADr dFojG5yYCqC17Q2ww82Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZYgK-000yif-IL; Tue, 07 Mar 2023 14:52:48 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZXzi-000evg-Vz for linux-arm-kernel@lists.infradead.org; Tue, 07 Mar 2023 14:08:48 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7FF0B6144B; Tue, 7 Mar 2023 14:08:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE89AC433D2; Tue, 7 Mar 2023 14:08:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678198125; bh=RiTy0vYA92racswYmJC1M4uj15gXwTRNr7hKOo4kKIg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tHi6giKRrBTBP69pl5D/Ze+suO+NTYUMuAAkvqG+E3EbEgSNRY/WwDhaWs2uKPUnZ oQQU1KFNMBUIPklIVCIfsZB23Adk9umPOVHqVb1hThs/suZ0BVi79cjcZMQsVMYDT5 CA2mZe4OxqRdzMOvM6iA2/g12i1TedUc+jgOZ0UB+LZN4061JpXJmqFsf5uFNxj3z0 1R+DQHfJOofRBRr5+MQvPBSKJh2Gmrzb9gLdXjyU+gmmLUEAFxK+Jrhq418+Z6dto2 UqRUsRLju7U+QD/O2WivTgxMbO+/75sfHkQvd+6ZlPxFvrGibbl9ezNpPnCsL37G0p pjG9zwq1jEHKw== From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Catalin Marinas , Will Deacon , Marc Zyngier , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook Subject: [PATCH v3 53/60] arm64: ptdump: Disregard unaddressable VA space Date: Tue, 7 Mar 2023 15:05:15 +0100 Message-Id: <20230307140522.2311461-54-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307140522.2311461-1-ardb@kernel.org> References: <20230307140522.2311461-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2007; i=ardb@kernel.org; h=from:subject; bh=RiTy0vYA92racswYmJC1M4uj15gXwTRNr7hKOo4kKIg=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIYXdpfsPQ7PLPGfjNrOZH1MdPO5I7ODnu/6iolxCYGrTm woL1+0dpSwMYhwMsmKKLAKz/77beXqiVK3zLFmYOaxMIEMYuDgFYCKb3BgZFtkJLsjQfO3/sduE /xnjqQOc9+Nfz2xfY+J0ruU/w1Phewz/ffe3H7eZc+7Qe/36jy97S785Moq7va2vv78787Pob8Z b/AA= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230307_060847_147613_35F1C111 X-CRM114-Status: GOOD ( 17.36 ) 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 Configurations built with support for 52-bit virtual addressing can also run on CPUs that only support 48 bits of VA space, in which case only that part of swapper_pg_dir that represents the 48-bit addressable region is relevant, and everything else is ignored by the hardware. Our software pagetable walker has little in the way of input address validation, and so it will happily start a walk from an address that is not representable by the number of paging levels that are actually active, resulting in lots of bogus output from the page table dumper unless we take care to start at a valid address. Signed-off-by: Ard Biesheuvel --- arch/arm64/mm/ptdump.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 8f37d6d8b5216473..8aee5d25f3d8cbe6 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -345,7 +345,7 @@ static void __init ptdump_initialize(void) pg_level[i].mask |= pg_level[i].bits[j].mask; } -static struct ptdump_info kernel_ptdump_info = { +static struct ptdump_info kernel_ptdump_info __ro_after_init = { .mm = &init_mm, .markers = address_markers, .base_addr = PAGE_OFFSET, @@ -364,7 +364,7 @@ void ptdump_check_wx(void) .ptdump = { .note_page = note_page, .range = (struct ptdump_range[]) { - {PAGE_OFFSET, ~0UL}, + {_PAGE_OFFSET(vabits_actual), ~0UL}, {0, 0} } } @@ -388,8 +388,9 @@ static int __init ptdump_init(void) address_markers[VMALLOC_END_NR].start_address = VMALLOC_END; ptdump_initialize(); if (vabits_actual < VA_BITS) { + kernel_ptdump_info.base_addr = _PAGE_OFFSET(vabits_actual); address_markers[VMEMMAP_START_NR].start_address = - (unsigned long)virt_to_page(_PAGE_OFFSET(vabits_actual)); + (unsigned long)virt_to_page(kernel_ptdump_info.base_addr); } ptdump_debugfs_register(&kernel_ptdump_info, "kernel_page_tables"); return 0;