public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch 01/02] Debug option to write-protect rodata: change_page_attr fixes
@ 2005-11-07 10:56 arjan
  2005-11-07 10:58 ` [patch 02/02] Debug option to write-protect rodata: the write protect logic and config option arjan
  0 siblings, 1 reply; 20+ messages in thread
From: arjan @ 2005-11-07 10:56 UTC (permalink / raw)
  To: linux-kernel; +Cc: ak, akpm

Hi,

I've been working on a patch that turns the kernel's .rodata section to be
actually read only, eg any write attempts to it cause a segmentation fault.
During this work I found a bug in the change_page_attr() code on x86-64, and
this patch 1 is the bugfix for that. Patch 2 will be the actual introduction
of the readonly option.


The bug fixed here is the following: when splitting a 2Mb PSE page that also
happened to contain kernel text, the split PMD would get the NX bit set
eventhough the individual pte entries for the 4Kb pages would not. This
causes problems still since this NX bit overrides in practice the sub bits.
The solution I've chosen is I think the right one: On splitting a 2Mb page
in the change_page_attr() code, inherit the existing pagetable permissions
exactly, for both the PMD page and all the 4Kb pte entries (with the
exception of the one that you wanted to change, but the code already did
that part correct).


Signed-off-by: Arjan van de Ven <arjan@infradead.org>

diff -purN linux-2.6.14/arch/x86_64/mm/pageattr.c linux-2.6.14-fordiff/arch/x86_64/mm/pageattr.c
--- linux-2.6.14/arch/x86_64/mm/pageattr.c	2005-10-28 02:02:08.000000000 +0200
+++ linux-2.6.14-fordiff/arch/x86_64/mm/pageattr.c	2005-11-05 18:27:07.000000000 +0100
@@ -128,6 +131,7 @@ __change_page_attr(unsigned long address
 	pte_t *kpte; 
 	struct page *kpte_page;
 	unsigned kpte_flags;
+	pgprot_t ref_prot2;
 	kpte = lookup_address(address);
 	if (!kpte) return 0;
 	kpte_page = virt_to_page(((unsigned long)kpte) & PAGE_MASK);
@@ -140,10 +144,14 @@ __change_page_attr(unsigned long address
  			 * split_large_page will take the reference for this change_page_attr
  			 * on the split page.
  			 */
-			struct page *split = split_large_page(address, prot, ref_prot); 
+
+			struct page *split;
+			ref_prot2 = __pgprot(pgprot_val(pte_pgprot(*lookup_address(address))) & ~(1<<_PAGE_BIT_PSE));
+
+			split = split_large_page(address, prot, ref_prot2); 
 			if (!split)
 				return -ENOMEM;
-			set_pte(kpte,mk_pte(split, ref_prot));
+			set_pte(kpte,mk_pte(split, ref_prot2));
 			kpte_page = split;
 		}	
 		get_page(kpte_page);
diff -purN linux-2.6.14/include/asm-x86_64/pgtable.h linux-2.6.14-fordiff/include/asm-x86_64/pgtable.h
--- linux-2.6.14/include/asm-x86_64/pgtable.h	2005-11-03 18:49:01.000000000 +0100
+++ linux-2.6.14-fordiff/include/asm-x86_64/pgtable.h	2005-11-05 13:20:44.000000000 +0100
@@ -119,6 +119,8 @@ static inline pte_t ptep_get_and_clear_f
 
 #define pte_same(a, b)		((a).pte == (b).pte)
 
+#define pte_pgprot(a)	(__pgprot((a).pte & ~(PHYSICAL_PAGE_MASK)))
+
 #define PMD_SIZE	(1UL << PMD_SHIFT)
 #define PMD_MASK	(~(PMD_SIZE-1))
 #define PUD_SIZE	(1UL << PUD_SHIFT)


^ permalink raw reply	[flat|nested] 20+ messages in thread
[parent not found: <56cTZ-2PF-5@gated-at.bofh.it>]

end of thread, other threads:[~2005-11-14 13:34 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-07 10:56 [patch 01/02] Debug option to write-protect rodata: change_page_attr fixes arjan
2005-11-07 10:58 ` [patch 02/02] Debug option to write-protect rodata: the write protect logic and config option arjan
2005-11-07 14:06   ` Josh Boyer
2005-11-07 14:20     ` Arjan van de Ven
2005-11-11  9:39       ` Coywolf Qi Hunt
2005-11-11  9:47         ` Arjan van de Ven
2005-11-11 18:57           ` Coywolf Qi Hunt
2005-11-11 19:04             ` [patch] mark text section read-only Coywolf Qi Hunt
2005-11-11 19:09               ` Arjan van de Ven
2005-11-11 19:34               ` linux-os (Dick Johnson)
2005-11-12 14:01                 ` Coywolf Qi Hunt
2005-11-11 21:43               ` Andi Kleen
2005-11-11 23:30                 ` Nikita Danilov
2005-11-12 17:26                   ` Andi Kleen
2005-11-12 14:32                 ` Coywolf Qi Hunt
2005-11-12 16:34                   ` Coywolf Qi Hunt
2005-11-13  4:50                     ` Keith Owens
2005-11-14 13:34               ` Linh Dang
     [not found] <56cTZ-2PF-5@gated-at.bofh.it>
     [not found] ` <56cTZ-2PF-3@gated-at.bofh.it>
     [not found]   ` <56fRE-7wr-21@gated-at.bofh.it>
     [not found]     ` <56gaT-7Un-17@gated-at.bofh.it>
     [not found]       ` <57DHW-jb-21@gated-at.bofh.it>
     [not found]         ` <57DHW-jb-19@gated-at.bofh.it>
     [not found]           ` <57Mia-4BG-5@gated-at.bofh.it>
     [not found]             ` <57MrY-50s-39@gated-at.bofh.it>
2005-11-11 23:03               ` Bodo Eggert
2005-11-12  4:42                 ` Coywolf Qi Hunt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox