summaryrefslogtreecommitdiff
path: root/exec
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2004-02-10 21:42:05 +0000
committerRoland McGrath <roland@gnu.org>2004-02-10 21:42:05 +0000
commit6b1ecbc6e533eb7f2395623dccb2f80d94dae764 (patch)
tree2546094869048a5e3c65c5effcdd64682a6c35f9 /exec
parentb69041235d4c3b5d5d392fb0ae2f54d44e25e841 (diff)
2004-01-15 Roland McGrath <roland@frob.com>
* priv.h (struct execdata.info.elf): Add `execstack' flag. * exec.c (check_elf_phdr): Set it according to PT_GNU_STACK's PF_X flag bit. If no PT_GNU_STACK, default to set. (do_exec): If flag is clear, remove execute permission from stack.
Diffstat (limited to 'exec')
-rw-r--r--exec/exec.c22
-rw-r--r--exec/priv.h3
2 files changed, 23 insertions, 2 deletions
diff --git a/exec/exec.c b/exec/exec.c
index d96ce8e9..6ffacbde 100644
--- a/exec/exec.c
+++ b/exec/exec.c
@@ -1,5 +1,5 @@
/* GNU Hurd standard exec server.
- Copyright (C) 1992,93,94,95,96,98,99,2000,01,02
+ Copyright (C) 1992,93,94,95,96,98,99,2000,01,02,04
Free Software Foundation, Inc.
Written by Roland McGrath.
@@ -902,6 +902,12 @@ check_elf_phdr (struct execdata *e, const ElfW(Phdr) *mapped_phdr,
memcpy (e->info.elf.phdr, mapped_phdr,
e->info.elf.phnum * sizeof (ElfW(Phdr)));
+ /* Default state if we do not see PT_GNU_STACK telling us what to do.
+ Executable stack is the compatible default.
+ (XXX should be machine-dependent??)
+ */
+ e->info.elf.execstack = 1;
+
for (phdr = e->info.elf.phdr;
phdr < &e->info.elf.phdr[e->info.elf.phnum];
++phdr)
@@ -922,6 +928,9 @@ check_elf_phdr (struct execdata *e, const ElfW(Phdr) *mapped_phdr,
phdr->p_filesz))
e->error = ENOEXEC;
break;
+ case PT_GNU_STACK:
+ e->info.elf.execstack = phdr->p_flags & PF_X;
+ break;
}
}
@@ -1822,6 +1831,17 @@ do_exec (file_t file,
&boot->stack_base, &boot->stack_size);
if (e.error)
goto out;
+#ifdef BFD
+ if (!e.bfd)
+#endif
+ {
+ /* It would probably be better to change mach_setup_thread so
+ it does a vm_map with the right permissions to start with. */
+ if (!e.info.elf.execstack)
+ e.error = vm_protect (newtask, boot->stack_base, boot->stack_size,
+ 0, VM_PROT_READ | VM_PROT_WRITE);
+ }
+
if (oldtask != newtask && oldtask != MACH_PORT_NULL)
{
diff --git a/exec/priv.h b/exec/priv.h
index 46cc919e..625ea477 100644
--- a/exec/priv.h
+++ b/exec/priv.h
@@ -1,5 +1,5 @@
/* GNU Hurd standard exec server, private declarations.
- Copyright (C) 1992,93,94,95,96,99,2000,02 Free Software Foundation, Inc.
+ Copyright (C) 1992,93,94,95,96,99,2000,02, 04 Free Software Foundation, Inc.
Written by Roland McGrath.
This file is part of the GNU Hurd.
@@ -151,6 +151,7 @@ struct execdata
ElfW(Word) phnum; /* Number of program header table elements. */
int anywhere; /* Nonzero if image can go anywhere. */
vm_address_t loadbase; /* Actual mapping location. */
+ int execstack; /* Zero if stack can be nonexecutable. */
} elf;
} info;
};