mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Robert P. J. Day" <rpjday@crashcourse.ca>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: curious about setting read-only section to RO
Date: Fri, 25 Apr 2008 06:57:21 -0400 (EDT)	[thread overview]
Message-ID: <alpine.LFD.1.10.0804250651170.5837@localhost.localdomain> (raw)


  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
========================================================================

                 reply	other threads:[~2008-04-25 10:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.1.10.0804250651170.5837@localhost.localdomain \
    --to=rpjday@crashcourse.ca \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®