* curious about setting read-only section to RO
@ 2008-04-25 10:57 Robert P. J. Day
0 siblings, 0 replies; only message in thread
From: Robert P. J. Day @ 2008-04-25 10:57 UTC (permalink / raw)
To: Linux Kernel Mailing List
from arch/x86/mm/init_32.c:
...
#ifdef CONFIG_DEBUG_RODATA
const int rodata_test_data = 0xC3;
EXPORT_SYMBOL_GPL(rodata_test_data);
void mark_rodata_ro(void)
{
unsigned long start = PFN_ALIGN(_text);
unsigned long size = PFN_ALIGN(_etext) - start;
set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
printk(KERN_INFO "Write protecting the kernel text: %luk\n",
size >> 10);
#ifdef CONFIG_CPA_DEBUG
printk(KERN_INFO "Testing CPA: Reverting %lx-%lx\n",
start, start+size);
set_pages_rw(virt_to_page(start), size>>PAGE_SHIFT);
printk(KERN_INFO "Testing CPA: write protecting again\n");
set_pages_ro(virt_to_page(start), size>>PAGE_SHIFT);
#endif
start += size;
size = (unsigned long)__end_rodata - start;
set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n",
size >> 10);
rodata_test();
...
some questions:
1) i was going to ask why the kernel .text section wasn't just set to
RO by default, but i read a post by arjan suggesting that might be a
performance hit. enough of a performance hit to actually not put in
that check permanently?
2) the .rodata section is allegedly write-protected by simply assuming
it always lives *immediately* after the .text section. is that always
a valid assumption here? wouldn't it be safer to identify the .rodata
section based on the __start_rodata symbol defined in
include/asm-generic/vmlinux.lds.h? that would seem to be the more
reliable thing to do, no?
3) is there any debugging benefit to treating the .text and .rodata
sections independently? as in, allowing one to write-protect one or
the other, but not both? i'm not arguing for that, just asking.
rday
--
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
Have classroom, will lecture.
http://crashcourse.ca Waterloo, Ontario, CANADA
========================================================================
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-04-25 10:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-25 10:57 curious about setting read-only section to RO Robert P. J. Day
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®