Commit 2813e143 authored by David Mosberger's avatar David Mosberger Committed by Linus Torvalds

[PATCH] NX: allow architectures to select legacy mode dynamically

On some platforms, you'll want to support READ_IMPLIES_EXEC differently
depending on personality (e.g, native binary vs. x86 binary).

This supports that (and makes the code more readable while at it) by
replacing the old architecture-specific fixed LEGACY_BINARIES macro
define with a architecture-specific "elf_read_implies_exec_binary()"
helper function.

For now, x86 is the only user, and sets the "read implies exec" bit for
legacy apps.  ia64 and x86-64 are likely to want to do their own thing.

Acked by Ingo.
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 6ad38b90
...@@ -492,7 +492,7 @@ static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs) ...@@ -492,7 +492,7 @@ static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs)
struct exec interp_ex; struct exec interp_ex;
char passed_fileno[6]; char passed_fileno[6];
struct files_struct *files; struct files_struct *files;
int executable_stack = EXSTACK_DEFAULT; int have_pt_gnu_stack, executable_stack = EXSTACK_DEFAULT;
unsigned long def_flags = 0; unsigned long def_flags = 0;
/* Get the exec-header */ /* Get the exec-header */
...@@ -627,10 +627,7 @@ static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs) ...@@ -627,10 +627,7 @@ static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs)
executable_stack = EXSTACK_DISABLE_X; executable_stack = EXSTACK_DISABLE_X;
break; break;
} }
#ifdef LEGACY_BINARIES have_pt_gnu_stack = (i < elf_ex.e_phnum);
if (i == elf_ex.e_phnum)
current->personality |= READ_IMPLIES_EXEC;
#endif
/* Some simple consistency checks for the interpreter */ /* Some simple consistency checks for the interpreter */
if (elf_interpreter) { if (elf_interpreter) {
...@@ -703,6 +700,8 @@ static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs) ...@@ -703,6 +700,8 @@ static int load_elf_binary(struct linux_binprm * bprm, struct pt_regs * regs)
/* Do this immediately, since STACK_TOP as used in setup_arg_pages /* Do this immediately, since STACK_TOP as used in setup_arg_pages
may depend on the personality. */ may depend on the personality. */
SET_PERSONALITY(elf_ex, ibcs2_interpreter); SET_PERSONALITY(elf_ex, ibcs2_interpreter);
if (elf_read_implies_exec(elf_ex, have_pt_gnu_stack))
current->personality |= READ_IMPLIES_EXEC;
/* Do this so that we can load the interpreter, if need be. We will /* Do this so that we can load the interpreter, if need be. We will
change some of these later */ change some of these later */
......
...@@ -120,10 +120,10 @@ typedef struct user_fxsr_struct elf_fpxregset_t; ...@@ -120,10 +120,10 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
#define SET_PERSONALITY(ex, ibcs2) do { } while (0) #define SET_PERSONALITY(ex, ibcs2) do { } while (0)
/* /*
* A legacy binary, when loaded by the ELF loader, will have the * An executable for which elf_read_implies_exec() returns TRUE will
* READ_IMPLIES_EXEC personality flag set automatically: * have the READ_IMPLIES_EXEC personality flag set automatically.
*/ */
#define LEGACY_BINARIES #define elf_read_implies_exec_binary(ex, have_pt_gnu_stack) (!(have_pt_gnu_stack))
extern int dump_task_regs (struct task_struct *, elf_gregset_t *); extern int dump_task_regs (struct task_struct *, elf_gregset_t *);
extern int dump_task_fpu (struct task_struct *, elf_fpregset_t *); extern int dump_task_fpu (struct task_struct *, elf_fpregset_t *);
......
...@@ -4,6 +4,13 @@ ...@@ -4,6 +4,13 @@
#include <linux/types.h> #include <linux/types.h>
#include <asm/elf.h> #include <asm/elf.h>
#ifndef elf_read_implies_exec
/* Executables for which elf_read_implies_exec() returns TRUE will
have the READ_IMPLIES_EXEC personality flag set automatically.
Override in asm/elf.h as needed. */
# define elf_read_implies_exec(ex, have_pt_gnu_stack) 0
#endif
/* 32-bit ELF base types. */ /* 32-bit ELF base types. */
typedef __u32 Elf32_Addr; typedef __u32 Elf32_Addr;
typedef __u16 Elf32_Half; typedef __u16 Elf32_Half;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment