diff options
author | dchagin <dchagin@FreeBSD.org> | 2014-06-03 04:31:42 +0000 |
---|---|---|
committer | dchagin <dchagin@FreeBSD.org> | 2014-06-03 04:31:42 +0000 |
commit | e871acf5e4e1215e87d652c0645ffd349e7ec4ab (patch) | |
tree | b7a72de6aa780aa13c65481c4c8143a2c21953ea | |
parent | 403ddf0c10f4587ee3dfdf27513fde189d7f4dbf (diff) | |
download | FreeBSD-src-e871acf5e4e1215e87d652c0645ffd349e7ec4ab.zip FreeBSD-src-e871acf5e4e1215e87d652c0645ffd349e7ec4ab.tar.gz |
MFC r266925:
To allow to run the interpreter itself add a new ELF branding type.
Allow Linux ABI to run ELF interpreter.
-rw-r--r-- | sys/amd64/linux32/linux32_sysvec.c | 4 | ||||
-rw-r--r-- | sys/i386/linux/linux_sysvec.c | 4 | ||||
-rw-r--r-- | sys/kern/imgact_elf.c | 29 | ||||
-rw-r--r-- | sys/sys/imgact_elf.h | 1 |
4 files changed, 34 insertions, 4 deletions
diff --git a/sys/amd64/linux32/linux32_sysvec.c b/sys/amd64/linux32/linux32_sysvec.c index c06ce11..9b5c555 100644 --- a/sys/amd64/linux32/linux32_sysvec.c +++ b/sys/amd64/linux32/linux32_sysvec.c @@ -1083,7 +1083,7 @@ static Elf32_Brandinfo linux_brand = { .sysvec = &elf_linux_sysvec, .interp_newpath = NULL, .brand_note = &linux32_brandnote, - .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE + .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE | BI_CAN_EXEC_INTERP }; static Elf32_Brandinfo linux_glibc2brand = { @@ -1095,7 +1095,7 @@ static Elf32_Brandinfo linux_glibc2brand = { .sysvec = &elf_linux_sysvec, .interp_newpath = NULL, .brand_note = &linux32_brandnote, - .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE + .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE | BI_CAN_EXEC_INTERP }; Elf32_Brandinfo *linux_brandlist[] = { diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c index 0ad6791..60df6a2 100644 --- a/sys/i386/linux/linux_sysvec.c +++ b/sys/i386/linux/linux_sysvec.c @@ -1058,7 +1058,7 @@ static Elf32_Brandinfo linux_brand = { .sysvec = &elf_linux_sysvec, .interp_newpath = NULL, .brand_note = &linux_brandnote, - .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE + .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE | BI_CAN_EXEC_INTERP }; static Elf32_Brandinfo linux_glibc2brand = { @@ -1070,7 +1070,7 @@ static Elf32_Brandinfo linux_glibc2brand = { .sysvec = &elf_linux_sysvec, .interp_newpath = NULL, .brand_note = &linux_brandnote, - .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE + .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE | BI_CAN_EXEC_INTERP }; Elf32_Brandinfo *linux_brandlist[] = { diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index 8783670..a9659a1 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -261,6 +261,8 @@ __elfN(get_brandinfo)(struct image_params *imgp, const char *interp, { const Elf_Ehdr *hdr = (const Elf_Ehdr *)imgp->image_header; Elf_Brandinfo *bi; + const char *fname_name, *interp_brand_name; + int fname_len, interp_len; boolean_t ret; int i; @@ -311,6 +313,33 @@ __elfN(get_brandinfo)(struct image_params *imgp, const char *interp, } } + /* Some ABI allows to run the interpreter itself. */ + for (i = 0; i < MAX_BRANDS; i++) { + bi = elf_brand_list[i]; + if (bi == NULL || bi->flags & BI_BRAND_NOTE_MANDATORY) + continue; + if (hdr->e_machine != bi->machine || + (bi->flags & BI_CAN_EXEC_INTERP) == 0) + continue; + /* + * Compare the interpreter name not the path to allow run it + * from everywhere. + */ + interp_brand_name = strrchr(bi->interp_path, '/'); + if (interp_brand_name == NULL) + interp_brand_name = bi->interp_path; + interp_len = strlen(interp_brand_name); + fname_name = strrchr(imgp->args->fname, '/'); + if (fname_name == NULL) + fname_name = imgp->args->fname; + fname_len = strlen(fname_name); + if (fname_len < interp_len) + continue; + ret = strncmp(fname_name, interp_brand_name, interp_len); + if (ret == 0) + return (bi); + } + /* Lacking a recognized interpreter, try the default brand */ for (i = 0; i < MAX_BRANDS; i++) { bi = elf_brand_list[i]; diff --git a/sys/sys/imgact_elf.h b/sys/sys/imgact_elf.h index faef5f8..3b34854 100644 --- a/sys/sys/imgact_elf.h +++ b/sys/sys/imgact_elf.h @@ -77,6 +77,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_CAN_EXEC_INTERP 0x0008 /* Allow to run interpreter itself. */ } __ElfN(Brandinfo); __ElfType(Auxargs); |