summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2017-04-06 15:19:18 +0000
committerkib <kib@FreeBSD.org>2017-04-06 15:19:18 +0000
commit11ac0fc26ac23e16776d84b8d27eee593b527f8f (patch)
tree0f7461532ffabb423b535e6331c4c468c39ea31e /sys
parent9a92d335245044a13a361c9927ac09113ff68488 (diff)
downloadFreeBSD-src-11ac0fc26ac23e16776d84b8d27eee593b527f8f.zip
FreeBSD-src-11ac0fc26ac23e16776d84b8d27eee593b527f8f.tar.gz
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.
Diffstat (limited to 'sys')
-rw-r--r--sys/amd64/cloudabi32/cloudabi32_sysvec.c1
-rw-r--r--sys/amd64/cloudabi64/cloudabi64_sysvec.c2
-rw-r--r--sys/arm/cloudabi32/cloudabi32_sysvec.c1
-rw-r--r--sys/arm64/cloudabi64/cloudabi64_sysvec.c2
-rw-r--r--sys/i386/cloudabi32/cloudabi32_sysvec.c1
-rw-r--r--sys/kern/imgact_elf.c27
-rw-r--r--sys/sys/imgact_elf.h1
7 files changed, 26 insertions, 9 deletions
diff --git a/sys/amd64/cloudabi32/cloudabi32_sysvec.c b/sys/amd64/cloudabi32/cloudabi32_sysvec.c
index fa2f9ae..abede1a 100644
--- a/sys/amd64/cloudabi32/cloudabi32_sysvec.c
+++ b/sys/amd64/cloudabi32/cloudabi32_sysvec.c
@@ -227,4 +227,5 @@ Elf32_Brandinfo cloudabi32_brand = {
.brand = ELFOSABI_CLOUDABI,
.machine = EM_386,
.sysvec = &cloudabi32_elf_sysvec,
+ .flags = BI_BRAND_ONLY_STATIC,
};
diff --git a/sys/amd64/cloudabi64/cloudabi64_sysvec.c b/sys/amd64/cloudabi64/cloudabi64_sysvec.c
index 3a21ff3..84f0cb3 100644
--- a/sys/amd64/cloudabi64/cloudabi64_sysvec.c
+++ b/sys/amd64/cloudabi64/cloudabi64_sysvec.c
@@ -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,
};
diff --git a/sys/arm/cloudabi32/cloudabi32_sysvec.c b/sys/arm/cloudabi32/cloudabi32_sysvec.c
index f4e231b..100fa47 100644
--- a/sys/arm/cloudabi32/cloudabi32_sysvec.c
+++ b/sys/arm/cloudabi32/cloudabi32_sysvec.c
@@ -189,4 +189,5 @@ Elf32_Brandinfo cloudabi32_brand = {
.brand = ELFOSABI_CLOUDABI,
.machine = EM_ARM,
.sysvec = &cloudabi32_elf_sysvec,
+ .flags = BI_BRAND_ONLY_STATIC,
};
diff --git a/sys/arm64/cloudabi64/cloudabi64_sysvec.c b/sys/arm64/cloudabi64/cloudabi64_sysvec.c
index fc786de..fbad0ba 100644
--- a/sys/arm64/cloudabi64/cloudabi64_sysvec.c
+++ b/sys/arm64/cloudabi64/cloudabi64_sysvec.c
@@ -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,
};
diff --git a/sys/i386/cloudabi32/cloudabi32_sysvec.c b/sys/i386/cloudabi32/cloudabi32_sysvec.c
index 45b9e5c..c2a21fa 100644
--- a/sys/i386/cloudabi32/cloudabi32_sysvec.c
+++ b/sys/i386/cloudabi32/cloudabi32_sysvec.c
@@ -200,4 +200,5 @@ Elf32_Brandinfo cloudabi32_brand = {
.brand = ELFOSABI_CLOUDABI,
.machine = EM_386,
.sysvec = &cloudabi32_elf_sysvec,
+ .flags = BI_BRAND_ONLY_STATIC,
};
diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c
index 33a31c0..491b9dd 100644
--- a/sys/kern/imgact_elf.c
+++ b/sys/kern/imgact_elf.c
@@ -273,6 +273,8 @@ __elfN(get_brandinfo)(struct image_params *imgp, const char *interp,
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_params *imgp, const char *interp,
* 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_params *imgp, const char *interp,
/* 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_params *imgp, const char *interp,
* 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_params *imgp, const char *interp,
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_params *imgp, const char *interp,
/* 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)
diff --git a/sys/sys/imgact_elf.h b/sys/sys/imgact_elf.h
index 0ec04fc..40ad7c7 100644
--- a/sys/sys/imgact_elf.h
+++ b/sys/sys/imgact_elf.h
@@ -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);
OpenPOWER on IntegriCloud