Fix pte_modify() bug which allowed mprotect() to change too many bits.

Linux Kernel Mailing List <[email protected]> Tue, 03 Aug 2004 16:06:08 +0000
Newsgroups gmane.linux.kernel.commits.2-4
Message-ID <[email protected]>
ChangeSet 1.1454, 2004/08/03 10:06:08-06:00, [email protected]

	Fix pte_modify() bug which allowed mprotect() to change too many bits.
	Found by Russell King.



 pgtable.h |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)


diff -Nru a/include/asm-ia64/pgtable.h b/include/asm-ia64/pgtable.h
--- a/include/asm-ia64/pgtable.h	2005-03-24 09:03:55 -08:00
+++ b/include/asm-ia64/pgtable.h	2005-03-24 09:03:55 -08:00
@@ -60,7 +60,8 @@
 #define _PAGE_PROTNONE		(__IA64_UL(1) << 63)
 
 #define _PFN_MASK		_PAGE_PPN_MASK
-#define _PAGE_CHG_MASK		(_PFN_MASK | _PAGE_A | _PAGE_D)
+/* Mask of bits which may be changed by pte_modify(): */
+#define _PAGE_CHG_MASK		_PAGE_AR_MASK
 
 #define _PAGE_SIZE_4K	12
 #define _PAGE_SIZE_8K	13
@@ -216,7 +217,7 @@
 ({ pte_t __pte; pte_val(__pte) = physpage + pgprot_val(pgprot); __pte; })
 
 #define pte_modify(_pte, newprot) \
-	(__pte((pte_val(_pte) & _PAGE_CHG_MASK) | pgprot_val(newprot)))
+	(__pte((pte_val(_pte) & ~_PAGE_CHG_MASK) | (pgprot_val(newprot) & _PAGE_CHG_MASK)))
 
 #define page_pte_prot(page,prot)	mk_pte(page, prot)
 #define page_pte(page)			page_pte_prot(page, __pgprot(0))