From: Ingo Molnar <mingo@elte.hu>
To: Linus Torvalds <torvalds@osdl.org>
Cc: linux-kernel@vger.kernel.org, Andrew Morton <akpm@osdl.org>,
Andi Kleen <ak@suse.de>, Arjan van de Ven <arjanv@redhat.com>,
"Siddha, Suresh B" <suresh.b.siddha@intel.com>,
"Nakajima, Jun" <jun.nakajima@intel.com>
Subject: Re: [announce] [patch] NX (No eXecute) support for x86, 2.6.7-rc2-bk2
Date: Thu, 3 Jun 2004 14:44:48 +0200 [thread overview]
Message-ID: <20040603124448.GA28775@elte.hu> (raw)
In-Reply-To: <20040603072146.GA14441@elte.hu>
* Ingo Molnar <mingo@elte.hu> wrote:
> > And do we have some way of on a per-process basis say "avoid NX
> > because this old version of Oracle/flash/whatever-binary-thing doesn't
> > run with it"?
[...]
> 2) via a runtime method: via the i386 personality. So an application can
> trigger the 'legacy' Linux VM layout by e.g doing 'i386 java
> ./test.class'.
>
> this is a hack in Fedora - we wanted to have a finegrained runtime
> mechanism just in case. But it would be nice to have this upstream too -
> e.g. via a PERSONALITY_3G?
i've attached a patch that provides a cleaner solution. It does 3
changes:
- it adds a ADDR_SPACE_EXECUTABLE bit to the personality 'bug bits'
section. This bit if set will make the stack executable. (if in the
future we decide to make the malloc() heap non-exec [which i definitely
think we should], that property will also listen to this bit.)
- in elf.h, it changes the x86 personality inheritance code to match
that of x86_64 - which is a much saner method. This means if a complex
app that does exec()s will all run with the personality of the
parent(s).
- in exec.c, since address-space executability is a security-relevant
item, we must clear the personality when we exec a setuid binary. I
believe this is also a (small) security robustness fix for current
64-bit architectures.
(the patch also adds a break to the elf_ex.e_phnum loop - there can only
be one STACK header in the binary and once we found it we should not
iterate through the remaining program headers (if any).)
we didnt want to add a non-standard personality flag to Fedora so we
abused PER_LINUX32 as the compatibility flag - but this only works on
x86. With the ADDR_SPACE_EXECUTABLE flag there would be a standard
method to fall back to 'legacy' executability assumptions Linux
applications might make.
hm?
Ingo
--- linux/include/linux/personality.h.orig
+++ linux/include/linux/personality.h
@@ -30,6 +30,7 @@ extern int abi_fake_utsname;
*/
enum {
MMAP_PAGE_ZERO = 0x0100000,
+ ADDR_SPACE_EXECUTABLE = 0x0200000,
ADDR_LIMIT_32BIT = 0x0800000,
SHORT_INODE = 0x1000000,
WHOLE_SECONDS = 0x2000000,
--- linux/include/asm-i386/elf.h.orig
+++ linux/include/asm-i386/elf.h
@@ -117,7 +117,8 @@ typedef struct user_fxsr_struct elf_fpxr
#define AT_SYSINFO_EHDR 33
#ifdef __KERNEL__
-#define SET_PERSONALITY(ex, ibcs2) set_personality((ibcs2)?PER_SVR4:PER_LINUX)
+/* child inherits the personality of the parent */
+#define SET_PERSONALITY(ex, ibcs2) do { } while (0)
extern int dump_task_regs (struct task_struct *, elf_gregset_t *);
extern int dump_task_fpu (struct task_struct *, elf_fpregset_t *);
--- linux/fs/exec.c.orig
+++ linux/fs/exec.c
@@ -886,8 +886,11 @@ int prepare_binprm(struct linux_binprm *
if(!(bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID)) {
/* Set-uid? */
- if (mode & S_ISUID)
+ if (mode & S_ISUID) {
bprm->e_uid = inode->i_uid;
+ /* reset personality */
+ current->personality = PER_LINUX;
+ }
/* Set-gid? */
/*
@@ -895,8 +898,11 @@ int prepare_binprm(struct linux_binprm *
* is a candidate for mandatory locking, not a setgid
* executable.
*/
- if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
+ if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
bprm->e_gid = inode->i_gid;
+ /* reset personality */
+ current->personality = PER_LINUX;
+ }
}
/* fill in binprm security blob */
--- linux/fs/binfmt_elf.c.orig
+++ linux/fs/binfmt_elf.c
@@ -490,7 +490,7 @@ static int load_elf_binary(struct linux_
struct exec interp_ex;
char passed_fileno[6];
struct files_struct *files;
- int executable_stack = EXSTACK_DEFAULT;
+ int executable_stack;
/* Get the exec-header */
elf_ex = *((struct elfhdr *) bprm->buf);
@@ -616,13 +616,19 @@ static int load_elf_binary(struct linux_
}
elf_ppnt = elf_phdata;
- for (i = 0; i < elf_ex.e_phnum; i++, elf_ppnt++)
- if (elf_ppnt->p_type == PT_GNU_STACK) {
- if (elf_ppnt->p_flags & PF_X)
- executable_stack = EXSTACK_ENABLE_X;
- else
- executable_stack = EXSTACK_DISABLE_X;
- }
+ if (current->personality & ADDR_SPACE_EXECUTABLE)
+ executable_stack = EXSTACK_ENABLE_X;
+ else {
+ executable_stack = EXSTACK_DEFAULT;
+ for (i = 0; i < elf_ex.e_phnum; i++, elf_ppnt++)
+ if (elf_ppnt->p_type == PT_GNU_STACK) {
+ if (elf_ppnt->p_flags & PF_X)
+ executable_stack = EXSTACK_ENABLE_X;
+ else
+ executable_stack = EXSTACK_DISABLE_X;
+ break;
+ }
+ }
/* Some simple consistency checks for the interpreter */
if (elf_interpreter) {
next prev parent reply other threads:[~2004-06-03 12:43 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-02 20:50 [announce] [patch] NX (No eXecute) support for x86, 2.6.7-rc2-bk2 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 [this message]
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
[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 ` Andi Kleen
-- strict thread matches above, loose matches on Subject: below --
2004-06-04 18:01 Nakajima, Jun
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=20040603124448.GA28775@elte.hu \
--to=mingo@elte.hu \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=arjanv@redhat.com \
--cc=jun.nakajima@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=suresh.b.siddha@intel.com \
--cc=torvalds@osdl.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