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: 65555 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2458578wrd; Tue, 7 Mar 2023 06:24:26 -0800 (PST) X-Google-Smtp-Source: AK7set9e1cuaVNpxpjGuH+OmJ69g/tCXfj9LG2As5iSQdrjZhLaOxZxj4m3WrIIe8wOCrL/QGvVL X-Received: by 2002:a17:90b:1c87:b0:236:73d5:82cf with SMTP id oo7-20020a17090b1c8700b0023673d582cfmr15039536pjb.9.1678199066339; Tue, 07 Mar 2023 06:24:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678199066; cv=none; d=google.com; s=arc-20160816; b=agdAkdLc51493aEzWI1AQlduxmQGGe04sbBWB7DKYn1WvLcNl3LYHygRjtjfo4VBDA 8gzyCUAbWrDH/UUo8LopO5y/B5mBSzmWetf8duuW0DGGqsv/TM8Ty1W8kCO3QSAUyDoB uPYIW6inMYNS6g5oRiZDVk2FK6gfqzg4REHVVJY4cqJd8rHpp+sDJuUZLzRk8zkRcarN IxHN6axy/njvLWRKmeUjfS+UEN+FT7Mv9qrabN5a9mF06wAiDUAb5A6ZYgCKhJ12F93i up8BHrNDbceqHsY0FS3NxgX9QnyaEDm7/NQwp63+tT6zg2twSS2LaBDKk9dl6dMAzNu6 d4GA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NbpaTuQs4+xjFf9xqRrxTj/YVD0PNYLrhyNUbn8x+hI=; b=ViiClnox+p30tAPEZLMmNO6JW2QodA+bZy/UsQ6YzhN/RGEMfDekvbj831MhSlXiNP GGa+Jexp8Uh47qh8hI7lFZgebpbQojhLyOrog1yYjUf0DgJ4rFgt1HBeVnQMfN+Jgm0q 9/ZQ065HSqUTTx2zCrK7lU8ykQfA6HQphi3fDfIIgRdUfHSiXrkuuJRQ30VjyZ4cQSC6 RQ7SmPXB3vR5Y/ZOKUdv3RPFYcV4C9fFS6xV0b/23JgPhUwK9UN8FxpUzw/VME25h8H8 w2DL4/39xjU7ANC4dlYmp4aKflQDuZtg709FjzXypnI3U6b+rXUz9/bEhZIhWA+pE0nh WU1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tHi6giKR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d18-20020a630e12000000b004fb96b91c57si11760793pgl.125.2023.03.07.06.24.13; Tue, 07 Mar 2023 06:24:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tHi6giKR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231455AbjCGONm (ORCPT + 99 others); Tue, 7 Mar 2023 09:13:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231420AbjCGOND (ORCPT ); Tue, 7 Mar 2023 09:13:03 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56F527E895 for ; Tue, 7 Mar 2023 06:09:34 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id 282C1B818F9 for ; Tue, 7 Mar 2023 14:08:47 +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-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759719264433241839?= X-GMAIL-MSGID: =?utf-8?q?1759719264433241839?= 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;