From mboxrd@z Thu Jan 1 00:00:00 1970 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 8AA90C5DF87 for ; Fri, 21 Aug 2026 13:20:46 +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: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ooAB9M49vill49JDOySEDWJc1n48k7rZxgRPawA1in0=; b=CBJRIeMz9hBk+xAujkXcDMURW7 gbVkuUeJZtuvvEbpJ/Ag/gmP6KjUuO069w+u5G3EJdEv0rYvXBiXIpptVtfTE9rb8J7TGg3su5xCx RzhzvuINeFw3tA0pdEXrUWtztnLxEXqIJ2PchLTjixdO5FbrWkqbwgtpJYfQZ62OsOiP3/bTg63ZI Lag8CPL/9j6AbuYO5rXkYqKKlT33/Ex1MEDpoMwcUcIIWEzP2l0bTCqf9xEt7Glnx3Z6x3FYRTzyY mV1fT1TLa0cYZxbODjeQYDQ+IBuBFCU1K9yoYpppR56gdzsRlt+UrZl3q2VabJfUpowukK3BYBVrP wway1fHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wxPAg-0000000DO45-2Ecz; Fri, 21 Aug 2026 13:20:34 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wxPAe-0000000DO3S-07kH for linux-arm-kernel@lists.infradead.org; Fri, 21 Aug 2026 13:20:33 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 08CDD1476; Fri, 21 Aug 2026 06:20:25 -0700 (PDT) Received: from [10.43.18.12] (unknown [10.43.18.12]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 662123F763; Fri, 21 Aug 2026 06:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1787318428; bh=2OeUaNMPu+bZ4hOVGmb2LFwuUA0hs71atyCF4/CFKQw=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=hza4DkujC7/DIpSTKMt+tG/p7p5i5Klwn99TIX85W/13RztKsk6CbPkZDhFuXn017 hcSu/fYfsj7Gc6azfpkOns3TY3W1mtn8qwSb7ne4tE2LCezmbSJMAyNwVXUaMh0zfk t5HJeljpPTNDNGSe3MZKxoGw50Hw+Aq1XIbFdj8k= Message-ID: <5a3b89a6-bc42-42c3-82e8-25d6f1a2c5d2@arm.com> Date: Fri, 21 Aug 2026 15:20:21 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH] arm64: mm: Map fixmap PTE tables r/o in the linear map To: Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Cc: will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, Ard Biesheuvel , Ryan Roberts , Anshuman Khandual , Liz Prucka , Seth Jenkins , Kees Cook , Jann Horn , linux-hardening@vger.kernel.org References: <20260805104042.1107678-2-ardb+git@google.com> From: Kevin Brodsky Content-Language: en-GB In-Reply-To: <20260805104042.1107678-2-ardb+git@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260821_062032_150325_4676021D X-CRM114-Status: GOOD ( 24.74 ) 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 On 05/08/2026 12:40, Ard Biesheuvel wrote: > From: Ard Biesheuvel > > Without physical KASLR, the fixmap page tables will appear at an a > priori known offset in the physical address space, and due to the lack > of randomization, the linear map carries a writeable alias of the fixmap > PTE pages, which appears at an offset in the kernel VA space that is > also predictable. > > Given that the placement of the fixmap area is never randomized either, > a single store to this linear alias region is sufficient to map any > physical page with any permissions at a known offset in the kernel VA > space, including on top of the PTI trampoline. > > Avoid this, by remapping the fixmap PTE pages read-only in the linear > map. Sounds good, logical next step after unmapping the rest of data/BSS from the linear map :) > This is possible because all updates to bm_pte[] occur via the > mapping of the kernel image in the vmap area. A read-only mapping is > still needed for things like ptdump that walk the page tables. > > Cc: Ryan Roberts > Cc: Anshuman Khandual > Cc: Kevin Brodsky > Cc: Liz Prucka > Cc: Seth Jenkins > Cc: Kees Cook > Cc: Jann Horn > Cc: linux-hardening@vger.kernel.org > Signed-off-by: Ard Biesheuvel > --- > arch/arm64/include/asm/set_memory.h | 2 ++ > arch/arm64/mm/fixmap.c | 7 +++++++ > arch/arm64/mm/pageattr.c | 10 ++++++++++ > 3 files changed, 19 insertions(+) > > diff --git a/arch/arm64/include/asm/set_memory.h b/arch/arm64/include/asm/set_memory.h > index 90f61b17275e..a685fb534c3e 100644 > --- a/arch/arm64/include/asm/set_memory.h > +++ b/arch/arm64/include/asm/set_memory.h > @@ -11,6 +11,8 @@ bool can_set_direct_map(void); > > int set_memory_valid(unsigned long addr, int numpages, int enable); > > +int set_direct_map_ro(unsigned long addr, int numpages); > + > int set_direct_map_invalid_noflush(struct page *page); > int set_direct_map_default_noflush(struct page *page); > int set_direct_map_valid_noflush(struct page *page, unsigned nr, bool valid); > diff --git a/arch/arm64/mm/fixmap.c b/arch/arm64/mm/fixmap.c > index f66a0016dd02..fcb571dffe82 100644 > --- a/arch/arm64/mm/fixmap.c > +++ b/arch/arm64/mm/fixmap.c > @@ -14,6 +14,7 @@ > #include > #include > #include > +#include > #include > > /* ensure that the fixmap region does not grow down into the PCI I/O region */ > @@ -173,3 +174,9 @@ void *__init fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot) > > return dt_virt; > } > + > +static int __init fixmap_remap_ro(void) > +{ > + return set_direct_map_ro((unsigned long)lm_alias(&bm_pte), NR_BM_PTE_TABLES); Should we not also remap bm_pmd and bm_pud? For that matter, do we need RW access via the linear map for any page annotated with __bss_pgtbl? I suppose that might be the case for kasan_early_shadow_* but I don't know enough about KASAN to tell for sure. > +} > +late_initcall(fixmap_remap_ro); Is mark_rodata_ro() definitely too early to remap these pages RO? - Kevin > diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c > index bbe98ac9ad8c..5072b14d4f9d 100644 > --- a/arch/arm64/mm/pageattr.c > +++ b/arch/arm64/mm/pageattr.c > @@ -251,6 +251,16 @@ int set_memory_valid(unsigned long addr, int numpages, int enable) > __pgprot(PTE_PRESENT_VALID_KERNEL)); > } > > +int set_direct_map_ro(unsigned long addr, int numpages) > +{ > + if (!can_set_direct_map()) > + return 0; > + > + return __change_memory_common(addr, PAGE_SIZE * numpages, > + __pgprot(PTE_RDONLY), > + __pgprot(PTE_WRITE)); > +} > + > int set_direct_map_invalid_noflush(struct page *page) > { > pgprot_t clear_mask = __pgprot(PTE_PRESENT_VALID_KERNEL);