public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Amerigo Wang <xiyou.wangcong@gmail.com>
To: Siarhei Liakh <sliakh.lkml@gmail.com>
Cc: linux-kernel@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	Arjan van de Ven <arjan@infradead.org>,
	James Morris <jmorris@namei.org>,
	Andrew Morton <akpm@linux-foundation.org>, Andi Kleen <ak@muc.de>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@elte.hu>
Subject: Re: [PATCH V2] x86: NX protection for kernel data
Date: Fri, 28 Aug 2009 16:52:22 +0800	[thread overview]
Message-ID: <20090828085222.GB4849@cr0.nay.redhat.com> (raw)
In-Reply-To: <817ecb6f0908261020y2267218h8f435e8dc392f69a@mail.gmail.com>

On Wed, Aug 26, 2009 at 01:20:19PM -0400, Siarhei Liakh wrote:
>This patch expands functionality of CONFIG_DEBUG_RODATA to set main
>(static) kernel data area as NX.
>The following steps are taken to achieve this:
>1. Linker script is adjusted so .text always starts and ends on a page boundary
>2. Linker script is adjusted so .rodata and .data always start and
>end on a page boundary
>3. void mark_nxdata_nx(void) added to init/main.c with actual
>functionality: NX is set for all
>pages from _etext through _end.
>4. mark_nxdata_nx() called from init_post(void) in init/main.c (after
>init has been released)
>5. free_init_pages() sets released memory NX in arch/x86/mm/init.c
>
>The patch have been developed for Linux 2.6.31-rc7 x86 by Siarhei Liakh
><sliakh.lkml@gmail.com> and Xuxian Jiang <jiang@cs.ncsu.edu>.
>


{snip}


>
> #include <linux/types.h>
>@@ -91,6 +93,21 @@ extern void radix_tree_init(void);
> extern void free_initmem(void);
> #ifndef CONFIG_DEBUG_RODATA
> static inline void mark_rodata_ro(void) { }
>+static inline void mark_nxdata_nx(void) { }
>+#else
>+void mark_nxdata_nx(void)
>+{
>+	/*
>+	 * When this called, init has already been executed and released,
>+	 * so everything past _etext sould be NX.
>+	 */
>+	unsigned long start = PFN_ALIGN(_etext);
>+	unsigned long size = PFN_ALIGN(_end) - start;
>+
>+	printk(KERN_INFO "NX-protecting the kernel data: %lx, %lu pages\n",
>+		start, size >> PAGE_SHIFT);
>+	set_pages_nx(virt_to_page(start), size >> PAGE_SHIFT);
>+}


I am afraid this function has to be in arch/x86/mm/init.c.
Seems set_pages_nx() is x86-specific.

Have you tested this on other arch?


  reply	other threads:[~2009-08-28  8:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-26 17:20 [PATCH V2] x86: NX protection for kernel data Siarhei Liakh
2009-08-28  8:52 ` Amerigo Wang [this message]
2009-08-31 10:39 ` Pavel Machek
2009-08-31 11:44   ` James Morris

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=20090828085222.GB4849@cr0.nay.redhat.com \
    --to=xiyou.wangcong@gmail.com \
    --cc=ak@muc.de \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@infradead.org \
    --cc=hpa@zytor.com \
    --cc=jmorris@namei.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rusty@rustcorp.com.au \
    --cc=sliakh.lkml@gmail.com \
    --cc=tglx@linutronix.de \
    /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