forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check user page table entries at the time they are added and removed. Allows to synchronously catch memory corruption issues related to double mapping. When a pte for an anonymous page is added into page table, we verify that this pte does not already point to a file backed page, and vice versa if this is a file backed page that is being added we verify that this page does not have an anonymous mapping We also enforce that read-only sharing for anonymous pages is allowed (i.e. cow after fork). All other sharing must be for file pages. Page table check allows to protect and debug cases where "struct page" metadata became corrupted for some reason. For example, when refcnt or mapcount become invalid. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Pasha Tatashin <[email protected]> Cc: Aneesh Kumar K.V <[email protected]> Cc: Dave Hansen <[email protected]> Cc: David Rientjes <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Greg Thelen <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Slaby <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Kees Cook <[email protected]> Cc: Masahiro Yamada <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Muchun Song <[email protected]> Cc: Paul Turner <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Sami Tolvanen <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Wei Xu <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
- Loading branch information
Showing
10 changed files
with
519 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
.. SPDX-License-Identifier: GPL-2.0 | ||
.. _page_table_check: | ||
|
||
================ | ||
Page Table Check | ||
================ | ||
|
||
Introduction | ||
============ | ||
|
||
Page table check allows to hardern the kernel by ensuring that some types of | ||
the memory corruptions are prevented. | ||
|
||
Page table check performs extra verifications at the time when new pages become | ||
accessible from the userspace by getting their page table entries (PTEs PMDs | ||
etc.) added into the table. | ||
|
||
In case of detected corruption, the kernel is crashed. There is a small | ||
performance and memory overhead associated with the page table check. Therefore, | ||
it is disabled by default, but can be optionally enabled on systems where the | ||
extra hardening outweighs the performance costs. Also, because page table check | ||
is synchronous, it can help with debugging double map memory corruption issues, | ||
by crashing kernel at the time wrong mapping occurs instead of later which is | ||
often the case with memory corruptions bugs. | ||
|
||
Double mapping detection logic | ||
============================== | ||
|
||
+-------------------+-------------------+-------------------+------------------+ | ||
| Current Mapping | New mapping | Permissions | Rule | | ||
+===================+===================+===================+==================+ | ||
| Anonymous | Anonymous | Read | Allow | | ||
+-------------------+-------------------+-------------------+------------------+ | ||
| Anonymous | Anonymous | Read / Write | Prohibit | | ||
+-------------------+-------------------+-------------------+------------------+ | ||
| Anonymous | Named | Any | Prohibit | | ||
+-------------------+-------------------+-------------------+------------------+ | ||
| Named | Anonymous | Any | Prohibit | | ||
+-------------------+-------------------+-------------------+------------------+ | ||
| Named | Named | Any | Allow | | ||
+-------------------+-------------------+-------------------+------------------+ | ||
|
||
Enabling Page Table Check | ||
========================= | ||
|
||
Build kernel with: | ||
|
||
- PAGE_TABLE_CHECK=y | ||
Note, it can only be enabled on platforms where ARCH_SUPPORTS_PAGE_TABLE_CHECK | ||
is available. | ||
|
||
- Boot with 'page_table_check=on' kernel parameter. | ||
|
||
Optionally, build kernel with PAGE_TABLE_CHECK_ENFORCED in order to have page | ||
table support without extra kernel parameter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14387,6 +14387,15 @@ F: include/net/page_pool.h | |
F: include/trace/events/page_pool.h | ||
F: net/core/page_pool.c | ||
|
||
PAGE TABLE CHECK | ||
M: Pasha Tatashin <[email protected]> | ||
M: Andrew Morton <[email protected]> | ||
L: [email protected] | ||
S: Maintained | ||
F: Documentation/vm/page_table_check.rst | ||
F: include/linux/page_table_check.h | ||
F: mm/page_table_check.c | ||
|
||
PANASONIC LAPTOP ACPI EXTRAS DRIVER | ||
M: Kenneth Chan <[email protected]> | ||
L: [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
|
||
/* | ||
* Copyright (c) 2021, Google LLC. | ||
* Pasha Tatashin <[email protected]> | ||
*/ | ||
#ifndef __LINUX_PAGE_TABLE_CHECK_H | ||
#define __LINUX_PAGE_TABLE_CHECK_H | ||
|
||
#ifdef CONFIG_PAGE_TABLE_CHECK | ||
#include <linux/jump_label.h> | ||
|
||
extern struct static_key_true page_table_check_disabled; | ||
extern struct page_ext_operations page_table_check_ops; | ||
|
||
void __page_table_check_zero(struct page *page, unsigned int order); | ||
void __page_table_check_pte_clear(struct mm_struct *mm, unsigned long addr, | ||
pte_t pte); | ||
void __page_table_check_pmd_clear(struct mm_struct *mm, unsigned long addr, | ||
pmd_t pmd); | ||
void __page_table_check_pud_clear(struct mm_struct *mm, unsigned long addr, | ||
pud_t pud); | ||
void __page_table_check_pte_set(struct mm_struct *mm, unsigned long addr, | ||
pte_t *ptep, pte_t pte); | ||
void __page_table_check_pmd_set(struct mm_struct *mm, unsigned long addr, | ||
pmd_t *pmdp, pmd_t pmd); | ||
void __page_table_check_pud_set(struct mm_struct *mm, unsigned long addr, | ||
pud_t *pudp, pud_t pud); | ||
|
||
static inline void page_table_check_alloc(struct page *page, unsigned int order) | ||
{ | ||
if (static_branch_likely(&page_table_check_disabled)) | ||
return; | ||
|
||
__page_table_check_zero(page, order); | ||
} | ||
|
||
static inline void page_table_check_free(struct page *page, unsigned int order) | ||
{ | ||
if (static_branch_likely(&page_table_check_disabled)) | ||
return; | ||
|
||
__page_table_check_zero(page, order); | ||
} | ||
|
||
static inline void page_table_check_pte_clear(struct mm_struct *mm, | ||
unsigned long addr, pte_t pte) | ||
{ | ||
if (static_branch_likely(&page_table_check_disabled)) | ||
return; | ||
|
||
__page_table_check_pte_clear(mm, addr, pte); | ||
} | ||
|
||
static inline void page_table_check_pmd_clear(struct mm_struct *mm, | ||
unsigned long addr, pmd_t pmd) | ||
{ | ||
if (static_branch_likely(&page_table_check_disabled)) | ||
return; | ||
|
||
__page_table_check_pmd_clear(mm, addr, pmd); | ||
} | ||
|
||
static inline void page_table_check_pud_clear(struct mm_struct *mm, | ||
unsigned long addr, pud_t pud) | ||
{ | ||
if (static_branch_likely(&page_table_check_disabled)) | ||
return; | ||
|
||
__page_table_check_pud_clear(mm, addr, pud); | ||
} | ||
|
||
static inline void page_table_check_pte_set(struct mm_struct *mm, | ||
unsigned long addr, pte_t *ptep, | ||
pte_t pte) | ||
{ | ||
if (static_branch_likely(&page_table_check_disabled)) | ||
return; | ||
|
||
__page_table_check_pte_set(mm, addr, ptep, pte); | ||
} | ||
|
||
static inline void page_table_check_pmd_set(struct mm_struct *mm, | ||
unsigned long addr, pmd_t *pmdp, | ||
pmd_t pmd) | ||
{ | ||
if (static_branch_likely(&page_table_check_disabled)) | ||
return; | ||
|
||
__page_table_check_pmd_set(mm, addr, pmdp, pmd); | ||
} | ||
|
||
static inline void page_table_check_pud_set(struct mm_struct *mm, | ||
unsigned long addr, pud_t *pudp, | ||
pud_t pud) | ||
{ | ||
if (static_branch_likely(&page_table_check_disabled)) | ||
return; | ||
|
||
__page_table_check_pud_set(mm, addr, pudp, pud); | ||
} | ||
|
||
#else | ||
|
||
static inline void page_table_check_alloc(struct page *page, unsigned int order) | ||
{ | ||
} | ||
|
||
static inline void page_table_check_free(struct page *page, unsigned int order) | ||
{ | ||
} | ||
|
||
static inline void page_table_check_pte_clear(struct mm_struct *mm, | ||
unsigned long addr, pte_t pte) | ||
{ | ||
} | ||
|
||
static inline void page_table_check_pmd_clear(struct mm_struct *mm, | ||
unsigned long addr, pmd_t pmd) | ||
{ | ||
} | ||
|
||
static inline void page_table_check_pud_clear(struct mm_struct *mm, | ||
unsigned long addr, pud_t pud) | ||
{ | ||
} | ||
|
||
static inline void page_table_check_pte_set(struct mm_struct *mm, | ||
unsigned long addr, pte_t *ptep, | ||
pte_t pte) | ||
{ | ||
} | ||
|
||
static inline void page_table_check_pmd_set(struct mm_struct *mm, | ||
unsigned long addr, pmd_t *pmdp, | ||
pmd_t pmd) | ||
{ | ||
} | ||
|
||
static inline void page_table_check_pud_set(struct mm_struct *mm, | ||
unsigned long addr, pud_t *pudp, | ||
pud_t pud) | ||
{ | ||
} | ||
|
||
#endif /* CONFIG_PAGE_TABLE_CHECK */ | ||
#endif /* __LINUX_PAGE_TABLE_CHECK_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.