| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: exec_elf.c,v 1.31 2011/08/02 16:44:01 christos Exp $ */ | | 1 | /* $NetBSD: exec_elf.c,v 1.32 2011/08/27 17:53:21 reinoud Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Christos Zoulas. | | 8 | * by Christos Zoulas. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -47,27 +47,27 @@ | | | @@ -47,27 +47,27 @@ |
47 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 47 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
48 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 48 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
49 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 49 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
50 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 50 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
51 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 51 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
52 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 52 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
53 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 53 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
54 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 54 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
55 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 55 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
56 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 56 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
57 | */ | | 57 | */ |
58 | | | 58 | |
59 | #include <sys/cdefs.h> | | 59 | #include <sys/cdefs.h> |
60 | __KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.31 2011/08/02 16:44:01 christos Exp $"); | | 60 | __KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.32 2011/08/27 17:53:21 reinoud Exp $"); |
61 | | | 61 | |
62 | #ifdef _KERNEL_OPT | | 62 | #ifdef _KERNEL_OPT |
63 | #include "opt_pax.h" | | 63 | #include "opt_pax.h" |
64 | #endif /* _KERNEL_OPT */ | | 64 | #endif /* _KERNEL_OPT */ |
65 | | | 65 | |
66 | #include <sys/param.h> | | 66 | #include <sys/param.h> |
67 | #include <sys/proc.h> | | 67 | #include <sys/proc.h> |
68 | #include <sys/malloc.h> | | 68 | #include <sys/malloc.h> |
69 | #include <sys/kmem.h> | | 69 | #include <sys/kmem.h> |
70 | #include <sys/namei.h> | | 70 | #include <sys/namei.h> |
71 | #include <sys/vnode.h> | | 71 | #include <sys/vnode.h> |
72 | #include <sys/exec.h> | | 72 | #include <sys/exec.h> |
73 | #include <sys/exec_elf.h> | | 73 | #include <sys/exec_elf.h> |
| @@ -142,26 +142,28 @@ elf_placedynexec(struct lwp *l, struct e | | | @@ -142,26 +142,28 @@ elf_placedynexec(struct lwp *l, struct e |
142 | delta = PAX_ASLR_DELTA(r, l2, PAX_ASLR_DELTA_EXEC_LEN); | | 142 | delta = PAX_ASLR_DELTA(r, l2, PAX_ASLR_DELTA_EXEC_LEN); |
143 | offset = ELF_TRUNC(delta, pax_align) + PAGE_SIZE; | | 143 | offset = ELF_TRUNC(delta, pax_align) + PAGE_SIZE; |
144 | #ifdef PAX_ASLR_DEBUG | | 144 | #ifdef PAX_ASLR_DEBUG |
145 | uprintf("r=0x%x l2=0x%zx PGSHIFT=0x%x Delta=0x%zx\n", r, l2, | | 145 | uprintf("r=0x%x l2=0x%zx PGSHIFT=0x%x Delta=0x%zx\n", r, l2, |
146 | PGSHIFT, delta); | | 146 | PGSHIFT, delta); |
147 | uprintf("pax offset=0x%llx entry=0x%llx\n", | | 147 | uprintf("pax offset=0x%llx entry=0x%llx\n", |
148 | (unsigned long long)offset, | | 148 | (unsigned long long)offset, |
149 | (unsigned long long)eh->e_entry); | | 149 | (unsigned long long)eh->e_entry); |
150 | #endif /* PAX_ASLR_DEBUG */ | | 150 | #endif /* PAX_ASLR_DEBUG */ |
151 | } else | | 151 | } else |
152 | #endif /* PAX_ASLR */ | | 152 | #endif /* PAX_ASLR */ |
153 | offset = MAX(align, PAGE_SIZE); | | 153 | offset = MAX(align, PAGE_SIZE); |
154 | | | 154 | |
| | | 155 | offset += epp->ep_vm_minaddr; |
| | | 156 | |
155 | for (i = 0; i < eh->e_phnum; i++) | | 157 | for (i = 0; i < eh->e_phnum; i++) |
156 | ph[i].p_vaddr += offset; | | 158 | ph[i].p_vaddr += offset; |
157 | eh->e_entry += offset; | | 159 | eh->e_entry += offset; |
158 | } | | 160 | } |
159 | | | 161 | |
160 | /* | | 162 | /* |
161 | * Copy arguments onto the stack in the normal way, but add some | | 163 | * Copy arguments onto the stack in the normal way, but add some |
162 | * extra information in case of dynamic binding. | | 164 | * extra information in case of dynamic binding. |
163 | */ | | 165 | */ |
164 | int | | 166 | int |
165 | elf_copyargs(struct lwp *l, struct exec_package *pack, | | 167 | elf_copyargs(struct lwp *l, struct exec_package *pack, |
166 | struct ps_strings *arginfo, char **stackp, void *argp) | | 168 | struct ps_strings *arginfo, char **stackp, void *argp) |
167 | { | | 169 | { |