public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* RE: [announce] [patch] NX (No eXecute) support for x86,   2.6.7-rc2-bk2
@ 2004-06-04 18:01 Nakajima, Jun
  0 siblings, 0 replies; 66+ messages in thread
From: Nakajima, Jun @ 2004-06-04 18:01 UTC (permalink / raw)
  To: Ingo Molnar, Linus Torvalds
  Cc: Andy Lutomirski, Andi Kleen, Kernel Mailing List, Andrew Morton,
	arjanv, Siddha, Suresh B

>From: Ingo Molnar [mailto:mingo@elte.hu]
>Sent: Friday, June 04, 2004 10:20 AM
>To: Linus Torvalds
>Cc: Andy Lutomirski; Andi Kleen; Kernel Mailing List; Andrew Morton;
>arjanv@redhat.com; Siddha, Suresh B; Nakajima, Jun
>Subject: Re: [announce] [patch] NX (No eXecute) support for x86,
2.6.7-rc2-
>bk2
>
>
>correction to the table:
>
>>  PT_GNU_STACK not present: legacy app, stack and heap executable
>>  PT_GNU_STACK present but X: heap non-executable, stack executable
>>  PT_GNU_STACK present and !X: both heap and stack are non-executable.
>>
>> this method is what is used in Fedora and it works pretty well.
>
Thanks for the correction. This sounds good to me. To me this simply
means the heap is non-executable by default in Linux if compiled by the
new gcc:
- the compiler controls if the stack is executable or not. 
- legacy apps would be more secure if recompiled by the new gcc
- if an app is broken when recompiled by the new gcc, the app has a bug,
or security issue. We should fix it, but in the meantime we could make
it run by removing PT_GNU_STACK, or by using the old binary, for
example. 

Jun

>the patch below implements this simple and pretty robust logic ontop of
>the -AF NX patch.
>
>in fact it's more conservative than what we have in Fedora because it
>will turn on executability even for data mmap()s. (in theory there
could
>be third party apps that expect a data mmap to be executable on x86
even
>if it's not PROT_EXEC.)
>
>I've test-booted it on an athlon64 box running FC2 and have tested an
>old PT_GNU_STACK-less binary and it indeed has all data mappings
>executable, explicitly. (I've also test-booted it on an x86 box with an
>older distribution installed - works as expected.)
>
>newly-compiled applications that have the PT_GNU_STACK flag (either as
X
>or NX) will have the heap non-executable, and the stack executable
>depending on the value of the flag.
>
>hm?
>
>	Ingo
>
>--- linux/fs/binfmt_elf.c
>+++ linux/fs/binfmt_elf.c
>@@ -491,6 +491,7 @@ static int load_elf_binary(struct linux_
> 	char passed_fileno[6];
> 	struct files_struct *files;
> 	int executable_stack = EXSTACK_DEFAULT;
>+	unsigned long def_flags = 0;
>
> 	/* Get the exec-header */
> 	elf_ex = *((struct elfhdr *) bprm->buf);
>@@ -622,7 +623,10 @@ static int load_elf_binary(struct linux_
> 				executable_stack = EXSTACK_ENABLE_X;
> 			else
> 				executable_stack = EXSTACK_DISABLE_X;
>+			break;
> 		}
>+	if (i == elf_ex.e_phnum)
>+		def_flags |= VM_EXEC | VM_MAYEXEC;
>
> 	/* Some simple consistency checks for the interpreter */
> 	if (elf_interpreter) {
>@@ -690,6 +694,7 @@ static int load_elf_binary(struct linux_
> 	current->mm->end_code = 0;
> 	current->mm->mmap = NULL;
> 	current->flags &= ~PF_FORKNOEXEC;
>+	current->mm->def_flags = def_flags;
>
> 	/* Do this immediately, since STACK_TOP as used in
setup_arg_pages
> 	   may depend on the personality.  */
>--- linux/fs/exec.c
>+++ linux/fs/exec.c
>@@ -431,6 +431,7 @@ int setup_arg_pages(struct linux_binprm
> 			mpnt->vm_flags = VM_STACK_FLAGS & ~VM_EXEC;
> 		else
> 			mpnt->vm_flags = VM_STACK_FLAGS;
>+		mpnt->vm_flags |= mm->def_flags;
> 		mpnt->vm_page_prot = protection_map[mpnt->vm_flags &
0x7];
> 		insert_vm_struct(mm, mpnt);
> 		mm->total_vm = (mpnt->vm_end - mpnt->vm_start) >>
PAGE_SHIFT;
>--- linux/include/asm-i386/page.h
>+++ linux/include/asm-i386/page.h
>@@ -138,7 +138,7 @@ static __inline__ int get_order(unsigned
>
> #define virt_addr_valid(kaddr)	pfn_valid(__pa(kaddr) >>
PAGE_SHIFT)
>
>-#define VM_DATA_DEFAULT_FLAGS	(VM_READ | VM_WRITE | VM_EXEC | \
>+#define VM_DATA_DEFAULT_FLAGS	(VM_READ | VM_WRITE | \
> 				 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
>
> #endif /* __KERNEL__ */


^ permalink raw reply	[flat|nested] 66+ messages in thread
* [announce] [patch] NX (No eXecute) support for x86, 2.6.7-rc2-bk2
@ 2004-06-02 20:50 Ingo Molnar
  2004-06-02 21:00 ` Christoph Hellwig
                   ` (5 more replies)
  0 siblings, 6 replies; 66+ messages in thread
From: Ingo Molnar @ 2004-06-02 20:50 UTC (permalink / raw)
  To: linux-kernel
  Cc: Andrew Morton, Andi Kleen, Linus Torvalds, Arjan van de Ven,
	Siddha, Suresh B, Nakajima, Jun


we'd like to announce the availability of the following kernel patch:

     http://redhat.com/~mingo/nx-patches/nx-2.6.7-rc2-bk2-AE

which makes use of the 'NX' x86 feature pioneered in AMD64 CPUs and for
which support has also been announced by Intel. (other x86 CPU vendors,
Transmeta and VIA announced support as well. Windows support for NX has
also been announced by Microsoft, for their next service pack.) The NX
feature is also being marketed as 'Enhanced Virus Protection'. This
patch makes sure Linux has full support for this hardware feature on x86
too.

What does this patch do? The pagetable format of current x86 CPUs does
not have an 'execute' bit. This means that even if an application maps a
memory area without PROT_EXEC, the CPU will still allow code to be
executed in this memory. This property is often abused by exploits when
they manage to inject hostile code into this memory, for example via a
buffer overflow.

The NX feature changes this and adds a 'dont execute' bit to the PAE
pagetable format. But since the flag defaults to zero (for compatibility
reasons), all pages are executable by default and the kernel has to be
taught to make use of this bit.

If the NX feature is supported by the CPU then the patched kernel turns
on NX and it will enforce userspace executability constraints such as a
no-exec stack and no-exec mmap and data areas. This means less chance
for stack overflows and buffer-overflows to cause exploits.

furthermore, the patch also implements 'NX protection' for kernelspace
code: only the kernel code and modules are executable - so even
kernel-space overflows are harder (in some cases, impossible) to
exploit. Here is how kernel code that tries to execute off the stack is 
stopped:

 kernel tried to access NX-protected page - exploit attempt? (uid: 500)
 Unable to handle kernel paging request at virtual address f78d0f40
  printing eip:
 ...

The patch is based on a prototype NX patch written for 2.4 by Intel -
special thanks go to Suresh Siddha and Jun Nakajima @ Intel. The
existing NX support in the 64-bit x86_64 kernels has been written by
Andi Kleen and this patch is modeled after his code.

Arjan van de Ven has also provided lots of feedback and he has
integrated the patch into the Fedora Core 2 kernel. Test rpms are
available for download at:

    http://redhat.com/~arjanv/2.6/RPMS.kernel/

the kernel-2.6.6-1.411 rpms have the NX patch applied.

here's a quickstart to recompile the vanilla kernel from source with the
NX patch:

    http://redhat.com/~mingo/nx-patches/QuickStart-NX.txt

	Ingo

^ permalink raw reply	[flat|nested] 66+ messages in thread

end of thread, other threads:[~2004-06-08 17:15 UTC | newest]

Thread overview: 66+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <22L0f-5Ci-11@gated-at.bofh.it>
     [not found] ` <22O7J-8dw-11@gated-at.bofh.it>
     [not found]   ` <22Wf4-5Xv-23@gated-at.bofh.it>
2004-06-03  9:43     ` [announce] [patch] NX (No eXecute) support for x86, 2.6.7-rc2-bk2 Andi Kleen
2004-06-04 18:01 Nakajima, Jun
  -- strict thread matches above, loose matches on Subject: below --
2004-06-02 20:50 Ingo Molnar
2004-06-02 21:00 ` Christoph Hellwig
2004-06-02 21:07   ` Ingo Molnar
2004-06-02 21:13 ` Linus Torvalds
2004-06-02 21:17   ` Arjan van de Ven
2004-06-02 21:31     ` Doug McNaught
2004-06-08  8:46       ` Jakub Jelinek
2004-06-03  1:12     ` Joel Becker
2004-06-03  1:27       ` Andi Kleen
2004-06-03  6:24       ` Arjan van de Ven
2004-06-03 20:37     ` jlnance
2004-06-03  7:21   ` Ingo Molnar
2004-06-03 12:44     ` Ingo Molnar
2004-06-03 15:54       ` Andi Kleen
2004-06-03 23:01         ` Andy Lutomirski
2004-06-03 23:08           ` Andi Kleen
2004-06-03 23:54             ` Andy Lutomirski
2004-06-04  0:05               ` Andy Lutomirski
2004-06-04  9:25             ` Ingo Molnar
2004-06-04 15:26               ` Andy Lutomirski
2004-06-04 15:36                 ` Linus Torvalds
2004-06-04 15:41                   ` Arjan van de Ven
2004-06-04 15:47                     ` Linus Torvalds
2004-06-04 15:51                       ` Arjan van de Ven
2004-06-04 16:02                         ` Linus Torvalds
2004-06-04 16:13                           ` Andi Kleen
2004-06-04 16:37                             ` Arjan van de Ven
2004-06-04 16:40                               ` Christoph Hellwig
2004-06-04 17:27                                 ` David Mosberger
2004-06-04 17:30                                 ` Andi Kleen
2004-06-08  9:07                             ` Jakub Jelinek
2004-06-08  9:14                               ` Andi Kleen
2004-06-08  9:19                                 ` Arjan van de Ven
2004-06-04 16:51                           ` Ulrich Drepper
2004-06-08 17:15                             ` Bill Davidsen
2004-06-04 18:11                         ` Gerhard Mack
2004-06-04 18:12                           ` Arjan van de Ven
2004-06-04 16:06                   ` Ingo Molnar
2004-06-04 17:20                     ` Ingo Molnar
2004-06-04 17:22                       ` Ingo Molnar
2004-06-04 17:32                         ` Ingo Molnar
2004-06-03 19:24       ` Suresh Siddha
2004-06-03 20:37         ` Andi Kleen
2004-06-03 22:58           ` Suresh Siddha
2004-06-03 23:06             ` Andi Kleen
2004-06-04  9:30             ` Ingo Molnar
2004-06-03 12:57     ` Brian Gerst
2004-06-04  9:39       ` Ingo Molnar
2004-06-04 10:41         ` Christoph Hellwig
2004-06-04 10:48           ` William Lee Irwin III
2004-06-03 16:21     ` Ulrich Drepper
2004-06-03 19:30   ` Kurt Garloff
2004-06-02 21:43 ` Andi Kleen
2004-06-03  0:11 ` Rusty Russell
2004-06-03  0:17   ` Jeff Garzik
2004-06-03  7:24   ` Ingo Molnar
2004-06-03  8:47   ` Ingo Molnar
2004-06-03  8:53   ` Ingo Molnar
2004-06-04  0:04     ` Rusty Russell
2004-06-03  9:07 ` Ingo Molnar
2004-06-03 14:36 ` Gerhard Mack
2004-06-03 16:22   ` Arjan van de Ven
2004-06-04  9:36   ` Ingo Molnar
2004-06-04 11:59     ` Stephen Wille Padnos

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox