Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Some ibcs2 binaries need executable stacks. Thanks to J ...



details:   https://anonhg.NetBSD.org/src/rev/cf752f54fd7d
branches:  trunk
changeset: 574521:cf752f54fd7d
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Mar 03 04:39:37 2005 +0000

description:
Some ibcs2 binaries need executable stacks. Thanks to J Chapman Flack
for determining this and coming up with a fix.

diffstat:

 sys/compat/ibcs2/ibcs2_exec.c |  65 +++++++++++++++++++++++++++++++++++++++++-
 sys/compat/ibcs2/ibcs2_exec.h |   3 +-
 sys/kern/exec_conf.c          |   8 ++--
 3 files changed, 69 insertions(+), 7 deletions(-)

diffs (136 lines):

diff -r ef0dba841151 -r cf752f54fd7d sys/compat/ibcs2/ibcs2_exec.c
--- a/sys/compat/ibcs2/ibcs2_exec.c     Thu Mar 03 04:21:51 2005 +0000
+++ b/sys/compat/ibcs2/ibcs2_exec.c     Thu Mar 03 04:39:37 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ibcs2_exec.c,v 1.61 2005/02/26 23:10:18 perry Exp $    */
+/*     $NetBSD: ibcs2_exec.c,v 1.62 2005/03/03 04:39:37 christos Exp $ */
 
 /*
  * Copyright (c) 1994, 1995, 1998 Scott Bartram
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ibcs2_exec.c,v 1.61 2005/02/26 23:10:18 perry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ibcs2_exec.c,v 1.62 2005/03/03 04:39:37 christos Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_syscall_debug.h"
@@ -125,3 +125,64 @@
        else
                p->p_emuldata = IBCS2_EXEC_OTHER;
 }
+
+/*
+ * ibcs2_exec_setup_stack(): Set up the stack segment for an
+ * executable.
+ *
+ * Note that the ep_ssize parameter must be set to be the current stack
+ * limit; this is adjusted in the body of execve() to yield the
+ * appropriate stack segment usage once the argument length is
+ * calculated.
+ *
+ * This function returns an int for uniformity with other (future) formats'
+ * stack setup functions.  They might have errors to return.
+ */
+
+int
+ibcs2_exec_setup_stack(struct proc *p, struct exec_package *epp)
+{
+       u_long max_stack_size;
+       u_long access_linear_min, access_size;
+       u_long noaccess_linear_min, noaccess_size;
+
+#ifndef        USRSTACK32
+#define USRSTACK32     (0x00000000ffffffffL&~PGOFSET)
+#endif
+
+       if (epp->ep_flags & EXEC_32) {
+               epp->ep_minsaddr = USRSTACK32;
+               max_stack_size = MAXSSIZ;
+       } else {
+               epp->ep_minsaddr = USRSTACK;
+               max_stack_size = MAXSSIZ;
+       }
+       epp->ep_maxsaddr = (u_long)STACK_GROW(epp->ep_minsaddr,
+               max_stack_size);
+       epp->ep_ssize = p->p_rlimit[RLIMIT_STACK].rlim_cur;
+
+       /*
+        * set up commands for stack.  note that this takes *two*, one to
+        * map the part of the stack which we can access, and one to map
+        * the part which we can't.
+        *
+        * arguably, it could be made into one, but that would require the
+        * addition of another mapping proc, which is unnecessary
+        */
+       access_size = epp->ep_ssize;
+       access_linear_min = (u_long)STACK_ALLOC(epp->ep_minsaddr, access_size);
+       noaccess_size = max_stack_size - access_size;
+       noaccess_linear_min = (u_long)STACK_ALLOC(STACK_GROW(epp->ep_minsaddr,
+           access_size), noaccess_size);
+       if (noaccess_size > 0) {
+               NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, noaccess_size,
+                   noaccess_linear_min, NULL, 0, VM_PROT_NONE);
+       }
+       KASSERT(access_size > 0);
+       /* XXX: some ibcs2 binaries need an executable stack. */
+       NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_zero, access_size,
+           access_linear_min, NULL, 0, VM_PROT_READ | VM_PROT_WRITE |
+           VM_PROT_EXECUTE);
+
+       return 0;
+}
diff -r ef0dba841151 -r cf752f54fd7d sys/compat/ibcs2/ibcs2_exec.h
--- a/sys/compat/ibcs2/ibcs2_exec.h     Thu Mar 03 04:21:51 2005 +0000
+++ b/sys/compat/ibcs2/ibcs2_exec.h     Thu Mar 03 04:39:37 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ibcs2_exec.h,v 1.12 2003/06/29 22:29:19 fvdl Exp $     */
+/*     $NetBSD: ibcs2_exec.h,v 1.13 2005/03/03 04:39:37 christos Exp $ */
 
 /*
  * Copyright (c) 1994, 1995, 1998 Scott Bartram
@@ -181,6 +181,7 @@
 #define XOUT_HDR_SIZE          (sizeof(struct xexec) + sizeof(struct xext))
 
 int     exec_ibcs2_xout_makecmds __P((struct proc *, struct exec_package *));
+int    ibcs2_exec_setup_stack __P((struct proc *, struct exec_package *));
 
 #ifdef EXEC_ELF32
 int    ibcs2_elf32_probe __P((struct proc *, struct exec_package *,
diff -r ef0dba841151 -r cf752f54fd7d sys/kern/exec_conf.c
--- a/sys/kern/exec_conf.c      Thu Mar 03 04:21:51 2005 +0000
+++ b/sys/kern/exec_conf.c      Thu Mar 03 04:39:37 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exec_conf.c,v 1.88 2005/02/26 21:34:55 perry Exp $     */
+/*     $NetBSD: exec_conf.c,v 1.89 2005/03/03 04:39:37 christos Exp $  */
 
 /*
  * Copyright (c) 1993, 1994 Christopher G. Demetriou
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exec_conf.c,v 1.88 2005/02/26 21:34:55 perry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_conf.c,v 1.89 2005/03/03 04:39:37 christos Exp $");
 
 #include "opt_execfmt.h"
 #include "opt_compat_freebsd.h"
@@ -583,7 +583,7 @@
          copyargs,
          NULL,
          coredump_netbsd,
-         exec_setup_stack },
+         ibcs2_exec_setup_stack },
 
        /* iBCS2 x.out (native word size) */
        { XOUT_HDR_SIZE,
@@ -595,7 +595,7 @@
          copyargs,
          NULL,
          coredump_netbsd,
-         exec_setup_stack },
+         ibcs2_exec_setup_stack },
 #endif
 
 #if defined(COMPAT_FREEBSD) && defined(EXEC_AOUT)



Home | Main Index | Thread Index | Old Index