]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm: Make empty_zero_page[] const
authorArd Biesheuvel <ardb@kernel.org>
Fri, 29 May 2026 15:02:04 +0000 (17:02 +0200)
committerWill Deacon <will@kernel.org>
Tue, 2 Jun 2026 15:29:16 +0000 (16:29 +0100)
The empty zero page is used to back any kernel or user space mapping
that is supposed to remain cleared, and so the page itself is never
supposed to be modified.

So mark it as const, which moves it into .rodata rather than .bss: on
most architectures, this ensures that both the kernel's mapping of it
and any aliases that are accessible via the kernel direct (linear) map
are mapped read-only, and cannot be used (inadvertently or maliciously)
to corrupt the contents of the zero page.

Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed-by: Kevin Brodsky <kevin.brodsky@arm.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Jann Horn <jannh@google.com>
Reviewed-by: Feng Tang <feng.tang@linux.alibaba.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Will Deacon <will@kernel.org>
include/linux/pgtable.h
mm/mm_init.c

index cdd68ed3ae1a90bea6696bf5e06bc422e9293e5e..67aa23814010833c5a3fdf45ccfedf2be21c5a84 100644 (file)
@@ -1993,7 +1993,7 @@ static inline unsigned long zero_pfn(unsigned long addr)
        return zero_page_pfn;
 }
 
-extern uint8_t empty_zero_page[PAGE_SIZE];
+extern const uint8_t empty_zero_page[PAGE_SIZE];
 extern struct page *__zero_page;
 
 static inline struct page *_zero_page(unsigned long addr)
index f9f8e1af921cda91d812cffdad2f1a0698cfd6ac..46cf001238c5bb88da62f08c109eb1815ef3043e 100644 (file)
@@ -57,7 +57,7 @@ unsigned long zero_page_pfn __ro_after_init;
 EXPORT_SYMBOL(zero_page_pfn);
 
 #ifndef __HAVE_COLOR_ZERO_PAGE
-uint8_t empty_zero_page[PAGE_SIZE] __page_aligned_bss;
+const uint8_t empty_zero_page[PAGE_SIZE] __aligned(PAGE_SIZE);
 EXPORT_SYMBOL(empty_zero_page);
 
 struct page *__zero_page __ro_after_init;