Home | History | Annotate | Line # | Download | only in freebsd
freebsd_exec_elf32.c revision 1.17.78.2
      1  1.17.78.1       tls /*	$NetBSD: freebsd_exec_elf32.c,v 1.17.78.2 2017/12/03 11:36:53 jdolecek Exp $	*/
      2        1.1  jdolecek 
      3        1.1  jdolecek /*
      4        1.1  jdolecek  * Copyright (c) 1993, 1994 Christopher G. Demetriou
      5        1.1  jdolecek  * All rights reserved.
      6        1.1  jdolecek  *
      7        1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
      8        1.1  jdolecek  * modification, are permitted provided that the following conditions
      9        1.1  jdolecek  * are met:
     10        1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     11        1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     12        1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     14        1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     15        1.1  jdolecek  * 3. All advertising materials mentioning features or use of this software
     16        1.1  jdolecek  *    must display the following acknowledgement:
     17        1.1  jdolecek  *      This product includes software developed by Christopher G. Demetriou.
     18        1.1  jdolecek  * 4. The name of the author may not be used to endorse or promote products
     19        1.1  jdolecek  *    derived from this software without specific prior written permission
     20        1.1  jdolecek  *
     21        1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22        1.1  jdolecek  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23        1.1  jdolecek  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24        1.1  jdolecek  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25        1.1  jdolecek  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26        1.1  jdolecek  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27        1.1  jdolecek  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28        1.1  jdolecek  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29        1.1  jdolecek  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30        1.1  jdolecek  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31        1.1  jdolecek  */
     32        1.6     lukem 
     33        1.6     lukem #include <sys/cdefs.h>
     34  1.17.78.1       tls __KERNEL_RCSID(0, "$NetBSD: freebsd_exec_elf32.c,v 1.17.78.2 2017/12/03 11:36:53 jdolecek Exp $");
     35        1.1  jdolecek 
     36        1.1  jdolecek #include <sys/param.h>
     37        1.1  jdolecek #include <sys/systm.h>
     38        1.1  jdolecek #include <sys/proc.h>
     39        1.1  jdolecek #include <sys/vnode.h>
     40        1.1  jdolecek #include <sys/exec.h>
     41        1.1  jdolecek #ifndef ELFSIZE
     42        1.1  jdolecek #  define ELFSIZE 32
     43        1.1  jdolecek #endif /* !ELFSIZE */
     44        1.1  jdolecek #include <sys/exec_elf.h>
     45        1.1  jdolecek 
     46        1.1  jdolecek #include <compat/freebsd/freebsd_exec.h>
     47        1.1  jdolecek #include <compat/common/compat_util.h>
     48        1.1  jdolecek 
     49  1.17.78.2  jdolecek #include <compat/freebsd/freebsd_machdep.h>
     50       1.13  christos 
     51        1.1  jdolecek int
     52  1.17.78.1       tls ELFNAME2(freebsd,probe)(struct lwp *l, struct exec_package *epp, void *veh,
     53  1.17.78.1       tls     char *itp, vaddr_t *pos)
     54        1.1  jdolecek {
     55        1.1  jdolecek 	int error;
     56        1.1  jdolecek 	Elf_Ehdr *eh = (Elf_Ehdr *) veh;
     57  1.17.78.1       tls 	static const char wantBrand[] = FREEBSD_ELF_BRAND_STRING;
     58  1.17.78.1       tls 	static const char wantInterp[] = FREEBSD_ELF_INTERP_PREFIX_STRING;
     59        1.1  jdolecek 
     60  1.17.78.1       tls 	/*
     61        1.8  jdolecek 	 * Insist that the executable have a brand, and that it be "FreeBSD".
     62        1.8  jdolecek 	 * Newer FreeBSD binaries have OSABI set to ELFOSABI_FREEBSD. This
     63        1.8  jdolecek 	 * is arguably broken, but they seem to think they need it, for
     64        1.8  jdolecek 	 * whatever reason.
     65        1.8  jdolecek 	 */
     66        1.7  christos #ifndef EI_BRAND
     67        1.7  christos #define EI_BRAND 8
     68        1.7  christos #endif
     69  1.17.78.1       tls 	if ((eh->e_ident[EI_BRAND] == '\0' ||
     70  1.17.78.1       tls 	     strcmp(&eh->e_ident[EI_BRAND], wantBrand) != 0) &&
     71  1.17.78.1       tls 		eh->e_ident[EI_OSABI] != ELFOSABI_FREEBSD)
     72        1.5  jdolecek 		return ENOEXEC;
     73        1.1  jdolecek 
     74       1.12  drochner 	if (itp) {
     75  1.17.78.1       tls 		if (strncmp(itp, wantInterp, sizeof(wantInterp) - 1))
     76  1.17.78.1       tls 			return ENOEXEC;
     77       1.17       dsl 		if ((error = emul_find_interp(l, epp, itp)))
     78        1.1  jdolecek 			return error;
     79        1.1  jdolecek 	}
     80        1.1  jdolecek 
     81  1.17.78.1       tls 	return 0;
     82        1.1  jdolecek }
     83