login
Header Space

 
 

Re: [git head] X86_PAT & mprotect

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Ingo Molnar <mingo@...>
Cc: Hugh Dickins <hugh@...>, Frans Pop <elendil@...>, Jesse Barnes <jesse.barnes@...>, <linux-kernel@...>, Packard, Keith <keith.packard@...>, Yinghai Lu <yhlu.kernel@...>, Andrew Morton <akpm@...>, Linus Torvalds <torvalds@...>, H. Peter Anvin <hpa@...>, Thomas Gleixner <tglx@...>, Nick Piggin <npiggin@...>, Jesse Barnes <jbarnes@...>
Date: Friday, May 9, 2008 - 4:09 pm

On Fri, May 09, 2008 at 01:05:19PM -0700, Venki Pallipadi wrote:

And the second patch for mprotect problem.


There is a defect in mprotect, which lets the user to change the page
cache type bits by-passing the kernel reserve_memtype and free_memtype
wrappers. Fix the problem by not letting mprotect change the PAT bits.

Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Hugh Dickins <hugh@veritas.com>

---
 include/asm-x86/pgtable.h |   16 +++++++++++++---
 mm/mprotect.c             |   11 ++++++++++-
 2 files changed, 23 insertions(+), 4 deletions(-)

Index: linux-2.6/mm/mprotect.c
===================================================================
--- linux-2.6.orig/mm/mprotect.c	2008-05-09 10:50:28.000000000 -0700
+++ linux-2.6/mm/mprotect.c	2008-05-09 11:01:23.000000000 -0700
@@ -26,6 +26,13 @@
 #include <asm/cacheflush.h>
 #include <asm/tlbflush.h>
 
+#ifndef pgprot_modify
+static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
+{
+	return newprot;
+}
+#endif
+
 static void change_pte_range(struct mm_struct *mm, pmd_t *pmd,
 		unsigned long addr, unsigned long end, pgprot_t newprot,
 		int dirty_accountable)
@@ -192,7 +199,9 @@ success:
 	 * held in write mode.
 	 */
 	vma->vm_flags = newflags;
-	vma->vm_page_prot = vm_get_page_prot(newflags);
+	vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
+					  vm_get_page_prot(newflags));
+
 	if (vma_wants_writenotify(vma)) {
 		vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
 		dirty_accountable = 1;
Index: linux-2.6/include/asm-x86/pgtable.h
===================================================================
--- linux-2.6.orig/include/asm-x86/pgtable.h	2008-05-09 10:50:28.000000000 -0700
+++ linux-2.6/include/asm-x86/pgtable.h	2008-05-09 11:01:23.000000000 -0700
@@ -57,7 +57,8 @@
 #define _KERNPG_TABLE	(_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED |	\
 			 _PAGE_DIRTY)
 
-#define _PAGE_CHG_MASK	(PTE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
+#define _PAGE_CHG_MASK	(PTE_MASK |_PAGE_PCD | _PAGE_PWT |		\
+			 _PAGE_ACCESSED | _PAGE_DIRTY)
 
 #define _PAGE_CACHE_MASK	(_PAGE_PCD | _PAGE_PWT)
 #define _PAGE_CACHE_WB		(0)
@@ -288,12 +289,21 @@ static inline pte_t pte_modify(pte_t pte
 	 * Chop off the NX bit (if present), and add the NX portion of
 	 * the newprot (if present):
 	 */
-	val &= _PAGE_CHG_MASK & ~_PAGE_NX;
-	val |= pgprot_val(newprot) & __supported_pte_mask;
+	val &= _PAGE_CHG_MASK;
+	val |= pgprot_val(newprot) & (~_PAGE_CHG_MASK) & __supported_pte_mask;
 
 	return __pte(val);
 }
 
+/* mprotect needs to preserve PAT bits when updating vm_page_prot */
+#define pgprot_modify pgprot_modify
+static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
+{
+	pgprotval_t preservebits = pgprot_val(oldprot) & _PAGE_CHG_MASK;
+	pgprotval_t addbits = pgprot_val(newprot);
+	return __pgprot(preservebits | addbits);
+}
+
 #define pte_pgprot(x) __pgprot(pte_val(x) & (0xfff | _PAGE_NX))
 
 #define canon_pgprot(p) __pgprot(pgprot_val(p) & __supported_pte_mask)
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[git head] Should X86_PAT really default to yes?, Frans Pop, (Fri May 2, 3:22 pm)
RE: [git head] Should X86_PAT really default to yes?, Pallipadi, Venkatesh, (Fri May 2, 3:37 pm)
Re: [git head] Should X86_PAT really default to yes?, Jesse Barnes, (Fri May 2, 4:40 pm)
Re: [git head] Should X86_PAT really default to yes?, Jesse Barnes, (Mon May 5, 11:57 am)
Re: [git head] Should X86_PAT really default to yes?, Venki Pallipadi, (Tue May 6, 6:42 pm)
Re: [git head] Should X86_PAT really default to yes?, Frans Pop, (Sun May 25, 11:08 am)
Re: [git head] X86_PAT &amp; mprotect, Ingo Molnar, (Wed May 7, 3:02 am)
Re: [git head] X86_PAT &amp; mprotect, Venki Pallipadi, (Wed May 7, 6:36 pm)
Re: [git head] X86_PAT &amp; mprotect, Hugh Dickins, (Wed May 7, 3:18 pm)
Re: [git head] X86_PAT &amp; mprotect, Venki Pallipadi, (Wed May 7, 7:23 pm)
Re: [git head] X86_PAT &amp; mprotect, Ingo Molnar, (Fri May 9, 6:08 am)
Re: [git head] X86_PAT &amp; mprotect, Venki Pallipadi, (Fri May 9, 4:05 pm)
Re: [git head] X86_PAT &amp; mprotect, Dave Airlie, (Fri May 9, 6:11 pm)
Re: [git head] X86_PAT &amp; mprotect, Keith Packard, (Sat May 10, 1:45 am)
RE: [git head] X86_PAT &amp; mprotect, Pallipadi, Venkatesh, (Fri May 9, 6:20 pm)
Re: [git head] X86_PAT &amp; mprotect, Dave Airlie, (Sat May 10, 2:19 am)
Re: [git head] X86_PAT &amp; mprotect, Keith Packard, (Sat May 10, 2:29 am)
Re: [git head] X86_PAT & mprotect, Venki Pallipadi, (Fri May 9, 4:09 pm)
Re: [git head] X86_PAT &amp; mprotect, Hugh Dickins, (Fri May 9, 4:48 pm)
Re: [git head] Should X86_PAT really default to yes?, Jesse Barnes, (Mon May 5, 1:45 pm)
Re: fb layer &amp; ioremap_wc, Jesse Barnes, (Mon May 5, 3:04 pm)
Re: fb layer &amp; ioremap_wc, Frans Pop, (Fri Jun 13, 12:42 pm)
RE: [git head] Should X86_PAT really default to yes?, Pallipadi, Venkatesh, (Mon May 5, 1:59 pm)
RE: [git head] Should X86_PAT really default to yes?, Pallipadi, Venkatesh, (Mon May 5, 1:00 pm)
Re: [git head] Should X86_PAT really default to yes?, Ingo Molnar, (Sun May 4, 5:04 am)
RE: [git head] Should X86_PAT really default to yes?, Pallipadi, Venkatesh, (Fri May 2, 5:55 pm)
Re: [git head] Should X86_PAT really default to yes?, Jesse Barnes, (Fri May 2, 6:07 pm)
speck-geostationary