Author: kib
Date: Thu Apr  6 15:19:18 2017
New Revision: 316576
URL: https://svnweb.freebsd.org/changeset/base/316576

Log:
  Improvements for the brand detection and prioritization.
  
  MFC r315701 (by ed):
  Set the interpreter path to /nonexistent.
  
  MFC r315749:
  Adjust r314851 to not require every brand to specify interpreter path.
  
  MFC r315753:
  Add a flag BI_BRAND_ONLY_STATIC to specify that the brand only
  matches static binaries.
  
  MFC r315754:
  Update r315753 with the proper flag name.
  
  MFC r316211:
  A followup to r315749, two more places where brand->interp_path was
  accessed unconditionally.

Modified:
  stable/11/sys/amd64/cloudabi32/cloudabi32_sysvec.c
  stable/11/sys/amd64/cloudabi64/cloudabi64_sysvec.c
  stable/11/sys/arm/cloudabi32/cloudabi32_sysvec.c
  stable/11/sys/arm64/cloudabi64/cloudabi64_sysvec.c
  stable/11/sys/i386/cloudabi32/cloudabi32_sysvec.c
  stable/11/sys/kern/imgact_elf.c
  stable/11/sys/sys/imgact_elf.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/amd64/cloudabi32/cloudabi32_sysvec.c
==============================================================================
--- stable/11/sys/amd64/cloudabi32/cloudabi32_sysvec.c  Thu Apr  6 15:15:01 
2017        (r316575)
+++ stable/11/sys/amd64/cloudabi32/cloudabi32_sysvec.c  Thu Apr  6 15:19:18 
2017        (r316576)
@@ -227,4 +227,5 @@ Elf32_Brandinfo cloudabi32_brand = {
        .brand          = ELFOSABI_CLOUDABI,
        .machine        = EM_386,
        .sysvec         = &cloudabi32_elf_sysvec,
+       .flags          = BI_BRAND_ONLY_STATIC,
 };

Modified: stable/11/sys/amd64/cloudabi64/cloudabi64_sysvec.c
==============================================================================
--- stable/11/sys/amd64/cloudabi64/cloudabi64_sysvec.c  Thu Apr  6 15:15:01 
2017        (r316575)
+++ stable/11/sys/amd64/cloudabi64/cloudabi64_sysvec.c  Thu Apr  6 15:19:18 
2017        (r316576)
@@ -212,5 +212,5 @@ Elf64_Brandinfo cloudabi64_brand = {
        .brand          = ELFOSABI_CLOUDABI,
        .machine        = EM_X86_64,
        .sysvec         = &cloudabi64_elf_sysvec,
-       .flags          = BI_CAN_EXEC_DYN,
+       .flags          = BI_CAN_EXEC_DYN | BI_BRAND_ONLY_STATIC,
 };

Modified: stable/11/sys/arm/cloudabi32/cloudabi32_sysvec.c
==============================================================================
--- stable/11/sys/arm/cloudabi32/cloudabi32_sysvec.c    Thu Apr  6 15:15:01 
2017        (r316575)
+++ stable/11/sys/arm/cloudabi32/cloudabi32_sysvec.c    Thu Apr  6 15:19:18 
2017        (r316576)
@@ -189,4 +189,5 @@ Elf32_Brandinfo cloudabi32_brand = {
        .brand          = ELFOSABI_CLOUDABI,
        .machine        = EM_ARM,
        .sysvec         = &cloudabi32_elf_sysvec,
+       .flags          = BI_BRAND_ONLY_STATIC,
 };

Modified: stable/11/sys/arm64/cloudabi64/cloudabi64_sysvec.c
==============================================================================
--- stable/11/sys/arm64/cloudabi64/cloudabi64_sysvec.c  Thu Apr  6 15:15:01 
2017        (r316575)
+++ stable/11/sys/arm64/cloudabi64/cloudabi64_sysvec.c  Thu Apr  6 15:19:18 
2017        (r316576)
@@ -181,5 +181,5 @@ Elf64_Brandinfo cloudabi64_brand = {
        .brand          = ELFOSABI_CLOUDABI,
        .machine        = EM_AARCH64,
        .sysvec         = &cloudabi64_elf_sysvec,
-       .flags          = BI_CAN_EXEC_DYN,
+       .flags          = BI_CAN_EXEC_DYN | BI_BRAND_ONLY_STATIC,
 };

Modified: stable/11/sys/i386/cloudabi32/cloudabi32_sysvec.c
==============================================================================
--- stable/11/sys/i386/cloudabi32/cloudabi32_sysvec.c   Thu Apr  6 15:15:01 
2017        (r316575)
+++ stable/11/sys/i386/cloudabi32/cloudabi32_sysvec.c   Thu Apr  6 15:19:18 
2017        (r316576)
@@ -200,4 +200,5 @@ Elf32_Brandinfo cloudabi32_brand = {
        .brand          = ELFOSABI_CLOUDABI,
        .machine        = EM_386,
        .sysvec         = &cloudabi32_elf_sysvec,
+       .flags          = BI_BRAND_ONLY_STATIC,
 };

Modified: stable/11/sys/kern/imgact_elf.c
==============================================================================
--- stable/11/sys/kern/imgact_elf.c     Thu Apr  6 15:15:01 2017        
(r316575)
+++ stable/11/sys/kern/imgact_elf.c     Thu Apr  6 15:19:18 2017        
(r316576)
@@ -273,6 +273,8 @@ __elfN(get_brandinfo)(struct image_param
                bi = elf_brand_list[i];
                if (bi == NULL)
                        continue;
+               if (interp != NULL && (bi->flags & BI_BRAND_ONLY_STATIC) != 0)
+                       continue;
                if (hdr->e_machine == bi->machine && (bi->flags &
                    (BI_BRAND_NOTE|BI_BRAND_NOTE_MANDATORY)) != 0) {
                        ret = __elfN(check_note)(imgp, bi->brand_note, osrel);
@@ -289,9 +291,11 @@ __elfN(get_brandinfo)(struct image_param
                         * this, we return first brand which accepted
                         * our note and, optionally, header.
                         */
-                       if (ret && bi_m == NULL && (strlen(bi->interp_path) +
-                           1 != interp_name_len || strncmp(interp,
-                           bi->interp_path, interp_name_len) != 0)) {
+                       if (ret && bi_m == NULL && interp != NULL &&
+                           (bi->interp_path == NULL ||
+                           (strlen(bi->interp_path) + 1 != interp_name_len ||
+                           strncmp(interp, bi->interp_path, interp_name_len)
+                           != 0))) {
                                bi_m = bi;
                                ret = 0;
                        }
@@ -305,7 +309,8 @@ __elfN(get_brandinfo)(struct image_param
        /* If the executable has a brand, search for it in the brand list. */
        for (i = 0; i < MAX_BRANDS; i++) {
                bi = elf_brand_list[i];
-               if (bi == NULL || bi->flags & BI_BRAND_NOTE_MANDATORY)
+               if (bi == NULL || (bi->flags & BI_BRAND_NOTE_MANDATORY) != 0 ||
+                   (interp != NULL && (bi->flags & BI_BRAND_ONLY_STATIC) != 0))
                        continue;
                if (hdr->e_machine == bi->machine &&
                    (hdr->e_ident[EI_OSABI] == bi->brand ||
@@ -319,7 +324,11 @@ __elfN(get_brandinfo)(struct image_param
                                 * Again, prefer strictly matching
                                 * interpreter path.
                                 */
-                               if (strlen(bi->interp_path) + 1 ==
+                               if (interp_name_len == 0 &&
+                                   bi->interp_path == NULL)
+                                       return (bi);
+                               if (bi->interp_path != NULL &&
+                                   strlen(bi->interp_path) + 1 ==
                                    interp_name_len && strncmp(interp,
                                    bi->interp_path, interp_name_len) == 0)
                                        return (bi);
@@ -348,9 +357,12 @@ __elfN(get_brandinfo)(struct image_param
        if (interp != NULL) {
                for (i = 0; i < MAX_BRANDS; i++) {
                        bi = elf_brand_list[i];
-                       if (bi == NULL || bi->flags & BI_BRAND_NOTE_MANDATORY)
+                       if (bi == NULL || (bi->flags &
+                           (BI_BRAND_NOTE_MANDATORY | BI_BRAND_ONLY_STATIC))
+                           != 0)
                                continue;
                        if (hdr->e_machine == bi->machine &&
+                           bi->interp_path != NULL &&
                            /* ELF image p_filesz includes terminating zero */
                            strlen(bi->interp_path) + 1 == interp_name_len &&
                            strncmp(interp, bi->interp_path, interp_name_len)
@@ -362,7 +374,8 @@ __elfN(get_brandinfo)(struct image_param
        /* Lacking a recognized interpreter, try the default brand */
        for (i = 0; i < MAX_BRANDS; i++) {
                bi = elf_brand_list[i];
-               if (bi == NULL || bi->flags & BI_BRAND_NOTE_MANDATORY)
+               if (bi == NULL || (bi->flags & BI_BRAND_NOTE_MANDATORY) != 0 ||
+                   (interp != NULL && (bi->flags & BI_BRAND_ONLY_STATIC) != 0))
                        continue;
                if (hdr->e_machine == bi->machine &&
                    __elfN(fallback_brand) == bi->brand)

Modified: stable/11/sys/sys/imgact_elf.h
==============================================================================
--- stable/11/sys/sys/imgact_elf.h      Thu Apr  6 15:15:01 2017        
(r316575)
+++ stable/11/sys/sys/imgact_elf.h      Thu Apr  6 15:19:18 2017        
(r316576)
@@ -81,6 +81,7 @@ typedef struct {
 #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. */
+#define        BI_BRAND_ONLY_STATIC    0x0008  /* Match only interp-less 
binaries. */
 } __ElfN(Brandinfo);
 
 __ElfType(Auxargs);
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to