From 312b63cab3976ffcb3290a469bbf55b90da4559e Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Wed, 10 Feb 1999 08:07:21 +0000 Subject: branding support and freebsd elf --- sys/arch/i386/i386/trap.c | 7 ++--- sys/compat/freebsd/freebsd_exec.c | 57 ++++++++++++++++++++++++++++++++++++--- sys/compat/freebsd/freebsd_exec.h | 4 ++- sys/compat/linux/linux_exec.c | 8 ++++-- sys/kern/exec_elf.c | 25 ++++++++++++++--- sys/sys/exec_elf.h | 4 ++- 6 files changed, 91 insertions(+), 14 deletions(-) diff --git a/sys/arch/i386/i386/trap.c b/sys/arch/i386/i386/trap.c index 3e9d4d4be43..860fd63c6f0 100644 --- a/sys/arch/i386/i386/trap.c +++ b/sys/arch/i386/i386/trap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trap.c,v 1.27 1998/08/20 19:46:35 deraadt Exp $ */ +/* $OpenBSD: trap.c,v 1.28 1999/02/10 08:07:20 deraadt Exp $ */ /* $NetBSD: trap.c,v 1.95 1996/05/05 06:50:02 mycroft Exp $ */ #undef DEBUG @@ -82,7 +82,7 @@ extern struct emul emul_ibcs2; extern struct emul emul_linux_aout, emul_linux_elf; #endif #ifdef COMPAT_FREEBSD -extern struct emul emul_freebsd; +extern struct emul emul_aout_freebsd, emul_elf_freebsd; #endif #ifdef COMPAT_BSDOS extern struct emul emul_bsdos; @@ -604,7 +604,8 @@ syscall(frame) */ if (callp != sysent #ifdef COMPAT_FREEBSD - && p->p_emul != &emul_freebsd + && p->p_emul != &emul_aout_freebsd + && p->p_emul != &emul_elf_freebsd #endif #ifdef COMPAT_BSDOS && p->p_emul != &emul_bsdos diff --git a/sys/compat/freebsd/freebsd_exec.c b/sys/compat/freebsd/freebsd_exec.c index a152b17580f..f8307218d2c 100644 --- a/sys/compat/freebsd/freebsd_exec.c +++ b/sys/compat/freebsd/freebsd_exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: freebsd_exec.c,v 1.4 1996/08/31 09:24:00 pefo Exp $ */ +/* $OpenBSD: freebsd_exec.c,v 1.5 1999/02/10 08:07:19 deraadt Exp $ */ /* $NetBSD: freebsd_exec.c,v 1.2 1996/05/18 16:02:08 christos Exp $ */ /* @@ -39,16 +39,37 @@ #include #include #include +#include +#include #include #include #include +#include extern struct sysent freebsd_sysent[]; extern char *freebsd_syscallnames[]; -struct emul emul_freebsd = { +extern const char freebsd_emul_path[]; + +struct emul emul_aout_freebsd = { + "freebsd", + NULL, + freebsd_sendsig, + FREEBSD_SYS_syscall, + FREEBSD_SYS_MAXSYSCALL, + freebsd_sysent, + freebsd_syscallnames, + 0, + copyargs, + setregs, + NULL, + freebsd_sigcode, + freebsd_esigcode, +}; + +struct emul emul_elf_freebsd = { "freebsd", NULL, freebsd_sendsig, @@ -106,9 +127,39 @@ exec_freebsd_aout_makecmds(p, epp) break; } if (error == 0) - epp->ep_emul = &emul_freebsd; + epp->ep_emul = &emul_aout_freebsd; else kill_vmcmds(&epp->ep_vmcmds); return error; } + +int +freebsd_elf_probe(p, epp, itp, pos, os) + struct proc *p; + struct exec_package *epp; + char *itp; + u_long *pos; + u_int8_t *os; +{ + Elf32_Ehdr *eh = epp->ep_hdr; + char *bp, *brand; + int error; + size_t len; + + brand = elf_check_brand(eh); + if (brand == NULL || strcmp(brand, "FreeBSD")) + return (EINVAL); + if (itp[0]) { + if ((error = emul_find(p, NULL, freebsd_emul_path, itp, &bp, 0))) + return (error); + if ((error = copystr(bp, itp, MAXPATHLEN, &len))) + return (error); + free(bp, M_TEMP); + } + epp->ep_emul = &emul_elf_freebsd; + *pos = ELF32_NO_ADDR; + if (*os == OOS_NULL) + *os = OOS_FREEBSD; + return (0); +} diff --git a/sys/compat/freebsd/freebsd_exec.h b/sys/compat/freebsd/freebsd_exec.h index 6930a10f110..da8e3e50fde 100644 --- a/sys/compat/freebsd/freebsd_exec.h +++ b/sys/compat/freebsd/freebsd_exec.h @@ -1,4 +1,4 @@ -/* $OpenBSD: freebsd_exec.h,v 1.2 1996/08/02 20:34:45 niklas Exp $ */ +/* $OpenBSD: freebsd_exec.h,v 1.3 1999/02/10 08:07:19 deraadt Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -95,6 +95,8 @@ #define FREEBSD_AOUT_HDR_SIZE sizeof(struct exec) int exec_freebsd_aout_makecmds __P((struct proc *, struct exec_package *)); +int freebsd_elf_probe __P((struct proc *, struct exec_package *, char *, + u_long *, u_int8_t *)); extern char freebsd_sigcode[], freebsd_esigcode[]; diff --git a/sys/compat/linux/linux_exec.c b/sys/compat/linux/linux_exec.c index 5002aaa0acf..c14c75ebb0a 100644 --- a/sys/compat/linux/linux_exec.c +++ b/sys/compat/linux/linux_exec.c @@ -1,4 +1,4 @@ -/* $OpenBSD: linux_exec.c,v 1.9 1999/01/11 05:12:12 millert Exp $ */ +/* $OpenBSD: linux_exec.c,v 1.10 1999/02/10 08:07:20 deraadt Exp $ */ /* $NetBSD: linux_exec.c,v 1.13 1996/04/05 00:01:10 christos Exp $ */ /* @@ -374,10 +374,14 @@ linux_elf_probe(p, epp, itp, pos, os) u_long *pos; u_int8_t *os; { - char *bp; + Elf32_Ehdr *eh = epp->ep_hdr; + char *bp, *brand; int error; size_t len; + brand = elf_check_brand(eh); + if (brand && strcmp(brand, "Linux")) + return (EINVAL); if (itp[0]) { if ((error = emul_find(p, NULL, linux_emul_path, itp, &bp, 0))) return (error); diff --git a/sys/kern/exec_elf.c b/sys/kern/exec_elf.c index 6cd23955660..9045261c8e5 100644 --- a/sys/kern/exec_elf.c +++ b/sys/kern/exec_elf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_elf.c,v 1.23 1999/01/11 05:12:22 millert Exp $ */ +/* $OpenBSD: exec_elf.c,v 1.24 1999/02/10 08:07:20 deraadt Exp $ */ /* * Copyright (c) 1996 Per Fogelstrom @@ -67,18 +67,25 @@ #include #endif +#ifdef COMPAT_FREEBSD +#include +#endif + struct elf_probe_entry { int (*func) __P((struct proc *, struct exec_package *, char *, u_long *, u_int8_t *)); int os_mask; } elf_probes[] = { +#ifdef COMPAT_FREEBSD + { freebsd_elf_probe, OOS_FREEBSD }, +#endif +#ifdef COMPAT_LINUX + { linux_elf_probe, OOS_LINUX }, +#endif #ifdef COMPAT_SVR4 { svr4_elf_probe, 1 << OOS_SVR4 | 1 << OOS_ESIX | 1 << OOS_SOLARIS | 1 << OOS_SCO | 1 << OOS_DELL | 1 << OOS_NCR }, -#endif -#ifdef COMPAT_LINUX - { linux_elf_probe, OOS_LINUX }, #endif { 0, OOS_OPENBSD } }; @@ -734,4 +741,14 @@ exec_elf_fixup(p, epp) free((char *)interp, M_TEMP); return (error); } + +char * +elf_check_brand(eh) + Elf32_Ehdr *eh; +{ + if (eh->e_ident[EI_BRAND] == '\0') + return (NULL); + return (&eh->e_ident[EI_BRAND]); +} + #endif /* _KERN_DO_ELF */ diff --git a/sys/sys/exec_elf.h b/sys/sys/exec_elf.h index 089d08c9179..9ed741773f2 100644 --- a/sys/sys/exec_elf.h +++ b/sys/sys/exec_elf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_elf.h,v 1.13 1999/02/01 16:33:01 pefo Exp $ */ +/* $OpenBSD: exec_elf.h,v 1.14 1999/02/10 08:07:20 deraadt Exp $ */ /* * Copyright (c) 1995, 1996 Erik Theisen. All rights reserved. * @@ -55,6 +55,7 @@ typedef u_int16_t Elf32_Half; /* Unsigned medium integer */ #define EI_DATA 5 /* data encoding */ #define EI_VERSION 6 /* ELF header version */ #define EI_PAD 7 /* start of pad bytes */ +#define EI_BRAND 8 /* brand */ #define EI_NIDENT 16 /* Size of e_ident[] */ /* e_ident[] magic number */ @@ -392,6 +393,7 @@ int exec_elf_makecmds __P((struct proc *, struct exec_package *)); void *elf_copyargs __P((struct exec_package *, struct ps_strings *, void *, void *)); int exec_elf_fixup __P((struct proc *, struct exec_package *)); +char *elf_check_brand __P((Elf32_Ehdr *)); #endif /* _KERNEL */ -- cgit v1.2.3