From owner-svn-src-head@FreeBSD.ORG Mon Aug 18 02:44:57 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E2B822F4; Mon, 18 Aug 2014 02:44:57 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C2F6C3EC9; Mon, 18 Aug 2014 02:44:57 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7I2ivB5087452; Mon, 18 Aug 2014 02:44:57 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s7I2iuYA087448; Mon, 18 Aug 2014 02:44:56 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201408180244.s7I2iuYA087448@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Mon, 18 Aug 2014 02:44:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r270123 - in head/sys: arm/arm arm/include kern sys X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Aug 2014 02:44:58 -0000 Author: imp Date: Mon Aug 18 02:44:56 2014 New Revision: 270123 URL: http://svnweb.freebsd.org/changeset/base/270123 Log: Expand the elf brandelf infrastructure to give access to the whole ELF header (Elf_Ehdr) to determine if a particular interpretor wants to accept it or not. Use this mechanism to filter EABI arm on OABI arm kernels, and vice versa. This method could also be used to implement OABI on EABI arm kernels, if desired, or to allow a single mips kernel to run o32, n32 and n64 binaries. Differential Revision: https://reviews.freebsd.org/D609 Modified: head/sys/arm/arm/elf_machdep.c head/sys/arm/include/elf.h head/sys/kern/imgact_elf.c head/sys/sys/imgact_elf.h Modified: head/sys/arm/arm/elf_machdep.c ============================================================================== --- head/sys/arm/arm/elf_machdep.c Mon Aug 18 02:42:23 2014 (r270122) +++ head/sys/arm/arm/elf_machdep.c Mon Aug 18 02:44:56 2014 (r270123) @@ -46,6 +46,8 @@ __FBSDID("$FreeBSD$"); #include #include +static boolean_t elf32_arm_abi_supported(struct image_params *); + struct sysentvec elf32_freebsd_sysvec = { .sv_size = SYS_MAXSYSCALL, .sv_table = sysent, @@ -90,7 +92,8 @@ static Elf32_Brandinfo freebsd_brand_inf .sysvec = &elf32_freebsd_sysvec, .interp_newpath = NULL, .brand_note = &elf32_freebsd_brandnote, - .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE + .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE, + .header_supported= elf32_arm_abi_supported, }; SYSINIT(elf32, SI_SUB_EXEC, SI_ORDER_FIRST, @@ -106,13 +109,42 @@ static Elf32_Brandinfo freebsd_brand_oin .sysvec = &elf32_freebsd_sysvec, .interp_newpath = NULL, .brand_note = &elf32_freebsd_brandnote, - .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE + .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE, + .header_supported= elf32_arm_abi_supported, }; SYSINIT(oelf32, SI_SUB_EXEC, SI_ORDER_ANY, (sysinit_cfunc_t) elf32_insert_brand_entry, &freebsd_brand_oinfo); +static boolean_t +elf32_arm_abi_supported(struct image_params *imgp) +{ + const Elf_Ehdr *hdr = (const Elf_Ehdr *)imgp->image_header; + +#ifdef __ARM_EABI__ + /* + * When configured for EABI, FreeBSD supports EABI vesions 4 and 5. + */ + if (EF_ARM_EABI_VERSION(hdr->e_flags) < EF_ARM_EABI_FREEBSD_MIN) { + if (bootverbose) + uprintf("Attempting to execute non EABI binary (rev %d) image %s", + EF_ARM_EABI_VERSION(hdr->e_flags), imgp->args->fname); + return (FALSE); + } +#else + /* + * When configured for OABI, that's all we do, so reject EABI binaries. + */ + if (EF_ARM_EABI_VERSION(hdr->e_flags) != EF_ARM_EABI_VERSION_UNKNOWN) { + if (bootverbose) + uprintf("Attempting to execute EABI binary (rev %d) image %s", + EF_ARM_EABI_VERSION(hdr->e_flags), imgp->args->fname); + return (FALSE); + } +#endif + return (TRUE); +} void elf32_dump_thread(struct thread *td __unused, void *dst __unused, Modified: head/sys/arm/include/elf.h ============================================================================== --- head/sys/arm/include/elf.h Mon Aug 18 02:42:23 2014 (r270122) +++ head/sys/arm/include/elf.h Mon Aug 18 02:44:56 2014 (r270123) @@ -103,6 +103,12 @@ __ElfType(Auxinfo); #define ELF_TARG_MACH EM_ARM #define ELF_TARG_VER 1 +/* Defines specific for arm headers */ +#define EF_ARM_EABIMASK 0xff000000 +#define EF_ARM_EABI_VERSION(x) (((x) & EF_ARM_EABIMASK) >> 24) +#define EF_ARM_EABI_VERSION_UNKNOWN 0 +#define EF_ARM_EABI_FREEBSD_MIN 4 + /* * Magic number for the elf trampoline, chosen wisely to be an immediate * value. Modified: head/sys/kern/imgact_elf.c ============================================================================== --- head/sys/kern/imgact_elf.c Mon Aug 18 02:42:23 2014 (r270122) +++ head/sys/kern/imgact_elf.c Mon Aug 18 02:44:56 2014 (r270123) @@ -294,6 +294,19 @@ __elfN(get_brandinfo)(struct image_param return (bi); } + /* No known brand, see if the header is recognized by any brand */ + for (i = 0; i < MAX_BRANDS; i++) { + bi = elf_brand_list[i]; + if (bi == NULL || bi->flags & BI_BRAND_NOTE_MANDATORY || + bi->header_supported == NULL) + continue; + if (hdr->e_machine == bi->machine) { + ret = bi->header_supported(imgp); + if (ret) + return (bi); + } + } + /* Lacking a known brand, search for a recognized interpreter. */ if (interp != NULL) { for (i = 0; i < MAX_BRANDS; i++) { Modified: head/sys/sys/imgact_elf.h ============================================================================== --- head/sys/sys/imgact_elf.h Mon Aug 18 02:42:23 2014 (r270122) +++ head/sys/sys/imgact_elf.h Mon Aug 18 02:44:56 2014 (r270123) @@ -74,6 +74,7 @@ typedef struct { const char *interp_newpath; int flags; Elf_Brandnote *brand_note; + boolean_t (*header_supported)(struct image_params *); #define BI_CAN_EXEC_DYN 0x0001 #define BI_BRAND_NOTE 0x0002 /* May have note.ABI-tag section. */ #define BI_BRAND_NOTE_MANDATORY 0x0004 /* Must have note.ABI-tag section. */