Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/imgact_elf.c
Show First 20 Lines • Show All 338 Lines • ▼ Show 20 Lines | |||||
static Elf_Brandinfo * | static Elf_Brandinfo * | ||||
__elfN(get_brandinfo)(struct image_params *imgp, const char *interp, | __elfN(get_brandinfo)(struct image_params *imgp, const char *interp, | ||||
int32_t *osrel, uint32_t *fctl0) | int32_t *osrel, uint32_t *fctl0) | ||||
{ | { | ||||
const Elf_Ehdr *hdr = (const Elf_Ehdr *)imgp->image_header; | const Elf_Ehdr *hdr = (const Elf_Ehdr *)imgp->image_header; | ||||
Elf_Brandinfo *bi, *bi_m; | Elf_Brandinfo *bi, *bi_m; | ||||
bool ret, has_fctl0; | bool ret, has_fctl0; | ||||
int i, interp_name_len; | int i, interp_name_len; | ||||
int prison_fallback_brand; | |||||
prison_fallback_brand = imgp->proc->p_ucred->cr_prison->pr_elf_fallback_brand; | |||||
dchagin: I suggest drop it below, ie, initialize prison_fallback_brand before using | |||||
interp_name_len = interp != NULL ? strlen(interp) + 1 : 0; | interp_name_len = interp != NULL ? strlen(interp) + 1 : 0; | ||||
/* | /* | ||||
* We support four types of branding -- (1) the ELF EI_OSABI field | * We support four types of branding -- (1) the ELF EI_OSABI field | ||||
* that SCO added to the ELF spec, (2) FreeBSD 3.x's traditional string | * that SCO added to the ELF spec, (2) FreeBSD 3.x's traditional string | ||||
* branding w/in the ELF header, (3) path of the `interp_path' | * branding w/in the ELF header, (3) path of the `interp_path' | ||||
* field, and (4) the ".note.ABI-tag" ELF section. | * field, and (4) the ".note.ABI-tag" ELF section. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | for (i = 0; i < MAX_BRANDS; i++) { | ||||
strlen(bi->interp_path) + 1 == interp_name_len && | strlen(bi->interp_path) + 1 == interp_name_len && | ||||
strncmp(interp, bi->interp_path, interp_name_len) | strncmp(interp, bi->interp_path, interp_name_len) | ||||
== 0 && (bi->header_supported == NULL || | == 0 && (bi->header_supported == NULL || | ||||
bi->header_supported(imgp, NULL, NULL))) | bi->header_supported(imgp, NULL, NULL))) | ||||
return (bi); | return (bi); | ||||
} | } | ||||
} | } | ||||
/* Lacking a recognized interpreter, try the default brand */ | /* Lacking a recognized interpreter, try the default brand */ | ||||
Not Done Inline ActionsThis line looks too long. markj: This line looks too long. | |||||
for (i = 0; i < MAX_BRANDS; i++) { | for (i = 0; i < MAX_BRANDS; i++) { | ||||
bi = elf_brand_list[i]; | bi = elf_brand_list[i]; | ||||
if (bi == NULL || (bi->flags & BI_BRAND_NOTE_MANDATORY) != 0 || | if (bi == NULL || (bi->flags & BI_BRAND_NOTE_MANDATORY) != 0 || | ||||
(interp != NULL && (bi->flags & BI_BRAND_ONLY_STATIC) != 0)) | (interp != NULL && (bi->flags & BI_BRAND_ONLY_STATIC) != 0)) | ||||
continue; | continue; | ||||
if (hdr->e_machine == bi->machine && | |||||
prison_fallback_brand == bi->brand && | |||||
(bi->header_supported == NULL || | |||||
bi->header_supported(imgp, NULL, NULL))) | |||||
return (bi); | |||||
if (hdr->e_machine == bi->machine && | if (hdr->e_machine == bi->machine && | ||||
__elfN(fallback_brand) == bi->brand && | __elfN(fallback_brand) == bi->brand && | ||||
(bi->header_supported == NULL || | (bi->header_supported == NULL || | ||||
bi->header_supported(imgp, NULL, NULL))) | bi->header_supported(imgp, NULL, NULL))) | ||||
return (bi); | return (bi); | ||||
Not Done Inline ActionsDon't we want to first match on prison_fallback_brand so long as it's not equal to -1? That is, it looks like there should be two loops, first searching for the per-jail fallback brand, then for the kernel's fallback brand. markj: Don't we want to first match on `prison_fallback_brand` so long as it's not equal to -1? That… | |||||
} | } | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
static bool | static bool | ||||
__elfN(phdr_in_zero_page)(const Elf_Ehdr *hdr) | __elfN(phdr_in_zero_page)(const Elf_Ehdr *hdr) | ||||
{ | { | ||||
return (hdr->e_phoff <= PAGE_SIZE && | return (hdr->e_phoff <= PAGE_SIZE && | ||||
▲ Show 20 Lines • Show All 2,437 Lines • Show Last 20 Lines |
I suggest drop it below, ie, initialize prison_fallback_brand before using