From 44c5429a92a99d5f29c59a2bc217206709bccf35 Mon Sep 17 00:00:00 2001 From: Arjan van de Ven Date: Fri, 6 Jan 2006 00:12:04 -0800 Subject: [PATCH] --- yaml --- r: 16383 b: refs/heads/master c: 67df197b1a07944c2e0e40ded3d4fd07d108e110 h: refs/heads/master i: 16381: 8dfeca6f36668a31c850b2271608dc5998695a09 16379: a6d0973f0178987ecefcfe9cc3e36d32850c9a21 16375: 2512522d49c0b42338cbc59f38083b81de0a3ed8 16367: 2d5e057e812be99caf664003b3650eafb580e8c4 16351: eb75807eeac19a8f8c38f54ae02cc347008e4928 16319: bd25bb0055ae5ea7696f0a823bb8cfc766c102ab 16255: b69fd24aa9cbdb9b4815ace69380b43f323a2f12 16127: b6a4d61f841173846125f140d6c64744b95b63e1 15871: 96b097471a5efccf41a91bd7ac0dc96c72b4d8c2 15359: dfd735e907a988f2f98c486fed98600a1869eb1d 14335: 17c11290a85606a80545b40505262233069d4eee 12287: bd96c6237ab7f45251157c831d903d96fdddbcc0 8191: 08f97ba64c3a1c2ff8d3b8828ffa9cf9073395bf v: v3 --- [refs] | 2 +- trunk/arch/x86_64/Kconfig.debug | 10 ++++++++++ trunk/arch/x86_64/mm/init.c | 23 +++++++++++++++++++++++ trunk/include/asm-x86_64/cacheflush.h | 4 ++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index f8a055346c36..8cb6f4637da7 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: c728252c7a072628bd3932ff87943d1e12423359 +refs/heads/master: 67df197b1a07944c2e0e40ded3d4fd07d108e110 diff --git a/trunk/arch/x86_64/Kconfig.debug b/trunk/arch/x86_64/Kconfig.debug index e2c6e64a85ec..fcb06a50fdd2 100644 --- a/trunk/arch/x86_64/Kconfig.debug +++ b/trunk/arch/x86_64/Kconfig.debug @@ -9,6 +9,16 @@ config INIT_DEBUG Fill __init and __initdata at the end of boot. This helps debugging illegal uses of __init and __initdata after initialization. +config DEBUG_RODATA + bool "Write protect kernel read-only data structures" + depends on DEBUG_KERNEL + help + Mark the kernel read-only data as write-protected in the pagetables, + in order to catch accidental (and incorrect) writes to such const data. + This option may have a slight performance impact because a portion + of the kernel code won't be covered by a 2MB TLB anymore. + If in doubt, say "N". + config IOMMU_DEBUG depends on GART_IOMMU && DEBUG_KERNEL bool "Enable IOMMU debugging" diff --git a/trunk/arch/x86_64/mm/init.c b/trunk/arch/x86_64/mm/init.c index c016dfe84784..1faae5fc1c01 100644 --- a/trunk/arch/x86_64/mm/init.c +++ b/trunk/arch/x86_64/mm/init.c @@ -498,6 +498,29 @@ void free_initmem(void) printk ("Freeing unused kernel memory: %luk freed\n", (__init_end - __init_begin) >> 10); } +#ifdef CONFIG_DEBUG_RODATA + +extern char __start_rodata, __end_rodata; +void mark_rodata_ro(void) +{ + unsigned long addr = (unsigned long)&__start_rodata; + + for (; addr < (unsigned long)&__end_rodata; addr += PAGE_SIZE) + change_page_attr_addr(addr, 1, PAGE_KERNEL_RO); + + printk ("Write protecting the kernel read-only data: %luk\n", + (&__end_rodata - &__start_rodata) >> 10); + + /* + * change_page_attr_addr() requires a global_flush_tlb() call after it. + * We do this after the printk so that if something went wrong in the + * change, the printk gets out at least to give a better debug hint + * of who is the culprit. + */ + global_flush_tlb(); +} +#endif + #ifdef CONFIG_BLK_DEV_INITRD void free_initrd_mem(unsigned long start, unsigned long end) { diff --git a/trunk/include/asm-x86_64/cacheflush.h b/trunk/include/asm-x86_64/cacheflush.h index b3189fb229d1..d32f7f58752a 100644 --- a/trunk/include/asm-x86_64/cacheflush.h +++ b/trunk/include/asm-x86_64/cacheflush.h @@ -27,4 +27,8 @@ void global_flush_tlb(void); int change_page_attr(struct page *page, int numpages, pgprot_t prot); int change_page_attr_addr(unsigned long addr, int numpages, pgprot_t prot); +#ifdef CONFIG_DEBUG_RODATA +void mark_rodata_ro(void); +#endif + #endif /* _X8664_CACHEFLUSH_H */