exec_elf.c revision 1.35 1 1.35 matt /* $NetBSD: exec_elf.c,v 1.35 2012/02/03 20:11:54 matt Exp $ */
2 1.10 ad
3 1.10 ad /*-
4 1.10 ad * Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc.
5 1.10 ad * All rights reserved.
6 1.10 ad *
7 1.10 ad * This code is derived from software contributed to The NetBSD Foundation
8 1.10 ad * by Christos Zoulas.
9 1.10 ad *
10 1.10 ad * Redistribution and use in source and binary forms, with or without
11 1.10 ad * modification, are permitted provided that the following conditions
12 1.10 ad * are met:
13 1.10 ad * 1. Redistributions of source code must retain the above copyright
14 1.10 ad * notice, this list of conditions and the following disclaimer.
15 1.10 ad * 2. Redistributions in binary form must reproduce the above copyright
16 1.10 ad * notice, this list of conditions and the following disclaimer in the
17 1.10 ad * documentation and/or other materials provided with the distribution.
18 1.10 ad *
19 1.10 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.10 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.10 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.10 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.10 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.10 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.10 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.10 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.10 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.10 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.10 ad * POSSIBILITY OF SUCH DAMAGE.
30 1.10 ad */
31 1.1 fvdl
32 1.1 fvdl /*
33 1.10 ad * Copyright (c) 1996 Christopher G. Demetriou
34 1.1 fvdl * All rights reserved.
35 1.1 fvdl *
36 1.1 fvdl * Redistribution and use in source and binary forms, with or without
37 1.1 fvdl * modification, are permitted provided that the following conditions
38 1.1 fvdl * are met:
39 1.1 fvdl * 1. Redistributions of source code must retain the above copyright
40 1.1 fvdl * notice, this list of conditions and the following disclaimer.
41 1.1 fvdl * 2. Redistributions in binary form must reproduce the above copyright
42 1.1 fvdl * notice, this list of conditions and the following disclaimer in the
43 1.1 fvdl * documentation and/or other materials provided with the distribution.
44 1.1 fvdl * 3. The name of the author may not be used to endorse or promote products
45 1.1 fvdl * derived from this software without specific prior written permission
46 1.1 fvdl *
47 1.1 fvdl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
48 1.1 fvdl * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 1.1 fvdl * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 1.1 fvdl * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
51 1.1 fvdl * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52 1.1 fvdl * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53 1.1 fvdl * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54 1.1 fvdl * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55 1.1 fvdl * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
56 1.1 fvdl * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 1.1 fvdl */
58 1.1 fvdl
59 1.10 ad #include <sys/cdefs.h>
60 1.35 matt __KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.35 2012/02/03 20:11:54 matt Exp $");
61 1.10 ad
62 1.10 ad #ifdef _KERNEL_OPT
63 1.10 ad #include "opt_pax.h"
64 1.10 ad #endif /* _KERNEL_OPT */
65 1.10 ad
66 1.1 fvdl #include <sys/param.h>
67 1.1 fvdl #include <sys/proc.h>
68 1.10 ad #include <sys/kmem.h>
69 1.1 fvdl #include <sys/namei.h>
70 1.1 fvdl #include <sys/vnode.h>
71 1.1 fvdl #include <sys/exec.h>
72 1.1 fvdl #include <sys/exec_elf.h>
73 1.8 christos #include <sys/syscall.h>
74 1.8 christos #include <sys/signalvar.h>
75 1.10 ad #include <sys/mount.h>
76 1.10 ad #include <sys/stat.h>
77 1.10 ad #include <sys/kauth.h>
78 1.10 ad #include <sys/bitops.h>
79 1.33 tls #include <sys/cprng.h>
80 1.10 ad
81 1.10 ad #include <sys/cpu.h>
82 1.10 ad #include <machine/reg.h>
83 1.1 fvdl
84 1.10 ad #include <compat/common/compat_util.h>
85 1.1 fvdl
86 1.10 ad #include <sys/pax.h>
87 1.1 fvdl
88 1.10 ad extern struct emul emul_netbsd;
89 1.1 fvdl
90 1.10 ad #define elf_check_header ELFNAME(check_header)
91 1.10 ad #define elf_copyargs ELFNAME(copyargs)
92 1.10 ad #define elf_load_file ELFNAME(load_file)
93 1.10 ad #define elf_load_psection ELFNAME(load_psection)
94 1.10 ad #define exec_elf_makecmds ELFNAME2(exec,makecmds)
95 1.10 ad #define netbsd_elf_signature ELFNAME2(netbsd,signature)
96 1.10 ad #define netbsd_elf_probe ELFNAME2(netbsd,probe)
97 1.10 ad #define coredump ELFNAMEEND(coredump)
98 1.35 matt #define elf_free_emul_arg ELFNAME(free_emul_arg)
99 1.1 fvdl
100 1.10 ad int elf_load_file(struct lwp *, struct exec_package *, char *,
101 1.10 ad struct exec_vmcmd_set *, u_long *, struct elf_args *, Elf_Addr *);
102 1.10 ad void elf_load_psection(struct exec_vmcmd_set *, struct vnode *,
103 1.10 ad const Elf_Phdr *, Elf_Addr *, u_long *, int *, int);
104 1.6 christos
105 1.10 ad int netbsd_elf_signature(struct lwp *, struct exec_package *, Elf_Ehdr *);
106 1.10 ad int netbsd_elf_probe(struct lwp *, struct exec_package *, void *, char *,
107 1.10 ad vaddr_t *);
108 1.1 fvdl
109 1.35 matt static void elf_free_emul_arg(void *);
110 1.35 matt
111 1.10 ad /* round up and down to page boundaries. */
112 1.10 ad #define ELF_ROUND(a, b) (((a) + (b) - 1) & ~((b) - 1))
113 1.10 ad #define ELF_TRUNC(a, b) ((a) & ~((b) - 1))
114 1.1 fvdl
115 1.15 christos /*
116 1.15 christos * Arbitrary limits to avoid DoS for excessive memory allocation.
117 1.15 christos */
118 1.15 christos #define MAXPHNUM 128
119 1.15 christos #define MAXSHNUM 32768
120 1.15 christos #define MAXNOTESIZE 1024
121 1.1 fvdl
122 1.10 ad static void
123 1.16 christos elf_placedynexec(struct lwp *l, struct exec_package *epp, Elf_Ehdr *eh,
124 1.10 ad Elf_Phdr *ph)
125 1.10 ad {
126 1.19 drochner Elf_Addr align, offset;
127 1.19 drochner int i;
128 1.19 drochner
129 1.19 drochner for (align = i = 0; i < eh->e_phnum; i++)
130 1.19 drochner if (ph[i].p_type == PT_LOAD && ph[i].p_align > align)
131 1.19 drochner align = ph[i].p_align;
132 1.10 ad
133 1.16 christos #ifdef PAX_ASLR
134 1.15 christos if (pax_aslr_active(l)) {
135 1.15 christos size_t pax_align, l2, delta;
136 1.15 christos uint32_t r;
137 1.10 ad
138 1.19 drochner pax_align = align;
139 1.10 ad
140 1.33 tls r = cprng_fast32();
141 1.8 christos
142 1.15 christos if (pax_align == 0)
143 1.15 christos pax_align = PGSHIFT;
144 1.15 christos l2 = ilog2(pax_align);
145 1.15 christos delta = PAX_ASLR_DELTA(r, l2, PAX_ASLR_DELTA_EXEC_LEN);
146 1.16 christos offset = ELF_TRUNC(delta, pax_align) + PAGE_SIZE;
147 1.17 christos #ifdef PAX_ASLR_DEBUG
148 1.18 christos uprintf("r=0x%x l2=0x%zx PGSHIFT=0x%x Delta=0x%zx\n", r, l2,
149 1.18 christos PGSHIFT, delta);
150 1.20 christos uprintf("pax offset=0x%llx entry=0x%llx\n",
151 1.20 christos (unsigned long long)offset,
152 1.20 christos (unsigned long long)eh->e_entry);
153 1.17 christos #endif /* PAX_ASLR_DEBUG */
154 1.15 christos } else
155 1.16 christos #endif /* PAX_ASLR */
156 1.19 drochner offset = MAX(align, PAGE_SIZE);
157 1.10 ad
158 1.32 reinoud offset += epp->ep_vm_minaddr;
159 1.32 reinoud
160 1.10 ad for (i = 0; i < eh->e_phnum; i++)
161 1.18 christos ph[i].p_vaddr += offset;
162 1.16 christos eh->e_entry += offset;
163 1.10 ad }
164 1.8 christos
165 1.8 christos /*
166 1.1 fvdl * Copy arguments onto the stack in the normal way, but add some
167 1.1 fvdl * extra information in case of dynamic binding.
168 1.1 fvdl */
169 1.10 ad int
170 1.10 ad elf_copyargs(struct lwp *l, struct exec_package *pack,
171 1.10 ad struct ps_strings *arginfo, char **stackp, void *argp)
172 1.1 fvdl {
173 1.10 ad size_t len, vlen;
174 1.10 ad AuxInfo ai[ELF_AUX_ENTRIES], *a, *execname;
175 1.1 fvdl struct elf_args *ap;
176 1.10 ad int error;
177 1.1 fvdl
178 1.10 ad if ((error = copyargs(l, pack, arginfo, stackp, argp)) != 0)
179 1.10 ad return error;
180 1.10 ad
181 1.10 ad a = ai;
182 1.10 ad execname = NULL;
183 1.1 fvdl
184 1.1 fvdl /*
185 1.1 fvdl * Push extra arguments on the stack needed by dynamically
186 1.1 fvdl * linked binaries
187 1.1 fvdl */
188 1.10 ad if ((ap = (struct elf_args *)pack->ep_emul_arg)) {
189 1.10 ad struct vattr *vap = pack->ep_vap;
190 1.10 ad
191 1.10 ad a->a_type = AT_PHDR;
192 1.10 ad a->a_v = ap->arg_phaddr;
193 1.10 ad a++;
194 1.10 ad
195 1.10 ad a->a_type = AT_PHENT;
196 1.10 ad a->a_v = ap->arg_phentsize;
197 1.10 ad a++;
198 1.10 ad
199 1.10 ad a->a_type = AT_PHNUM;
200 1.10 ad a->a_v = ap->arg_phnum;
201 1.10 ad a++;
202 1.1 fvdl
203 1.10 ad a->a_type = AT_PAGESZ;
204 1.10 ad a->a_v = PAGE_SIZE;
205 1.1 fvdl a++;
206 1.1 fvdl
207 1.10 ad a->a_type = AT_BASE;
208 1.10 ad a->a_v = ap->arg_interp;
209 1.1 fvdl a++;
210 1.1 fvdl
211 1.10 ad a->a_type = AT_FLAGS;
212 1.10 ad a->a_v = 0;
213 1.1 fvdl a++;
214 1.1 fvdl
215 1.10 ad a->a_type = AT_ENTRY;
216 1.10 ad a->a_v = ap->arg_entry;
217 1.1 fvdl a++;
218 1.1 fvdl
219 1.10 ad a->a_type = AT_EUID;
220 1.10 ad if (vap->va_mode & S_ISUID)
221 1.10 ad a->a_v = vap->va_uid;
222 1.10 ad else
223 1.10 ad a->a_v = kauth_cred_geteuid(l->l_cred);
224 1.1 fvdl a++;
225 1.1 fvdl
226 1.10 ad a->a_type = AT_RUID;
227 1.10 ad a->a_v = kauth_cred_getuid(l->l_cred);
228 1.1 fvdl a++;
229 1.1 fvdl
230 1.10 ad a->a_type = AT_EGID;
231 1.10 ad if (vap->va_mode & S_ISGID)
232 1.10 ad a->a_v = vap->va_gid;
233 1.10 ad else
234 1.10 ad a->a_v = kauth_cred_getegid(l->l_cred);
235 1.1 fvdl a++;
236 1.1 fvdl
237 1.10 ad a->a_type = AT_RGID;
238 1.10 ad a->a_v = kauth_cred_getgid(l->l_cred);
239 1.1 fvdl a++;
240 1.1 fvdl
241 1.10 ad if (pack->ep_path) {
242 1.10 ad execname = a;
243 1.10 ad a->a_type = AT_SUN_EXECNAME;
244 1.10 ad a++;
245 1.10 ad }
246 1.10 ad
247 1.35 matt exec_free_emul_arg(pack);
248 1.1 fvdl }
249 1.10 ad
250 1.10 ad a->a_type = AT_NULL;
251 1.10 ad a->a_v = 0;
252 1.10 ad a++;
253 1.10 ad
254 1.10 ad vlen = (a - ai) * sizeof(AuxInfo);
255 1.10 ad
256 1.10 ad if (execname) {
257 1.10 ad char *path = pack->ep_path;
258 1.10 ad execname->a_v = (uintptr_t)(*stackp + vlen);
259 1.10 ad len = strlen(path) + 1;
260 1.10 ad if ((error = copyout(path, (*stackp + vlen), len)) != 0)
261 1.10 ad return error;
262 1.10 ad len = ALIGN(len);
263 1.10 ad } else
264 1.10 ad len = 0;
265 1.10 ad
266 1.10 ad if ((error = copyout(ai, *stackp, vlen)) != 0)
267 1.10 ad return error;
268 1.10 ad *stackp += vlen + len;
269 1.10 ad
270 1.10 ad return 0;
271 1.1 fvdl }
272 1.1 fvdl
273 1.1 fvdl /*
274 1.1 fvdl * elf_check_header():
275 1.1 fvdl *
276 1.1 fvdl * Check header for validity; return 0 of ok ENOEXEC if error
277 1.1 fvdl */
278 1.1 fvdl int
279 1.10 ad elf_check_header(Elf_Ehdr *eh, int type)
280 1.1 fvdl {
281 1.3 thorpej
282 1.10 ad if (memcmp(eh->e_ident, ELFMAG, SELFMAG) != 0 ||
283 1.10 ad eh->e_ident[EI_CLASS] != ELFCLASS)
284 1.1 fvdl return ENOEXEC;
285 1.1 fvdl
286 1.1 fvdl switch (eh->e_machine) {
287 1.10 ad
288 1.10 ad ELFDEFNNAME(MACHDEP_ID_CASES)
289 1.1 fvdl
290 1.1 fvdl default:
291 1.1 fvdl return ENOEXEC;
292 1.1 fvdl }
293 1.1 fvdl
294 1.10 ad if (ELF_EHDR_FLAGS_OK(eh) == 0)
295 1.10 ad return ENOEXEC;
296 1.10 ad
297 1.1 fvdl if (eh->e_type != type)
298 1.1 fvdl return ENOEXEC;
299 1.1 fvdl
300 1.15 christos if (eh->e_shnum > MAXSHNUM || eh->e_phnum > MAXPHNUM)
301 1.10 ad return ENOEXEC;
302 1.10 ad
303 1.1 fvdl return 0;
304 1.1 fvdl }
305 1.1 fvdl
306 1.1 fvdl /*
307 1.1 fvdl * elf_load_psection():
308 1.10 ad *
309 1.1 fvdl * Load a psection at the appropriate address
310 1.1 fvdl */
311 1.10 ad void
312 1.10 ad elf_load_psection(struct exec_vmcmd_set *vcset, struct vnode *vp,
313 1.10 ad const Elf_Phdr *ph, Elf_Addr *addr, u_long *size, int *prot, int flags)
314 1.1 fvdl {
315 1.10 ad u_long msize, psize, rm, rf;
316 1.1 fvdl long diff, offset;
317 1.1 fvdl
318 1.1 fvdl /*
319 1.10 ad * If the user specified an address, then we load there.
320 1.10 ad */
321 1.10 ad if (*addr == ELFDEFNNAME(NO_ADDR))
322 1.10 ad *addr = ph->p_vaddr;
323 1.10 ad
324 1.10 ad if (ph->p_align > 1) {
325 1.10 ad /*
326 1.10 ad * Make sure we are virtually aligned as we are supposed to be.
327 1.10 ad */
328 1.10 ad diff = ph->p_vaddr - ELF_TRUNC(ph->p_vaddr, ph->p_align);
329 1.10 ad KASSERT(*addr - diff == ELF_TRUNC(*addr, ph->p_align));
330 1.10 ad /*
331 1.10 ad * But make sure to not map any pages before the start of the
332 1.10 ad * psection by limiting the difference to within a page.
333 1.10 ad */
334 1.10 ad diff &= PAGE_MASK;
335 1.10 ad } else
336 1.10 ad diff = 0;
337 1.1 fvdl
338 1.10 ad *prot |= (ph->p_flags & PF_R) ? VM_PROT_READ : 0;
339 1.10 ad *prot |= (ph->p_flags & PF_W) ? VM_PROT_WRITE : 0;
340 1.10 ad *prot |= (ph->p_flags & PF_X) ? VM_PROT_EXECUTE : 0;
341 1.1 fvdl
342 1.10 ad /*
343 1.10 ad * Adjust everything so it all starts on a page boundary.
344 1.10 ad */
345 1.10 ad *addr -= diff;
346 1.1 fvdl offset = ph->p_offset - diff;
347 1.1 fvdl *size = ph->p_filesz + diff;
348 1.1 fvdl msize = ph->p_memsz + diff;
349 1.1 fvdl
350 1.10 ad if (ph->p_align >= PAGE_SIZE) {
351 1.10 ad if ((ph->p_flags & PF_W) != 0) {
352 1.10 ad /*
353 1.10 ad * Because the pagedvn pager can't handle zero fill
354 1.10 ad * of the last data page if it's not page aligned we
355 1.10 ad * map the last page readvn.
356 1.10 ad */
357 1.10 ad psize = trunc_page(*size);
358 1.10 ad } else {
359 1.10 ad psize = round_page(*size);
360 1.10 ad }
361 1.10 ad } else {
362 1.10 ad psize = *size;
363 1.10 ad }
364 1.10 ad
365 1.10 ad if (psize > 0) {
366 1.10 ad NEW_VMCMD2(vcset, ph->p_align < PAGE_SIZE ?
367 1.10 ad vmcmd_map_readvn : vmcmd_map_pagedvn, psize, *addr, vp,
368 1.10 ad offset, *prot, flags);
369 1.10 ad flags &= VMCMD_RELATIVE;
370 1.10 ad }
371 1.10 ad if (psize < *size) {
372 1.10 ad NEW_VMCMD2(vcset, vmcmd_map_readvn, *size - psize,
373 1.10 ad *addr + psize, vp, offset + psize, *prot, flags);
374 1.10 ad }
375 1.1 fvdl
376 1.1 fvdl /*
377 1.10 ad * Check if we need to extend the size of the segment (does
378 1.10 ad * bss extend page the next page boundary)?
379 1.10 ad */
380 1.1 fvdl rm = round_page(*addr + msize);
381 1.1 fvdl rf = round_page(*addr + *size);
382 1.1 fvdl
383 1.1 fvdl if (rm != rf) {
384 1.10 ad NEW_VMCMD2(vcset, vmcmd_map_zero, rm - rf, rf, NULLVP,
385 1.10 ad 0, *prot, flags & VMCMD_RELATIVE);
386 1.1 fvdl *size = msize;
387 1.1 fvdl }
388 1.1 fvdl }
389 1.1 fvdl
390 1.1 fvdl /*
391 1.1 fvdl * elf_load_file():
392 1.1 fvdl *
393 1.1 fvdl * Load a file (interpreter/library) pointed to by path
394 1.1 fvdl * [stolen from coff_load_shlib()]. Made slightly generic
395 1.1 fvdl * so it might be used externally.
396 1.1 fvdl */
397 1.1 fvdl int
398 1.10 ad elf_load_file(struct lwp *l, struct exec_package *epp, char *path,
399 1.10 ad struct exec_vmcmd_set *vcset, u_long *entryoff, struct elf_args *ap,
400 1.10 ad Elf_Addr *last)
401 1.1 fvdl {
402 1.1 fvdl int error, i;
403 1.10 ad struct vnode *vp;
404 1.10 ad struct vattr attr;
405 1.10 ad Elf_Ehdr eh;
406 1.10 ad Elf_Phdr *ph = NULL;
407 1.10 ad const Elf_Phdr *ph0;
408 1.10 ad const Elf_Phdr *base_ph;
409 1.10 ad const Elf_Phdr *last_ph;
410 1.1 fvdl u_long phsize;
411 1.10 ad Elf_Addr addr = *last;
412 1.10 ad struct proc *p;
413 1.10 ad
414 1.10 ad p = l->l_proc;
415 1.10 ad
416 1.10 ad /*
417 1.10 ad * 1. open file
418 1.10 ad * 2. read filehdr
419 1.10 ad * 3. map text, data, and bss out of it using VM_*
420 1.10 ad */
421 1.10 ad vp = epp->ep_interp;
422 1.10 ad if (vp == NULL) {
423 1.10 ad error = emul_find_interp(l, epp, path);
424 1.10 ad if (error != 0)
425 1.10 ad return error;
426 1.10 ad vp = epp->ep_interp;
427 1.10 ad }
428 1.10 ad /* We'll tidy this ourselves - otherwise we have locking issues */
429 1.10 ad epp->ep_interp = NULL;
430 1.10 ad vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
431 1.1 fvdl
432 1.1 fvdl /*
433 1.10 ad * Similarly, if it's not marked as executable, or it's not a regular
434 1.10 ad * file, we don't allow it to be used.
435 1.10 ad */
436 1.10 ad if (vp->v_type != VREG) {
437 1.10 ad error = EACCES;
438 1.10 ad goto badunlock;
439 1.10 ad }
440 1.10 ad if ((error = VOP_ACCESS(vp, VEXEC, l->l_cred)) != 0)
441 1.10 ad goto badunlock;
442 1.10 ad
443 1.10 ad /* get attributes */
444 1.10 ad if ((error = VOP_GETATTR(vp, &attr, l->l_cred)) != 0)
445 1.10 ad goto badunlock;
446 1.10 ad
447 1.10 ad /*
448 1.10 ad * Check mount point. Though we're not trying to exec this binary,
449 1.10 ad * we will be executing code from it, so if the mount point
450 1.10 ad * disallows execution or set-id-ness, we punt or kill the set-id.
451 1.10 ad */
452 1.10 ad if (vp->v_mount->mnt_flag & MNT_NOEXEC) {
453 1.10 ad error = EACCES;
454 1.10 ad goto badunlock;
455 1.1 fvdl }
456 1.10 ad if (vp->v_mount->mnt_flag & MNT_NOSUID)
457 1.10 ad epp->ep_vap->va_mode &= ~(S_ISUID | S_ISGID);
458 1.10 ad
459 1.10 ad #ifdef notyet /* XXX cgd 960926 */
460 1.10 ad XXX cgd 960926: (maybe) VOP_OPEN it (and VOP_CLOSE in copyargs?)
461 1.28 pooka
462 1.28 pooka XXXps: this problem will make it impossible to use an interpreter
463 1.28 pooka from a file system which actually does something in VOP_OPEN
464 1.10 ad #endif
465 1.10 ad
466 1.10 ad error = vn_marktext(vp);
467 1.10 ad if (error)
468 1.10 ad goto badunlock;
469 1.10 ad
470 1.23 hannken VOP_UNLOCK(vp);
471 1.10 ad
472 1.10 ad if ((error = exec_read_from(l, vp, 0, &eh, sizeof(eh))) != 0)
473 1.10 ad goto bad;
474 1.10 ad
475 1.10 ad if ((error = elf_check_header(&eh, ET_DYN)) != 0)
476 1.1 fvdl goto bad;
477 1.1 fvdl
478 1.10 ad if (eh.e_phnum > MAXPHNUM || eh.e_phnum == 0) {
479 1.10 ad error = ENOEXEC;
480 1.1 fvdl goto bad;
481 1.10 ad }
482 1.1 fvdl
483 1.10 ad phsize = eh.e_phnum * sizeof(Elf_Phdr);
484 1.10 ad ph = kmem_alloc(phsize, KM_SLEEP);
485 1.1 fvdl
486 1.10 ad if ((error = exec_read_from(l, vp, eh.e_phoff, ph, phsize)) != 0)
487 1.1 fvdl goto bad;
488 1.1 fvdl
489 1.10 ad #ifdef ELF_INTERP_NON_RELOCATABLE
490 1.10 ad /*
491 1.10 ad * Evil hack: Only MIPS should be non-relocatable, and the
492 1.10 ad * psections should have a high address (typically 0x5ffe0000).
493 1.10 ad * If it's now relocatable, it should be linked at 0 and the
494 1.10 ad * psections should have zeros in the upper part of the address.
495 1.10 ad * Otherwise, force the load at the linked address.
496 1.10 ad */
497 1.10 ad if (*last == ELF_LINK_ADDR && (ph->p_vaddr & 0xffff0000) == 0)
498 1.10 ad *last = ELFDEFNNAME(NO_ADDR);
499 1.10 ad #endif
500 1.10 ad
501 1.10 ad /*
502 1.10 ad * If no position to load the interpreter was set by a probe
503 1.10 ad * function, pick the same address that a non-fixed mmap(0, ..)
504 1.10 ad * would (i.e. something safely out of the way).
505 1.10 ad */
506 1.10 ad if (*last == ELFDEFNNAME(NO_ADDR)) {
507 1.10 ad u_long limit = 0;
508 1.10 ad /*
509 1.10 ad * Find the start and ending addresses of the psections to
510 1.10 ad * be loaded. This will give us the size.
511 1.10 ad */
512 1.10 ad for (i = 0, ph0 = ph, base_ph = NULL; i < eh.e_phnum;
513 1.10 ad i++, ph0++) {
514 1.10 ad if (ph0->p_type == PT_LOAD) {
515 1.10 ad u_long psize = ph0->p_vaddr + ph0->p_memsz;
516 1.10 ad if (base_ph == NULL)
517 1.10 ad base_ph = ph0;
518 1.10 ad if (psize > limit)
519 1.10 ad limit = psize;
520 1.10 ad }
521 1.10 ad }
522 1.10 ad
523 1.10 ad if (base_ph == NULL) {
524 1.10 ad error = ENOEXEC;
525 1.10 ad goto bad;
526 1.10 ad }
527 1.10 ad
528 1.10 ad /*
529 1.10 ad * Now compute the size and load address.
530 1.10 ad */
531 1.10 ad addr = (*epp->ep_esch->es_emul->e_vm_default_addr)(p,
532 1.10 ad epp->ep_daddr,
533 1.10 ad round_page(limit) - trunc_page(base_ph->p_vaddr));
534 1.10 ad } else
535 1.10 ad addr = *last; /* may be ELF_LINK_ADDR */
536 1.10 ad
537 1.1 fvdl /*
538 1.10 ad * Load all the necessary sections
539 1.10 ad */
540 1.10 ad for (i = 0, ph0 = ph, base_ph = NULL, last_ph = NULL;
541 1.10 ad i < eh.e_phnum; i++, ph0++) {
542 1.10 ad switch (ph0->p_type) {
543 1.10 ad case PT_LOAD: {
544 1.10 ad u_long size;
545 1.10 ad int prot = 0;
546 1.10 ad int flags;
547 1.10 ad
548 1.10 ad if (base_ph == NULL) {
549 1.10 ad /*
550 1.10 ad * First encountered psection is always the
551 1.10 ad * base psection. Make sure it's aligned
552 1.10 ad * properly (align down for topdown and align
553 1.10 ad * upwards for not topdown).
554 1.10 ad */
555 1.10 ad base_ph = ph0;
556 1.10 ad flags = VMCMD_BASE;
557 1.10 ad if (addr == ELF_LINK_ADDR)
558 1.10 ad addr = ph0->p_vaddr;
559 1.10 ad if (p->p_vmspace->vm_map.flags & VM_MAP_TOPDOWN)
560 1.10 ad addr = ELF_TRUNC(addr, ph0->p_align);
561 1.10 ad else
562 1.10 ad addr = ELF_ROUND(addr, ph0->p_align);
563 1.10 ad } else {
564 1.10 ad u_long limit = round_page(last_ph->p_vaddr
565 1.10 ad + last_ph->p_memsz);
566 1.10 ad u_long base = trunc_page(ph0->p_vaddr);
567 1.10 ad
568 1.10 ad /*
569 1.10 ad * If there is a gap in between the psections,
570 1.10 ad * map it as inaccessible so nothing else
571 1.10 ad * mmap'ed will be placed there.
572 1.10 ad */
573 1.10 ad if (limit != base) {
574 1.10 ad NEW_VMCMD2(vcset, vmcmd_map_zero,
575 1.10 ad base - limit,
576 1.10 ad limit - base_ph->p_vaddr, NULLVP,
577 1.10 ad 0, VM_PROT_NONE, VMCMD_RELATIVE);
578 1.10 ad }
579 1.1 fvdl
580 1.10 ad addr = ph0->p_vaddr - base_ph->p_vaddr;
581 1.10 ad flags = VMCMD_RELATIVE;
582 1.10 ad }
583 1.10 ad last_ph = ph0;
584 1.10 ad elf_load_psection(vcset, vp, &ph[i], &addr,
585 1.10 ad &size, &prot, flags);
586 1.10 ad /*
587 1.10 ad * If entry is within this psection then this
588 1.10 ad * must contain the .text section. *entryoff is
589 1.10 ad * relative to the base psection.
590 1.10 ad */
591 1.10 ad if (eh.e_entry >= ph0->p_vaddr &&
592 1.10 ad eh.e_entry < (ph0->p_vaddr + size)) {
593 1.10 ad *entryoff = eh.e_entry - base_ph->p_vaddr;
594 1.1 fvdl }
595 1.1 fvdl addr += size;
596 1.1 fvdl break;
597 1.10 ad }
598 1.1 fvdl
599 1.10 ad case PT_DYNAMIC:
600 1.10 ad case PT_PHDR:
601 1.10 ad break;
602 1.10 ad
603 1.10 ad case PT_NOTE:
604 1.1 fvdl break;
605 1.1 fvdl
606 1.1 fvdl default:
607 1.1 fvdl break;
608 1.1 fvdl }
609 1.1 fvdl }
610 1.1 fvdl
611 1.10 ad kmem_free(ph, phsize);
612 1.10 ad /*
613 1.10 ad * This value is ignored if TOPDOWN.
614 1.10 ad */
615 1.10 ad *last = addr;
616 1.10 ad vrele(vp);
617 1.10 ad return 0;
618 1.10 ad
619 1.10 ad badunlock:
620 1.23 hannken VOP_UNLOCK(vp);
621 1.10 ad
622 1.1 fvdl bad:
623 1.1 fvdl if (ph != NULL)
624 1.10 ad kmem_free(ph, phsize);
625 1.10 ad #ifdef notyet /* XXX cgd 960926 */
626 1.10 ad (maybe) VOP_CLOSE it
627 1.10 ad #endif
628 1.10 ad vrele(vp);
629 1.1 fvdl return error;
630 1.1 fvdl }
631 1.1 fvdl
632 1.1 fvdl /*
633 1.1 fvdl * exec_elf_makecmds(): Prepare an Elf binary's exec package
634 1.1 fvdl *
635 1.1 fvdl * First, set of the various offsets/lengths in the exec package.
636 1.1 fvdl *
637 1.1 fvdl * Then, mark the text image busy (so it can be demand paged) or error
638 1.1 fvdl * out if this is not possible. Finally, set up vmcmds for the
639 1.1 fvdl * text, data, bss, and stack segments.
640 1.1 fvdl */
641 1.1 fvdl int
642 1.10 ad exec_elf_makecmds(struct lwp *l, struct exec_package *epp)
643 1.10 ad {
644 1.10 ad Elf_Ehdr *eh = epp->ep_hdr;
645 1.10 ad Elf_Phdr *ph, *pp;
646 1.26 chs Elf_Addr phdr = 0, computed_phdr = 0, pos = 0, end_text = 0;
647 1.10 ad int error, i, nload;
648 1.10 ad char *interp = NULL;
649 1.10 ad u_long phsize;
650 1.1 fvdl struct proc *p;
651 1.26 chs struct elf_args *ap = NULL;
652 1.10 ad bool is_dyn;
653 1.1 fvdl
654 1.10 ad if (epp->ep_hdrvalid < sizeof(Elf_Ehdr))
655 1.1 fvdl return ENOEXEC;
656 1.1 fvdl
657 1.10 ad is_dyn = elf_check_header(eh, ET_DYN) == 0;
658 1.10 ad /*
659 1.10 ad * XXX allow for executing shared objects. It seems silly
660 1.10 ad * but other ELF-based systems allow it as well.
661 1.10 ad */
662 1.10 ad if (elf_check_header(eh, ET_EXEC) != 0 && !is_dyn)
663 1.1 fvdl return ENOEXEC;
664 1.1 fvdl
665 1.10 ad if (eh->e_phnum > MAXPHNUM || eh->e_phnum == 0)
666 1.10 ad return ENOEXEC;
667 1.10 ad
668 1.10 ad error = vn_marktext(epp->ep_vp);
669 1.10 ad if (error)
670 1.10 ad return error;
671 1.10 ad
672 1.1 fvdl /*
673 1.10 ad * Allocate space to hold all the program headers, and read them
674 1.10 ad * from the file
675 1.10 ad */
676 1.10 ad p = l->l_proc;
677 1.10 ad phsize = eh->e_phnum * sizeof(Elf_Phdr);
678 1.10 ad ph = kmem_alloc(phsize, KM_SLEEP);
679 1.1 fvdl
680 1.10 ad if ((error = exec_read_from(l, epp->ep_vp, eh->e_phoff, ph, phsize)) !=
681 1.10 ad 0)
682 1.1 fvdl goto bad;
683 1.1 fvdl
684 1.10 ad epp->ep_taddr = epp->ep_tsize = ELFDEFNNAME(NO_ADDR);
685 1.10 ad epp->ep_daddr = epp->ep_dsize = ELFDEFNNAME(NO_ADDR);
686 1.1 fvdl
687 1.1 fvdl for (i = 0; i < eh->e_phnum; i++) {
688 1.1 fvdl pp = &ph[i];
689 1.10 ad if (pp->p_type == PT_INTERP) {
690 1.10 ad if (pp->p_filesz >= MAXPATHLEN) {
691 1.10 ad error = ENOEXEC;
692 1.1 fvdl goto bad;
693 1.10 ad }
694 1.10 ad interp = PNBUF_GET();
695 1.10 ad interp[0] = '\0';
696 1.10 ad if ((error = exec_read_from(l, epp->ep_vp,
697 1.10 ad pp->p_offset, interp, pp->p_filesz)) != 0)
698 1.1 fvdl goto bad;
699 1.1 fvdl break;
700 1.1 fvdl }
701 1.1 fvdl }
702 1.1 fvdl
703 1.1 fvdl /*
704 1.1 fvdl * On the same architecture, we may be emulating different systems.
705 1.10 ad * See which one will accept this executable.
706 1.1 fvdl *
707 1.1 fvdl * Probe functions would normally see if the interpreter (if any)
708 1.1 fvdl * exists. Emulation packages may possibly replace the interpreter in
709 1.10 ad * interp[] with a changed path (/emul/xxx/<path>).
710 1.1 fvdl */
711 1.10 ad pos = ELFDEFNNAME(NO_ADDR);
712 1.10 ad if (epp->ep_esch->u.elf_probe_func) {
713 1.10 ad vaddr_t startp = (vaddr_t)pos;
714 1.1 fvdl
715 1.10 ad error = (*epp->ep_esch->u.elf_probe_func)(l, epp, eh, interp,
716 1.10 ad &startp);
717 1.1 fvdl if (error)
718 1.1 fvdl goto bad;
719 1.10 ad pos = (Elf_Addr)startp;
720 1.1 fvdl }
721 1.1 fvdl
722 1.10 ad #if defined(PAX_MPROTECT) || defined(PAX_SEGVGUARD) || defined(PAX_ASLR)
723 1.10 ad p->p_pax = epp->ep_pax_flags;
724 1.10 ad #endif /* PAX_MPROTECT || PAX_SEGVGUARD || PAX_ASLR */
725 1.10 ad
726 1.13 drochner if (is_dyn)
727 1.16 christos elf_placedynexec(l, epp, eh, ph);
728 1.10 ad
729 1.1 fvdl /*
730 1.10 ad * Load all the necessary sections
731 1.10 ad */
732 1.4 fvdl for (i = nload = 0; i < eh->e_phnum; i++) {
733 1.10 ad Elf_Addr addr = ELFDEFNNAME(NO_ADDR);
734 1.10 ad u_long size = 0;
735 1.1 fvdl int prot = 0;
736 1.1 fvdl
737 1.1 fvdl pp = &ph[i];
738 1.1 fvdl
739 1.1 fvdl switch (ph[i].p_type) {
740 1.10 ad case PT_LOAD:
741 1.1 fvdl elf_load_psection(&epp->ep_vmcmds, epp->ep_vp,
742 1.10 ad &ph[i], &addr, &size, &prot, VMCMD_FIXED);
743 1.10 ad
744 1.4 fvdl /*
745 1.24 joerg * Consider this as text segment, if it is executable.
746 1.24 joerg * If there is more than one text segment, pick the
747 1.24 joerg * largest.
748 1.4 fvdl */
749 1.24 joerg if (ph[i].p_flags & PF_X) {
750 1.24 joerg if (epp->ep_taddr == ELFDEFNNAME(NO_ADDR) ||
751 1.24 joerg size > epp->ep_tsize) {
752 1.24 joerg epp->ep_taddr = addr;
753 1.24 joerg epp->ep_tsize = size;
754 1.10 ad }
755 1.25 joerg end_text = addr + size;
756 1.4 fvdl } else {
757 1.4 fvdl epp->ep_daddr = addr;
758 1.4 fvdl epp->ep_dsize = size;
759 1.4 fvdl }
760 1.26 chs if (ph[i].p_offset == 0) {
761 1.26 chs computed_phdr = ph[i].p_vaddr + eh->e_phoff;
762 1.26 chs }
763 1.1 fvdl break;
764 1.1 fvdl
765 1.10 ad case PT_SHLIB:
766 1.10 ad /* SCO has these sections. */
767 1.10 ad case PT_INTERP:
768 1.10 ad /* Already did this one. */
769 1.10 ad case PT_DYNAMIC:
770 1.10 ad break;
771 1.10 ad case PT_NOTE:
772 1.1 fvdl break;
773 1.10 ad case PT_PHDR:
774 1.4 fvdl /* Note address of program headers (in text segment) */
775 1.4 fvdl phdr = pp->p_vaddr;
776 1.7 christos break;
777 1.4 fvdl
778 1.1 fvdl default:
779 1.1 fvdl /*
780 1.10 ad * Not fatal; we don't need to understand everything.
781 1.1 fvdl */
782 1.1 fvdl break;
783 1.1 fvdl }
784 1.1 fvdl }
785 1.26 chs if (interp || (epp->ep_flags & EXEC_FORCEAUX) != 0) {
786 1.34 matt ap = kmem_alloc(sizeof(*ap), KM_SLEEP);
787 1.26 chs ap->arg_interp = (vaddr_t)NULL;
788 1.26 chs }
789 1.5 fvdl
790 1.24 joerg if (epp->ep_daddr == ELFDEFNNAME(NO_ADDR)) {
791 1.27 chs epp->ep_daddr = round_page(end_text);
792 1.25 joerg epp->ep_dsize = 0;
793 1.24 joerg }
794 1.24 joerg
795 1.5 fvdl /*
796 1.10 ad * Check if we found a dynamically linked binary and arrange to load
797 1.10 ad * its interpreter
798 1.5 fvdl */
799 1.10 ad if (interp) {
800 1.10 ad int j = epp->ep_vmcmds.evs_used;
801 1.10 ad u_long interp_offset;
802 1.1 fvdl
803 1.10 ad if ((error = elf_load_file(l, epp, interp,
804 1.10 ad &epp->ep_vmcmds, &interp_offset, ap, &pos)) != 0) {
805 1.1 fvdl goto bad;
806 1.1 fvdl }
807 1.10 ad ap->arg_interp = epp->ep_vmcmds.evs_cmds[j].ev_addr;
808 1.10 ad epp->ep_entry = ap->arg_interp + interp_offset;
809 1.26 chs PNBUF_PUT(interp);
810 1.26 chs } else
811 1.26 chs epp->ep_entry = eh->e_entry;
812 1.1 fvdl
813 1.26 chs if (ap) {
814 1.26 chs ap->arg_phaddr = phdr ? phdr : computed_phdr;
815 1.1 fvdl ap->arg_phentsize = eh->e_phentsize;
816 1.1 fvdl ap->arg_phnum = eh->e_phnum;
817 1.1 fvdl ap->arg_entry = eh->e_entry;
818 1.1 fvdl epp->ep_emul_arg = ap;
819 1.35 matt epp->ep_emul_arg_free = elf_free_emul_arg;
820 1.26 chs }
821 1.1 fvdl
822 1.8 christos #ifdef ELF_MAP_PAGE_ZERO
823 1.8 christos /* Dell SVR4 maps page zero, yeuch! */
824 1.10 ad NEW_VMCMD(&epp->ep_vmcmds, vmcmd_map_readvn, PAGE_SIZE, 0,
825 1.10 ad epp->ep_vp, 0, VM_PROT_READ);
826 1.8 christos #endif
827 1.10 ad kmem_free(ph, phsize);
828 1.10 ad return (*epp->ep_esch->es_setup_stack)(l, epp);
829 1.1 fvdl
830 1.1 fvdl bad:
831 1.10 ad if (interp)
832 1.10 ad PNBUF_PUT(interp);
833 1.35 matt exec_free_emul_arg(epp);
834 1.10 ad kmem_free(ph, phsize);
835 1.1 fvdl kill_vmcmds(&epp->ep_vmcmds);
836 1.10 ad return error;
837 1.10 ad }
838 1.10 ad
839 1.10 ad int
840 1.10 ad netbsd_elf_signature(struct lwp *l, struct exec_package *epp,
841 1.10 ad Elf_Ehdr *eh)
842 1.10 ad {
843 1.10 ad size_t i;
844 1.15 christos Elf_Shdr *sh;
845 1.15 christos Elf_Nhdr *np;
846 1.15 christos size_t shsize;
847 1.10 ad int error;
848 1.10 ad int isnetbsd = 0;
849 1.10 ad char *ndata;
850 1.10 ad
851 1.10 ad epp->ep_pax_flags = 0;
852 1.15 christos if (eh->e_shnum > MAXSHNUM || eh->e_shnum == 0)
853 1.10 ad return ENOEXEC;
854 1.10 ad
855 1.15 christos shsize = eh->e_shnum * sizeof(Elf_Shdr);
856 1.15 christos sh = kmem_alloc(shsize, KM_SLEEP);
857 1.15 christos error = exec_read_from(l, epp->ep_vp, eh->e_shoff, sh, shsize);
858 1.10 ad if (error)
859 1.10 ad goto out;
860 1.10 ad
861 1.15 christos np = kmem_alloc(MAXNOTESIZE, KM_SLEEP);
862 1.15 christos for (i = 0; i < eh->e_shnum; i++) {
863 1.15 christos Elf_Shdr *shp = &sh[i];
864 1.15 christos
865 1.15 christos if (shp->sh_type != SHT_NOTE ||
866 1.15 christos shp->sh_size > MAXNOTESIZE ||
867 1.15 christos shp->sh_size < sizeof(Elf_Nhdr) + ELF_NOTE_NETBSD_NAMESZ)
868 1.10 ad continue;
869 1.10 ad
870 1.15 christos error = exec_read_from(l, epp->ep_vp, shp->sh_offset, np,
871 1.15 christos shp->sh_size);
872 1.10 ad if (error)
873 1.15 christos continue;
874 1.10 ad
875 1.10 ad ndata = (char *)(np + 1);
876 1.10 ad switch (np->n_type) {
877 1.10 ad case ELF_NOTE_TYPE_NETBSD_TAG:
878 1.10 ad if (np->n_namesz != ELF_NOTE_NETBSD_NAMESZ ||
879 1.10 ad np->n_descsz != ELF_NOTE_NETBSD_DESCSZ ||
880 1.10 ad memcmp(ndata, ELF_NOTE_NETBSD_NAME,
881 1.10 ad ELF_NOTE_NETBSD_NAMESZ))
882 1.15 christos goto bad;
883 1.10 ad isnetbsd = 1;
884 1.10 ad break;
885 1.10 ad
886 1.10 ad case ELF_NOTE_TYPE_PAX_TAG:
887 1.10 ad if (np->n_namesz != ELF_NOTE_PAX_NAMESZ ||
888 1.10 ad np->n_descsz != ELF_NOTE_PAX_DESCSZ ||
889 1.10 ad memcmp(ndata, ELF_NOTE_PAX_NAME,
890 1.15 christos ELF_NOTE_PAX_NAMESZ)) {
891 1.15 christos bad:
892 1.30 christos /*
893 1.30 christos * Ignore GNU tags
894 1.30 christos */
895 1.30 christos if (np->n_namesz == ELF_NOTE_GNU_NAMESZ &&
896 1.30 christos memcmp(ndata, ELF_NOTE_GNU_NAME,
897 1.30 christos ELF_NOTE_GNU_NAMESZ) == 0)
898 1.30 christos break;
899 1.15 christos #ifdef DIAGNOSTIC
900 1.15 christos printf("%s: bad tag %d: "
901 1.15 christos "[%d %d, %d %d, %*.*s %*.*s]\n",
902 1.21 dholland epp->ep_kname,
903 1.18 christos np->n_type,
904 1.15 christos np->n_namesz, ELF_NOTE_PAX_NAMESZ,
905 1.15 christos np->n_descsz, ELF_NOTE_PAX_DESCSZ,
906 1.15 christos ELF_NOTE_PAX_NAMESZ,
907 1.15 christos ELF_NOTE_PAX_NAMESZ,
908 1.15 christos ndata,
909 1.15 christos ELF_NOTE_PAX_NAMESZ,
910 1.15 christos ELF_NOTE_PAX_NAMESZ,
911 1.15 christos ELF_NOTE_PAX_NAME);
912 1.15 christos #endif
913 1.15 christos continue;
914 1.15 christos }
915 1.10 ad (void)memcpy(&epp->ep_pax_flags,
916 1.10 ad ndata + ELF_NOTE_PAX_NAMESZ,
917 1.10 ad sizeof(epp->ep_pax_flags));
918 1.10 ad break;
919 1.10 ad
920 1.31 christos case ELF_NOTE_TYPE_SUSE_TAG:
921 1.31 christos break;
922 1.31 christos
923 1.10 ad default:
924 1.15 christos #ifdef DIAGNOSTIC
925 1.22 dholland printf("%s: unknown note type %d\n", epp->ep_kname,
926 1.15 christos np->n_type);
927 1.15 christos #endif
928 1.10 ad break;
929 1.10 ad }
930 1.10 ad }
931 1.15 christos kmem_free(np, MAXNOTESIZE);
932 1.10 ad
933 1.10 ad error = isnetbsd ? 0 : ENOEXEC;
934 1.10 ad out:
935 1.15 christos kmem_free(sh, shsize);
936 1.10 ad return error;
937 1.10 ad }
938 1.10 ad
939 1.10 ad int
940 1.10 ad netbsd_elf_probe(struct lwp *l, struct exec_package *epp, void *eh, char *itp,
941 1.10 ad vaddr_t *pos)
942 1.10 ad {
943 1.10 ad int error;
944 1.10 ad
945 1.10 ad if ((error = netbsd_elf_signature(l, epp, eh)) != 0)
946 1.10 ad return error;
947 1.12 matt #ifdef ELF_MD_PROBE_FUNC
948 1.12 matt if ((error = ELF_MD_PROBE_FUNC(l, epp, eh, itp, pos)) != 0)
949 1.12 matt return error;
950 1.12 matt #elif defined(ELF_INTERP_NON_RELOCATABLE)
951 1.10 ad *pos = ELF_LINK_ADDR;
952 1.10 ad #endif
953 1.29 joerg epp->ep_flags |= EXEC_FORCEAUX;
954 1.10 ad return 0;
955 1.1 fvdl }
956 1.35 matt
957 1.35 matt void
958 1.35 matt elf_free_emul_arg(void *arg)
959 1.35 matt {
960 1.35 matt struct elf_args *ap = arg;
961 1.35 matt KASSERT(ap != NULL);
962 1.35 matt kmem_free(ap, sizeof(*ap));
963 1.35 matt }
964