From owner-svn-src-head@freebsd.org Sun Aug 23 20:06:56 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 919873C8BD0; Sun, 23 Aug 2020 20:06:56 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BZR9X3NJnz4PxP; Sun, 23 Aug 2020 20:06:56 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5776BC763; Sun, 23 Aug 2020 20:06:56 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 07NK6u9i009319; Sun, 23 Aug 2020 20:06:56 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 07NK6tjk009313; Sun, 23 Aug 2020 20:06:55 GMT (envelope-from kib@FreeBSD.org) Message-Id: <202008232006.07NK6tjk009313@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sun, 23 Aug 2020 20:06:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r364521 - in head/sys: arm/arm arm64/arm64 kern powerpc/powerpc sys X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: in head/sys: arm/arm arm64/arm64 kern powerpc/powerpc sys X-SVN-Commit-Revision: 364521 X-SVN-Commit-Repository: base 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.33 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: Sun, 23 Aug 2020 20:06:56 -0000 Author: kib Date: Sun Aug 23 20:06:55 2020 New Revision: 364521 URL: https://svnweb.freebsd.org/changeset/base/364521 Log: Pass pointers to info parsed from notes, to brandinfo->header_supported filter. Currently, we parse notes for the values of ELF FreeBSD feature flags and osrel. Knowing these values, or knowing that image does not carry the note if pointers are NULL, is useful to decide which ABI variant (brand) we want to activate for the image. Right now this is only a plumbing change Tested by: pho Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D25273 Modified: head/sys/arm/arm/elf_machdep.c head/sys/arm64/arm64/elf32_machdep.c head/sys/kern/imgact_elf.c head/sys/powerpc/powerpc/elf64_machdep.c head/sys/sys/imgact_elf.h Modified: head/sys/arm/arm/elf_machdep.c ============================================================================== --- head/sys/arm/arm/elf_machdep.c Sun Aug 23 20:05:35 2020 (r364520) +++ head/sys/arm/arm/elf_machdep.c Sun Aug 23 20:06:55 2020 (r364521) @@ -56,7 +56,8 @@ __FBSDID("$FreeBSD$"); #include "opt_global.h" /* for OPT_KDTRACE_HOOKS */ #include "opt_stack.h" /* for OPT_STACK */ -static boolean_t elf32_arm_abi_supported(struct image_params *); +static boolean_t elf32_arm_abi_supported(struct image_params *, int32_t *, + uint32_t *); u_long elf_hwcap; u_long elf_hwcap2; @@ -121,7 +122,8 @@ SYSINIT(elf32, SI_SUB_EXEC, SI_ORDER_FIRST, &freebsd_brand_info); static boolean_t -elf32_arm_abi_supported(struct image_params *imgp) +elf32_arm_abi_supported(struct image_params *imgp, int32_t *osrel __unused, + uint32_t *fctl0 __unused) { const Elf_Ehdr *hdr = (const Elf_Ehdr *)imgp->image_header; Modified: head/sys/arm64/arm64/elf32_machdep.c ============================================================================== --- head/sys/arm64/arm64/elf32_machdep.c Sun Aug 23 20:05:35 2020 (r364520) +++ head/sys/arm64/arm64/elf32_machdep.c Sun Aug 23 20:06:55 2020 (r364521) @@ -69,7 +69,8 @@ static void freebsd32_setregs(struct thread *td, struc u_long stack); static void freebsd32_set_syscall_retval(struct thread *, int); -static boolean_t elf32_arm_abi_supported(struct image_params *); +static boolean_t elf32_arm_abi_supported(struct image_params *, int32_t *, + uint32_t *); extern void freebsd32_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask); @@ -126,7 +127,8 @@ SYSINIT(elf32, SI_SUB_EXEC, SI_ORDER_FIRST, (sysinit_cfunc_t)elf32_insert_brand_entry, &freebsd32_brand_info); static boolean_t -elf32_arm_abi_supported(struct image_params *imgp) +elf32_arm_abi_supported(struct image_params *imgp, int32_t *osrel __unused, + uint32_t *fctl0 __unused) { const Elf32_Ehdr *hdr; Modified: head/sys/kern/imgact_elf.c ============================================================================== --- head/sys/kern/imgact_elf.c Sun Aug 23 20:05:35 2020 (r364520) +++ head/sys/kern/imgact_elf.c Sun Aug 23 20:06:55 2020 (r364521) @@ -97,7 +97,8 @@ static bool __elfN(freebsd_trans_osrel)(const Elf_Note int32_t *osrel); static bool kfreebsd_trans_osrel(const Elf_Note *note, int32_t *osrel); static boolean_t __elfN(check_note)(struct image_params *imgp, - Elf_Brandnote *checknote, int32_t *osrel, uint32_t *fctl0); + Elf_Brandnote *checknote, int32_t *osrel, boolean_t *has_fctl0, + uint32_t *fctl0); static vm_prot_t __elfN(trans_prot)(Elf_Word); static Elf_Word __elfN(untrans_prot)(vm_prot_t); @@ -309,7 +310,7 @@ __elfN(get_brandinfo)(struct image_params *imgp, const { const Elf_Ehdr *hdr = (const Elf_Ehdr *)imgp->image_header; Elf_Brandinfo *bi, *bi_m; - boolean_t ret; + boolean_t ret, has_fctl0; int i, interp_name_len; interp_name_len = interp != NULL ? strlen(interp) + 1 : 0; @@ -331,11 +332,16 @@ __elfN(get_brandinfo)(struct image_params *imgp, const continue; if (hdr->e_machine == bi->machine && (bi->flags & (BI_BRAND_NOTE|BI_BRAND_NOTE_MANDATORY)) != 0) { + has_fctl0 = false; + *fctl0 = 0; + *osrel = 0; ret = __elfN(check_note)(imgp, bi->brand_note, osrel, - fctl0); + &has_fctl0, fctl0); /* Give brand a chance to veto check_note's guess */ - if (ret && bi->header_supported) - ret = bi->header_supported(imgp); + if (ret && bi->header_supported) { + ret = bi->header_supported(imgp, osrel, + has_fctl0 ? fctl0 : NULL); + } /* * If note checker claimed the binary, but the * interpreter path in the image does not @@ -374,7 +380,7 @@ __elfN(get_brandinfo)(struct image_params *imgp, const bi->compat_3_brand) == 0))) { /* Looks good, but give brand a chance to veto */ if (bi->header_supported == NULL || - bi->header_supported(imgp)) { + bi->header_supported(imgp, NULL, NULL)) { /* * Again, prefer strictly matching * interpreter path. @@ -402,7 +408,7 @@ __elfN(get_brandinfo)(struct image_params *imgp, const bi->header_supported == NULL) continue; if (hdr->e_machine == bi->machine) { - ret = bi->header_supported(imgp); + ret = bi->header_supported(imgp, NULL, NULL); if (ret) return (bi); } @@ -422,7 +428,7 @@ __elfN(get_brandinfo)(struct image_params *imgp, const strlen(bi->interp_path) + 1 == interp_name_len && strncmp(interp, bi->interp_path, interp_name_len) == 0 && (bi->header_supported == NULL || - bi->header_supported(imgp))) + bi->header_supported(imgp, NULL, NULL))) return (bi); } } @@ -436,7 +442,7 @@ __elfN(get_brandinfo)(struct image_params *imgp, const if (hdr->e_machine == bi->machine && __elfN(fallback_brand) == bi->brand && (bi->header_supported == NULL || - bi->header_supported(imgp))) + bi->header_supported(imgp, NULL, NULL))) return (bi); } return (NULL); @@ -2657,6 +2663,7 @@ static Elf_Note fctl_note = { }; struct fctl_cb_arg { + boolean_t *has_fctl0; uint32_t *fctl0; }; @@ -2671,6 +2678,7 @@ note_fctl_cb(const Elf_Note *note, void *arg0, boolean p = (uintptr_t)(note + 1); p += roundup2(note->n_namesz, ELF_NOTE_ROUNDSIZE); desc = (const Elf32_Word *)p; + *arg->has_fctl0 = TRUE; *arg->fctl0 = desc[0]; return (TRUE); } @@ -2683,7 +2691,7 @@ note_fctl_cb(const Elf_Note *note, void *arg0, boolean */ static boolean_t __elfN(check_note)(struct image_params *imgp, Elf_Brandnote *brandnote, - int32_t *osrel, uint32_t *fctl0) + int32_t *osrel, boolean_t *has_fctl0, uint32_t *fctl0) { const Elf_Phdr *phdr; const Elf_Ehdr *hdr; @@ -2695,6 +2703,7 @@ __elfN(check_note)(struct image_params *imgp, Elf_Bran phdr = (const Elf_Phdr *)(imgp->image_header + hdr->e_phoff); b_arg.brandnote = brandnote; b_arg.osrel = osrel; + f_arg.has_fctl0 = has_fctl0; f_arg.fctl0 = fctl0; for (i = 0; i < hdr->e_phnum; i++) { Modified: head/sys/powerpc/powerpc/elf64_machdep.c ============================================================================== --- head/sys/powerpc/powerpc/elf64_machdep.c Sun Aug 23 20:05:35 2020 (r364520) +++ head/sys/powerpc/powerpc/elf64_machdep.c Sun Aug 23 20:06:55 2020 (r364521) @@ -135,8 +135,10 @@ struct sysentvec elf64_freebsd_sysvec_v2 = { }; INIT_SYSENTVEC(elf64_sysvec_v2, &elf64_freebsd_sysvec_v2); -static boolean_t ppc64_elfv1_header_match(struct image_params *params); -static boolean_t ppc64_elfv2_header_match(struct image_params *params); +static boolean_t ppc64_elfv1_header_match(struct image_params *params, + int32_t *, uint32_t *); +static boolean_t ppc64_elfv2_header_match(struct image_params *params, + int32_t *, uint32_t *); static Elf64_Brandinfo freebsd_brand_info_elfv1 = { .brand = ELFOSABI_FREEBSD, @@ -192,7 +194,8 @@ SYSINIT(oelf64, SI_SUB_EXEC, SI_ORDER_ANY, void elf_reloc_self(Elf_Dyn *dynp, Elf_Addr relocbase); static boolean_t -ppc64_elfv1_header_match(struct image_params *params) +ppc64_elfv1_header_match(struct image_params *params, int32_t *osrel __unused, + uint32_t *fctl0 __unused) { const Elf64_Ehdr *hdr = (const Elf64_Ehdr *)params->image_header; int abi = (hdr->e_flags & 3); @@ -201,7 +204,8 @@ ppc64_elfv1_header_match(struct image_params *params) } static boolean_t -ppc64_elfv2_header_match(struct image_params *params) +ppc64_elfv2_header_match(struct image_params *params, int32_t *osrel __unused, + uint32_t *fctl0 __unused) { const Elf64_Ehdr *hdr = (const Elf64_Ehdr *)params->image_header; int abi = (hdr->e_flags & 3); Modified: head/sys/sys/imgact_elf.h ============================================================================== --- head/sys/sys/imgact_elf.h Sun Aug 23 20:05:35 2020 (r364520) +++ head/sys/sys/imgact_elf.h Sun Aug 23 20:06:55 2020 (r364521) @@ -87,7 +87,8 @@ typedef struct { const char *interp_newpath; int flags; Elf_Brandnote *brand_note; - boolean_t (*header_supported)(struct image_params *); + boolean_t (*header_supported)(struct image_params *, + int32_t *, uint32_t *); #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. */