Skip to content

Commit 0aae825

Browse files
ardbiesheuvelwilldeacon
authored andcommitted
mm: Make empty_zero_page[] const
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>
1 parent 99bad3e commit 0aae825

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

include/linux/pgtable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,7 @@ static inline unsigned long zero_pfn(unsigned long addr)
19931993
return zero_page_pfn;
19941994
}
19951995

1996-
extern uint8_t empty_zero_page[PAGE_SIZE];
1996+
extern const uint8_t empty_zero_page[PAGE_SIZE];
19971997
extern struct page *__zero_page;
19981998

19991999
static inline struct page *_zero_page(unsigned long addr)

mm/mm_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ unsigned long zero_page_pfn __ro_after_init;
5757
EXPORT_SYMBOL(zero_page_pfn);
5858

5959
#ifndef __HAVE_COLOR_ZERO_PAGE
60-
uint8_t empty_zero_page[PAGE_SIZE] __page_aligned_bss;
60+
const uint8_t empty_zero_page[PAGE_SIZE] __aligned(PAGE_SIZE);
6161
EXPORT_SYMBOL(empty_zero_page);
6262

6363
struct page *__zero_page __ro_after_init;

0 commit comments

Comments
 (0)