diff mbox series

[1/3] mm/page_table_check: Check writable zero page in page table check

Message ID 20220911095923.3614387-2-pasha.tatashin@soleen.com (mailing list archive)
State New
Headers show
Series page table check default to warn instead of panic | expand

Commit Message

Pasha Tatashin Sept. 11, 2022, 9:59 a.m. UTC
From: Rick Edgecombe <rick.p.edgecombe@intel.com>

The zero page should remain all zero, so that it can be mapped as
read-only for read faults of memory that should be zeroed. If it is ever
mapped writable to userspace, it could become non-zero and so other apps
would unexpectedly get non-zero data. So the zero page should never be
mapped writable to userspace. Check for this condition in
page_table_check_set().

Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
---
 mm/page_table_check.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Rick Edgecombe Sept. 12, 2022, 3:58 p.m. UTC | #1
On Sun, 2022-09-11 at 09:59 +0000, Pasha Tatashin wrote:
> From: Rick Edgecombe <rick.p.edgecombe@intel.com>
> 
> The zero page should remain all zero, so that it can be mapped as
> read-only for read faults of memory that should be zeroed. If it is
> ever
> mapped writable to userspace, it could become non-zero and so other
> apps
> would unexpectedly get non-zero data. So the zero page should never
> be
> mapped writable to userspace. Check for this condition in
> page_table_check_set().
> 
> Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
> ---
>  mm/page_table_check.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
Thanks. Should we put this at the end, in order to not add any more
BUG_ON()'s to the kernel? Or I can just send a follow up and add the
docs you asked for.
David Hildenbrand Sept. 26, 2022, 8:26 a.m. UTC | #2
On 11.09.22 11:59, Pasha Tatashin wrote:
> From: Rick Edgecombe <rick.p.edgecombe@intel.com>
> 
> The zero page should remain all zero, so that it can be mapped as
> read-only for read faults of memory that should be zeroed. If it is ever
> mapped writable to userspace, it could become non-zero and so other apps
> would unexpectedly get non-zero data. So the zero page should never be
> mapped writable to userspace. Check for this condition in
> page_table_check_set().
> 
> Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
> Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
> ---
>   mm/page_table_check.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/mm/page_table_check.c b/mm/page_table_check.c
> index e2062748791a..665ece0d55d4 100644
> --- a/mm/page_table_check.c
> +++ b/mm/page_table_check.c
> @@ -102,6 +102,8 @@ static void page_table_check_set(struct mm_struct *mm, unsigned long addr,
>   	if (!pfn_valid(pfn))
>   		return;
>   
> +	BUG_ON(is_zero_pfn(pfn) && rw);

We most probably don't want that:

https://lkml.kernel.org/r/20220923113426.52871-2-david@redhat.com
diff mbox series

Patch

diff --git a/mm/page_table_check.c b/mm/page_table_check.c
index e2062748791a..665ece0d55d4 100644
--- a/mm/page_table_check.c
+++ b/mm/page_table_check.c
@@ -102,6 +102,8 @@  static void page_table_check_set(struct mm_struct *mm, unsigned long addr,
 	if (!pfn_valid(pfn))
 		return;
 
+	BUG_ON(is_zero_pfn(pfn) && rw);
+
 	page = pfn_to_page(pfn);
 	page_ext = lookup_page_ext(page);
 	anon = PageAnon(page);