public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
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>
Subject: Re: [PATCH V3] x86: NX protection for kernel data
Date: Fri, 4 Sep 2009 09:46:26 +0200	[thread overview]
Message-ID: <20090904074626.GC20598@elte.hu> (raw)
In-Reply-To: <817ecb6f0909031813n335279a3pb974b9efa8989095@mail.gmail.com>


* Siarhei Liakh <sliakh.lkml@gmail.com> 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 arch/x86/mm/init.c with actual
> functionality: NX is set for all pages from _etext through _end.
> 4. mark_nxdata_nx() called from free_initmem() (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>.
> 
> V1:  initial patch for 2.6.30
> V2:  patch for 2.6.31-rc7
> V3:  moved all code into arch/x86, adjusted credits

ok, i like it.

One small cleanliness detail before we can apply it to the x86 tree:

> --- a/arch/x86/mm/init.c
> +++ b/arch/x86/mm/init.c
> @@ -440,11 +441,31 @@ void free_init_pages(char *what, unsigned long
> begin, unsigned long end)
>  #endif
>  }
> 
> +#ifndef CONFIG_DEBUG_RODATA
> +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);
> +}
> +#endif

This #ifdef looks ugly, it starts with an #ifndef which is inverted 
logic and mark_nxdata_nx() is a global symbol, needlessly. It should 
be written as something like:

static void mark_nxdata_nx(void)
{
#ifdef CONFIG_DEBUG_RODATA
...
#endif
}

Thanks,

	Ingo

  reply	other threads:[~2009-09-04  7:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-04  1:13 [PATCH V3] x86: NX protection for kernel data Siarhei Liakh
2009-09-04  7:46 ` Ingo Molnar [this message]
2009-09-04  9:37 ` Américo Wang

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=20090904074626.GC20598@elte.hu \
    --to=mingo@elte.hu \
    --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=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