コード例 #1
0
int build_elf_exec_info(const char *buf, off_t len, struct mem_ehdr *ehdr,
				uint32_t flags)
{
	struct mem_phdr *phdr, *end_phdr;
	int result;
	result = build_elf_info(buf, len, ehdr, flags);
	if (result < 0) {
		return result;
	}
	if ((ehdr->e_type != ET_EXEC) && (ehdr->e_type != ET_DYN)) {
		/* not an ELF executable */
		if (probe_debug) {
			fprintf(stderr, "Not ELF type ET_EXEC or ET_DYN\n");
		}
		return -1;
	}
	if (!ehdr->e_phdr) {
		/* No program header */
		fprintf(stderr, "No ELF program header\n");
		return -1; 
	}
	end_phdr = &ehdr->e_phdr[ehdr->e_phnum];
	for(phdr = ehdr->e_phdr; phdr != end_phdr; phdr++) {
		/* Kexec does not support loading interpreters.
		 * In addition this check keeps us from attempting
		 * to kexec ordinay executables.
		 */
		if (phdr->p_type == PT_INTERP) {
			fprintf(stderr, "Requires an ELF interpreter\n");
			return -1;
		}
	}

	return 0;
}
コード例 #2
0
int build_elf_rel_info(const char *buf, off_t len, struct mem_ehdr *ehdr,
				uint32_t flags)
{
	int result;
	result = build_elf_info(buf, len, ehdr, flags);
	if (result < 0) {
		return result;
	}
	if (ehdr->e_type != ET_REL) {
		/* not an ELF relocate object */
		if (probe_debug) {
			fprintf(stderr, "Not ELF type ET_REL\n");
			fprintf(stderr, "ELF Type: %x\n", ehdr->e_type);
		}
		return -1;
	}
	if (!ehdr->e_shdr) {
		/* No section headers */
		if (probe_debug) {
			fprintf(stderr, "No ELF section headers\n");
		}
		return -1;
	}
	if (!machine_verify_elf_rel(ehdr)) {
		/* It does not meant the native architecture constraints */
		if (probe_debug) {
			fprintf(stderr, "ELF architecture constraint failure\n");
		}
		return -1;
	}
	return 0;
}