Loading fs/binfmt_flat.c +51 −67 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,8 @@ * JAN/99 -- coded full program relocation (gerg@snapgear.com) * JAN/99 -- coded full program relocation (gerg@snapgear.com) */ */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/kernel.h> #include <linux/kernel.h> #include <linux/sched.h> #include <linux/sched.h> #include <linux/mm.h> #include <linux/mm.h> Loading @@ -40,16 +42,6 @@ /****************************************************************************/ /****************************************************************************/ #if 0 #define DEBUG 1 #endif #ifdef DEBUG #define DBG_FLT(a...) printk(a) #else #define DBG_FLT(a...) #endif /* /* * User data (data section and bss) needs to be aligned. * User data (data section and bss) needs to be aligned. * We pick 0x20 here because it is the max value elf2flt has always * We pick 0x20 here because it is the max value elf2flt has always Loading Loading @@ -102,7 +94,7 @@ static struct linux_binfmt flat_format = { static int flat_core_dump(struct coredump_params *cprm) static int flat_core_dump(struct coredump_params *cprm) { { printk("Process %s:%d received signr %d and should have core dumped\n", pr_warn("Process %s:%d received signr %d and should have core dumped\n", current->comm, current->pid, cprm->siginfo->si_signo); current->comm, current->pid, cprm->siginfo->si_signo); return 1; return 1; } } Loading Loading @@ -186,17 +178,17 @@ static int decompress_exec( loff_t fpos; loff_t fpos; int ret, retval; int ret, retval; DBG_FLT("decompress_exec(offset=%lx,buf=%p,len=%lx)\n", offset, dst, len); pr_debug("decompress_exec(offset=%lx,buf=%p,len=%lx)\n", offset, dst, len); memset(&strm, 0, sizeof(strm)); memset(&strm, 0, sizeof(strm)); strm.workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL); strm.workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL); if (strm.workspace == NULL) { if (strm.workspace == NULL) { DBG_FLT("binfmt_flat: no memory for decompress workspace\n"); pr_debug("no memory for decompress workspace\n"); return -ENOMEM; return -ENOMEM; } } buf = kmalloc(LBUFSIZE, GFP_KERNEL); buf = kmalloc(LBUFSIZE, GFP_KERNEL); if (buf == NULL) { if (buf == NULL) { DBG_FLT("binfmt_flat: no memory for read buffer\n"); pr_debug("no memory for read buffer\n"); retval = -ENOMEM; retval = -ENOMEM; goto out_free; goto out_free; } } Loading @@ -214,25 +206,25 @@ static int decompress_exec( /* Check minimum size -- gzip header */ /* Check minimum size -- gzip header */ if (ret < 10) { if (ret < 10) { DBG_FLT("binfmt_flat: file too small?\n"); pr_debug("file too small?\n"); goto out_free_buf; goto out_free_buf; } } /* Check gzip magic number */ /* Check gzip magic number */ if ((buf[0] != 037) || ((buf[1] != 0213) && (buf[1] != 0236))) { if ((buf[0] != 037) || ((buf[1] != 0213) && (buf[1] != 0236))) { DBG_FLT("binfmt_flat: unknown compression magic?\n"); pr_debug("unknown compression magic?\n"); goto out_free_buf; goto out_free_buf; } } /* Check gzip method */ /* Check gzip method */ if (buf[2] != 8) { if (buf[2] != 8) { DBG_FLT("binfmt_flat: unknown compression method?\n"); pr_debug("unknown compression method?\n"); goto out_free_buf; goto out_free_buf; } } /* Check gzip flags */ /* Check gzip flags */ if ((buf[3] & ENCRYPTED) || (buf[3] & CONTINUATION) || if ((buf[3] & ENCRYPTED) || (buf[3] & CONTINUATION) || (buf[3] & RESERVED)) { (buf[3] & RESERVED)) { DBG_FLT("binfmt_flat: unknown flags?\n"); pr_debug("unknown flags?\n"); goto out_free_buf; goto out_free_buf; } } Loading @@ -240,7 +232,7 @@ static int decompress_exec( if (buf[3] & EXTRA_FIELD) { if (buf[3] & EXTRA_FIELD) { ret += 2 + buf[10] + (buf[11] << 8); ret += 2 + buf[10] + (buf[11] << 8); if (unlikely(ret >= LBUFSIZE)) { if (unlikely(ret >= LBUFSIZE)) { DBG_FLT("binfmt_flat: buffer overflow (EXTRA)?\n"); pr_debug("buffer overflow (EXTRA)?\n"); goto out_free_buf; goto out_free_buf; } } } } Loading @@ -248,7 +240,7 @@ static int decompress_exec( while (ret < LBUFSIZE && buf[ret++] != 0) while (ret < LBUFSIZE && buf[ret++] != 0) ; ; if (unlikely(ret == LBUFSIZE)) { if (unlikely(ret == LBUFSIZE)) { DBG_FLT("binfmt_flat: buffer overflow (ORIG_NAME)?\n"); pr_debug("buffer overflow (ORIG_NAME)?\n"); goto out_free_buf; goto out_free_buf; } } } } Loading @@ -256,7 +248,7 @@ static int decompress_exec( while (ret < LBUFSIZE && buf[ret++] != 0) while (ret < LBUFSIZE && buf[ret++] != 0) ; ; if (unlikely(ret == LBUFSIZE)) { if (unlikely(ret == LBUFSIZE)) { DBG_FLT("binfmt_flat: buffer overflow (COMMENT)?\n"); pr_debug("buffer overflow (COMMENT)?\n"); goto out_free_buf; goto out_free_buf; } } } } Loading @@ -269,7 +261,7 @@ static int decompress_exec( strm.total_out = 0; strm.total_out = 0; if (zlib_inflateInit2(&strm, -MAX_WBITS) != Z_OK) { if (zlib_inflateInit2(&strm, -MAX_WBITS) != Z_OK) { DBG_FLT("binfmt_flat: zlib init failed?\n"); pr_debug("zlib init failed?\n"); goto out_free_buf; goto out_free_buf; } } Loading @@ -286,7 +278,7 @@ static int decompress_exec( } } if (ret < 0) { if (ret < 0) { DBG_FLT("binfmt_flat: decompression failed (%d), %s\n", pr_debug("decompression failed (%d), %s\n", ret, strm.msg); ret, strm.msg); goto out_zlib; goto out_zlib; } } Loading Loading @@ -323,24 +315,23 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp) r &= 0x00ffffff; /* Trim ID off here */ r &= 0x00ffffff; /* Trim ID off here */ } } if (id >= MAX_SHARED_LIBS) { if (id >= MAX_SHARED_LIBS) { printk("BINFMT_FLAT: reference 0x%lx to shared library %d", pr_err("reference 0x%lx to shared library %d", r, id); r, id); goto failed; goto failed; } } if (curid != id) { if (curid != id) { if (internalp) { if (internalp) { printk("BINFMT_FLAT: reloc address 0x%lx not in same module " pr_err("reloc address 0x%lx not in same module " "(%d != %d)", r, curid, id); "(%d != %d)", r, curid, id); goto failed; goto failed; } else if (!p->lib_list[id].loaded && } else if (!p->lib_list[id].loaded && load_flat_shared_library(id, p) < 0) { load_flat_shared_library(id, p) < 0) { printk("BINFMT_FLAT: failed to load library %d", id); pr_err("failed to load library %d", id); goto failed; goto failed; } } /* Check versioning information (i.e. time stamps) */ /* Check versioning information (i.e. time stamps) */ if (p->lib_list[id].build_date && p->lib_list[curid].build_date && if (p->lib_list[id].build_date && p->lib_list[curid].build_date && p->lib_list[curid].build_date < p->lib_list[id].build_date) { p->lib_list[curid].build_date < p->lib_list[id].build_date) { printk("BINFMT_FLAT: library %d is younger than %d", id, curid); pr_err("library %d is younger than %d", id, curid); goto failed; goto failed; } } } } Loading @@ -354,7 +345,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp) text_len = p->lib_list[id].text_len; text_len = p->lib_list[id].text_len; if (!flat_reloc_valid(r, start_brk - start_data + text_len)) { if (!flat_reloc_valid(r, start_brk - start_data + text_len)) { printk("BINFMT_FLAT: reloc outside program 0x%lx (0 - 0x%lx/0x%lx)", pr_err("reloc outside program 0x%lx (0 - 0x%lx/0x%lx)", r, start_brk-start_data+text_len, text_len); r, start_brk-start_data+text_len, text_len); goto failed; goto failed; } } Loading @@ -368,7 +359,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp) return addr; return addr; failed: failed: printk(", killing %s!\n", current->comm); pr_cont(", killing %s!\n", current->comm); send_sig(SIGSEGV, current, 0); send_sig(SIGSEGV, current, 0); return RELOC_FAILED; return RELOC_FAILED; Loading @@ -378,9 +369,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp) static void old_reloc(unsigned long rl) static void old_reloc(unsigned long rl) { { #ifdef DEBUG static const char *segment[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" }; static const char *segment[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" }; #endif flat_v2_reloc_t r; flat_v2_reloc_t r; unsigned long *ptr; unsigned long *ptr; Loading @@ -391,11 +380,9 @@ static void old_reloc(unsigned long rl) ptr = (unsigned long *) (current->mm->start_data + r.reloc.offset); ptr = (unsigned long *) (current->mm->start_data + r.reloc.offset); #endif #endif #ifdef DEBUG pr_debug("Relocation of variable at DATASEG+%x " printk("Relocation of variable at DATASEG+%x " "(address %p, currently %lx) into segment %s\n", "(address %p, currently %lx) into segment %s\n", r.reloc.offset, ptr, *ptr, segment[r.reloc.type]); r.reloc.offset, ptr, *ptr, segment[r.reloc.type]); #endif switch (r.reloc.type) { switch (r.reloc.type) { case OLD_FLAT_RELOC_TYPE_TEXT: case OLD_FLAT_RELOC_TYPE_TEXT: Loading @@ -408,13 +395,11 @@ static void old_reloc(unsigned long rl) *ptr += current->mm->end_data; *ptr += current->mm->end_data; break; break; default: default: printk("BINFMT_FLAT: Unknown relocation type=%x\n", r.reloc.type); pr_err("Unknown relocation type=%x\n", r.reloc.type); break; break; } } #ifdef DEBUG pr_debug("Relocation became %lx\n", *ptr); printk("Relocation became %lx\n", *ptr); #endif } } /****************************************************************************/ /****************************************************************************/ Loading Loading @@ -463,11 +448,10 @@ static int load_flat_file(struct linux_binprm *bprm, } } if (flags & FLAT_FLAG_KTRACE) if (flags & FLAT_FLAG_KTRACE) printk("BINFMT_FLAT: Loading file: %s\n", bprm->filename); pr_info("Loading file: %s\n", bprm->filename); if (rev != FLAT_VERSION && rev != OLD_FLAT_VERSION) { if (rev != FLAT_VERSION && rev != OLD_FLAT_VERSION) { printk("BINFMT_FLAT: bad flat file version 0x%x (supported " pr_err("bad flat file version 0x%x (supported 0x%lx and 0x%lx)\n", "0x%lx and 0x%lx)\n", rev, FLAT_VERSION, OLD_FLAT_VERSION); rev, FLAT_VERSION, OLD_FLAT_VERSION); ret = -ENOEXEC; ret = -ENOEXEC; goto err; goto err; Loading @@ -475,7 +459,7 @@ static int load_flat_file(struct linux_binprm *bprm, /* Don't allow old format executables to use shared libraries */ /* Don't allow old format executables to use shared libraries */ if (rev == OLD_FLAT_VERSION && id != 0) { if (rev == OLD_FLAT_VERSION && id != 0) { printk("BINFMT_FLAT: shared libraries are not available before rev 0x%lx\n", pr_err("shared libraries are not available before rev 0x%lx\n", FLAT_VERSION); FLAT_VERSION); ret = -ENOEXEC; ret = -ENOEXEC; goto err; goto err; Loading @@ -490,7 +474,7 @@ static int load_flat_file(struct linux_binprm *bprm, #ifndef CONFIG_BINFMT_ZFLAT #ifndef CONFIG_BINFMT_ZFLAT if (flags & (FLAT_FLAG_GZIP|FLAT_FLAG_GZDATA)) { if (flags & (FLAT_FLAG_GZIP|FLAT_FLAG_GZDATA)) { printk("Support for ZFLAT executables is not enabled.\n"); pr_err("Support for ZFLAT executables is not enabled.\n"); ret = -ENOEXEC; ret = -ENOEXEC; goto err; goto err; } } Loading Loading @@ -536,7 +520,7 @@ static int load_flat_file(struct linux_binprm *bprm, * this should give us a ROM ptr, but if it doesn't we don't * this should give us a ROM ptr, but if it doesn't we don't * really care * really care */ */ DBG_FLT("BINFMT_FLAT: ROM mapping of file (we hope)\n"); pr_debug("ROM mapping of file (we hope)\n"); textpos = vm_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC, textpos = vm_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_EXECUTABLE, 0); MAP_PRIVATE|MAP_EXECUTABLE, 0); Loading @@ -544,7 +528,7 @@ static int load_flat_file(struct linux_binprm *bprm, ret = textpos; ret = textpos; if (!textpos) if (!textpos) ret = -ENOMEM; ret = -ENOMEM; printk("Unable to mmap process text, errno %d\n", ret); pr_err("Unable to mmap process text, errno %d\n", ret); goto err; goto err; } } Loading @@ -557,7 +541,7 @@ static int load_flat_file(struct linux_binprm *bprm, ret = realdatastart; ret = realdatastart; if (!realdatastart) if (!realdatastart) ret = -ENOMEM; ret = -ENOMEM; printk("Unable to allocate RAM for process data, " pr_err("Unable to allocate RAM for process data, " "errno %d\n", ret); "errno %d\n", ret); vm_munmap(textpos, text_len); vm_munmap(textpos, text_len); goto err; goto err; Loading @@ -566,7 +550,7 @@ static int load_flat_file(struct linux_binprm *bprm, MAX_SHARED_LIBS * sizeof(unsigned long), MAX_SHARED_LIBS * sizeof(unsigned long), FLAT_DATA_ALIGN); FLAT_DATA_ALIGN); DBG_FLT("BINFMT_FLAT: Allocated data+bss+stack (%ld bytes): %lx\n", pr_debug("Allocated data+bss+stack (%ld bytes): %lx\n", data_len + bss_len + stack_len, datapos); data_len + bss_len + stack_len, datapos); fpos = ntohl(hdr->data_start); fpos = ntohl(hdr->data_start); Loading @@ -582,7 +566,7 @@ static int load_flat_file(struct linux_binprm *bprm, } } if (IS_ERR_VALUE(result)) { if (IS_ERR_VALUE(result)) { ret = result; ret = result; printk("Unable to read data+bss, errno %d\n", ret); pr_err("Unable to read data+bss, errno %d\n", ret); vm_munmap(textpos, text_len); vm_munmap(textpos, text_len); vm_munmap(realdatastart, len); vm_munmap(realdatastart, len); goto err; goto err; Loading @@ -603,7 +587,7 @@ static int load_flat_file(struct linux_binprm *bprm, ret = textpos; ret = textpos; if (!textpos) if (!textpos) ret = -ENOMEM; ret = -ENOMEM; printk("Unable to allocate RAM for process text/data, " pr_err("Unable to allocate RAM for process text/data, " "errno %d\n", ret); "errno %d\n", ret); goto err; goto err; } } Loading Loading @@ -645,7 +629,7 @@ static int load_flat_file(struct linux_binprm *bprm, } } if (IS_ERR_VALUE(result)) { if (IS_ERR_VALUE(result)) { ret = result; ret = result; printk("Unable to read code+data+bss, errno %d\n", ret); pr_err("Unable to read code+data+bss, errno %d\n", ret); vm_munmap(textpos, text_len + data_len + extra + vm_munmap(textpos, text_len + data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long)); MAX_SHARED_LIBS * sizeof(unsigned long)); goto err; goto err; Loading Loading @@ -675,9 +659,9 @@ static int load_flat_file(struct linux_binprm *bprm, } } if (flags & FLAT_FLAG_KTRACE) { if (flags & FLAT_FLAG_KTRACE) { printk("Mapping is %lx, Entry point is %x, data_start is %x\n", pr_info("Mapping is %lx, Entry point is %x, data_start is %x\n", textpos, 0x00ffffff&ntohl(hdr->entry), ntohl(hdr->data_start)); textpos, 0x00ffffff&ntohl(hdr->entry), ntohl(hdr->data_start)); printk("%s %s: TEXT=%lx-%lx DATA=%lx-%lx BSS=%lx-%lx\n", pr_info("%s %s: TEXT=%lx-%lx DATA=%lx-%lx BSS=%lx-%lx\n", id ? "Lib" : "Load", bprm->filename, id ? "Lib" : "Load", bprm->filename, start_code, end_code, datapos, datapos + data_len, start_code, end_code, datapos, datapos + data_len, datapos + data_len, (datapos + data_len + bss_len + 3) & ~3); datapos + data_len, (datapos + data_len + bss_len + 3) & ~3); Loading Loading @@ -890,7 +874,7 @@ static int load_flat_binary(struct linux_binprm *bprm) set_binfmt(&flat_format); set_binfmt(&flat_format); p = ((current->mm->context.end_brk + stack_len + 3) & ~3) - 4; p = ((current->mm->context.end_brk + stack_len + 3) & ~3) - 4; DBG_FLT("p=%lx\n", p); pr_debug("p=%lx\n", p); /* copy the arg pages onto the stack, this could be more efficient :-) */ /* copy the arg pages onto the stack, this could be more efficient :-) */ for (i = TOP_OF_ARGS - 1; i >= bprm->p; i--) for (i = TOP_OF_ARGS - 1; i >= bprm->p; i--) Loading Loading @@ -922,7 +906,7 @@ static int load_flat_binary(struct linux_binprm *bprm) FLAT_PLAT_INIT(regs); FLAT_PLAT_INIT(regs); #endif #endif DBG_FLT("start_thread(regs=0x%p, entry=0x%lx, start_stack=0x%lx)\n", pr_debug("start_thread(regs=0x%p, entry=0x%lx, start_stack=0x%lx)\n", regs, start_addr, current->mm->start_stack); regs, start_addr, current->mm->start_stack); start_thread(regs, start_addr, current->mm->start_stack); start_thread(regs, start_addr, current->mm->start_stack); Loading Loading
fs/binfmt_flat.c +51 −67 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,8 @@ * JAN/99 -- coded full program relocation (gerg@snapgear.com) * JAN/99 -- coded full program relocation (gerg@snapgear.com) */ */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/kernel.h> #include <linux/kernel.h> #include <linux/sched.h> #include <linux/sched.h> #include <linux/mm.h> #include <linux/mm.h> Loading @@ -40,16 +42,6 @@ /****************************************************************************/ /****************************************************************************/ #if 0 #define DEBUG 1 #endif #ifdef DEBUG #define DBG_FLT(a...) printk(a) #else #define DBG_FLT(a...) #endif /* /* * User data (data section and bss) needs to be aligned. * User data (data section and bss) needs to be aligned. * We pick 0x20 here because it is the max value elf2flt has always * We pick 0x20 here because it is the max value elf2flt has always Loading Loading @@ -102,7 +94,7 @@ static struct linux_binfmt flat_format = { static int flat_core_dump(struct coredump_params *cprm) static int flat_core_dump(struct coredump_params *cprm) { { printk("Process %s:%d received signr %d and should have core dumped\n", pr_warn("Process %s:%d received signr %d and should have core dumped\n", current->comm, current->pid, cprm->siginfo->si_signo); current->comm, current->pid, cprm->siginfo->si_signo); return 1; return 1; } } Loading Loading @@ -186,17 +178,17 @@ static int decompress_exec( loff_t fpos; loff_t fpos; int ret, retval; int ret, retval; DBG_FLT("decompress_exec(offset=%lx,buf=%p,len=%lx)\n", offset, dst, len); pr_debug("decompress_exec(offset=%lx,buf=%p,len=%lx)\n", offset, dst, len); memset(&strm, 0, sizeof(strm)); memset(&strm, 0, sizeof(strm)); strm.workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL); strm.workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL); if (strm.workspace == NULL) { if (strm.workspace == NULL) { DBG_FLT("binfmt_flat: no memory for decompress workspace\n"); pr_debug("no memory for decompress workspace\n"); return -ENOMEM; return -ENOMEM; } } buf = kmalloc(LBUFSIZE, GFP_KERNEL); buf = kmalloc(LBUFSIZE, GFP_KERNEL); if (buf == NULL) { if (buf == NULL) { DBG_FLT("binfmt_flat: no memory for read buffer\n"); pr_debug("no memory for read buffer\n"); retval = -ENOMEM; retval = -ENOMEM; goto out_free; goto out_free; } } Loading @@ -214,25 +206,25 @@ static int decompress_exec( /* Check minimum size -- gzip header */ /* Check minimum size -- gzip header */ if (ret < 10) { if (ret < 10) { DBG_FLT("binfmt_flat: file too small?\n"); pr_debug("file too small?\n"); goto out_free_buf; goto out_free_buf; } } /* Check gzip magic number */ /* Check gzip magic number */ if ((buf[0] != 037) || ((buf[1] != 0213) && (buf[1] != 0236))) { if ((buf[0] != 037) || ((buf[1] != 0213) && (buf[1] != 0236))) { DBG_FLT("binfmt_flat: unknown compression magic?\n"); pr_debug("unknown compression magic?\n"); goto out_free_buf; goto out_free_buf; } } /* Check gzip method */ /* Check gzip method */ if (buf[2] != 8) { if (buf[2] != 8) { DBG_FLT("binfmt_flat: unknown compression method?\n"); pr_debug("unknown compression method?\n"); goto out_free_buf; goto out_free_buf; } } /* Check gzip flags */ /* Check gzip flags */ if ((buf[3] & ENCRYPTED) || (buf[3] & CONTINUATION) || if ((buf[3] & ENCRYPTED) || (buf[3] & CONTINUATION) || (buf[3] & RESERVED)) { (buf[3] & RESERVED)) { DBG_FLT("binfmt_flat: unknown flags?\n"); pr_debug("unknown flags?\n"); goto out_free_buf; goto out_free_buf; } } Loading @@ -240,7 +232,7 @@ static int decompress_exec( if (buf[3] & EXTRA_FIELD) { if (buf[3] & EXTRA_FIELD) { ret += 2 + buf[10] + (buf[11] << 8); ret += 2 + buf[10] + (buf[11] << 8); if (unlikely(ret >= LBUFSIZE)) { if (unlikely(ret >= LBUFSIZE)) { DBG_FLT("binfmt_flat: buffer overflow (EXTRA)?\n"); pr_debug("buffer overflow (EXTRA)?\n"); goto out_free_buf; goto out_free_buf; } } } } Loading @@ -248,7 +240,7 @@ static int decompress_exec( while (ret < LBUFSIZE && buf[ret++] != 0) while (ret < LBUFSIZE && buf[ret++] != 0) ; ; if (unlikely(ret == LBUFSIZE)) { if (unlikely(ret == LBUFSIZE)) { DBG_FLT("binfmt_flat: buffer overflow (ORIG_NAME)?\n"); pr_debug("buffer overflow (ORIG_NAME)?\n"); goto out_free_buf; goto out_free_buf; } } } } Loading @@ -256,7 +248,7 @@ static int decompress_exec( while (ret < LBUFSIZE && buf[ret++] != 0) while (ret < LBUFSIZE && buf[ret++] != 0) ; ; if (unlikely(ret == LBUFSIZE)) { if (unlikely(ret == LBUFSIZE)) { DBG_FLT("binfmt_flat: buffer overflow (COMMENT)?\n"); pr_debug("buffer overflow (COMMENT)?\n"); goto out_free_buf; goto out_free_buf; } } } } Loading @@ -269,7 +261,7 @@ static int decompress_exec( strm.total_out = 0; strm.total_out = 0; if (zlib_inflateInit2(&strm, -MAX_WBITS) != Z_OK) { if (zlib_inflateInit2(&strm, -MAX_WBITS) != Z_OK) { DBG_FLT("binfmt_flat: zlib init failed?\n"); pr_debug("zlib init failed?\n"); goto out_free_buf; goto out_free_buf; } } Loading @@ -286,7 +278,7 @@ static int decompress_exec( } } if (ret < 0) { if (ret < 0) { DBG_FLT("binfmt_flat: decompression failed (%d), %s\n", pr_debug("decompression failed (%d), %s\n", ret, strm.msg); ret, strm.msg); goto out_zlib; goto out_zlib; } } Loading Loading @@ -323,24 +315,23 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp) r &= 0x00ffffff; /* Trim ID off here */ r &= 0x00ffffff; /* Trim ID off here */ } } if (id >= MAX_SHARED_LIBS) { if (id >= MAX_SHARED_LIBS) { printk("BINFMT_FLAT: reference 0x%lx to shared library %d", pr_err("reference 0x%lx to shared library %d", r, id); r, id); goto failed; goto failed; } } if (curid != id) { if (curid != id) { if (internalp) { if (internalp) { printk("BINFMT_FLAT: reloc address 0x%lx not in same module " pr_err("reloc address 0x%lx not in same module " "(%d != %d)", r, curid, id); "(%d != %d)", r, curid, id); goto failed; goto failed; } else if (!p->lib_list[id].loaded && } else if (!p->lib_list[id].loaded && load_flat_shared_library(id, p) < 0) { load_flat_shared_library(id, p) < 0) { printk("BINFMT_FLAT: failed to load library %d", id); pr_err("failed to load library %d", id); goto failed; goto failed; } } /* Check versioning information (i.e. time stamps) */ /* Check versioning information (i.e. time stamps) */ if (p->lib_list[id].build_date && p->lib_list[curid].build_date && if (p->lib_list[id].build_date && p->lib_list[curid].build_date && p->lib_list[curid].build_date < p->lib_list[id].build_date) { p->lib_list[curid].build_date < p->lib_list[id].build_date) { printk("BINFMT_FLAT: library %d is younger than %d", id, curid); pr_err("library %d is younger than %d", id, curid); goto failed; goto failed; } } } } Loading @@ -354,7 +345,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp) text_len = p->lib_list[id].text_len; text_len = p->lib_list[id].text_len; if (!flat_reloc_valid(r, start_brk - start_data + text_len)) { if (!flat_reloc_valid(r, start_brk - start_data + text_len)) { printk("BINFMT_FLAT: reloc outside program 0x%lx (0 - 0x%lx/0x%lx)", pr_err("reloc outside program 0x%lx (0 - 0x%lx/0x%lx)", r, start_brk-start_data+text_len, text_len); r, start_brk-start_data+text_len, text_len); goto failed; goto failed; } } Loading @@ -368,7 +359,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp) return addr; return addr; failed: failed: printk(", killing %s!\n", current->comm); pr_cont(", killing %s!\n", current->comm); send_sig(SIGSEGV, current, 0); send_sig(SIGSEGV, current, 0); return RELOC_FAILED; return RELOC_FAILED; Loading @@ -378,9 +369,7 @@ calc_reloc(unsigned long r, struct lib_info *p, int curid, int internalp) static void old_reloc(unsigned long rl) static void old_reloc(unsigned long rl) { { #ifdef DEBUG static const char *segment[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" }; static const char *segment[] = { "TEXT", "DATA", "BSS", "*UNKNOWN*" }; #endif flat_v2_reloc_t r; flat_v2_reloc_t r; unsigned long *ptr; unsigned long *ptr; Loading @@ -391,11 +380,9 @@ static void old_reloc(unsigned long rl) ptr = (unsigned long *) (current->mm->start_data + r.reloc.offset); ptr = (unsigned long *) (current->mm->start_data + r.reloc.offset); #endif #endif #ifdef DEBUG pr_debug("Relocation of variable at DATASEG+%x " printk("Relocation of variable at DATASEG+%x " "(address %p, currently %lx) into segment %s\n", "(address %p, currently %lx) into segment %s\n", r.reloc.offset, ptr, *ptr, segment[r.reloc.type]); r.reloc.offset, ptr, *ptr, segment[r.reloc.type]); #endif switch (r.reloc.type) { switch (r.reloc.type) { case OLD_FLAT_RELOC_TYPE_TEXT: case OLD_FLAT_RELOC_TYPE_TEXT: Loading @@ -408,13 +395,11 @@ static void old_reloc(unsigned long rl) *ptr += current->mm->end_data; *ptr += current->mm->end_data; break; break; default: default: printk("BINFMT_FLAT: Unknown relocation type=%x\n", r.reloc.type); pr_err("Unknown relocation type=%x\n", r.reloc.type); break; break; } } #ifdef DEBUG pr_debug("Relocation became %lx\n", *ptr); printk("Relocation became %lx\n", *ptr); #endif } } /****************************************************************************/ /****************************************************************************/ Loading Loading @@ -463,11 +448,10 @@ static int load_flat_file(struct linux_binprm *bprm, } } if (flags & FLAT_FLAG_KTRACE) if (flags & FLAT_FLAG_KTRACE) printk("BINFMT_FLAT: Loading file: %s\n", bprm->filename); pr_info("Loading file: %s\n", bprm->filename); if (rev != FLAT_VERSION && rev != OLD_FLAT_VERSION) { if (rev != FLAT_VERSION && rev != OLD_FLAT_VERSION) { printk("BINFMT_FLAT: bad flat file version 0x%x (supported " pr_err("bad flat file version 0x%x (supported 0x%lx and 0x%lx)\n", "0x%lx and 0x%lx)\n", rev, FLAT_VERSION, OLD_FLAT_VERSION); rev, FLAT_VERSION, OLD_FLAT_VERSION); ret = -ENOEXEC; ret = -ENOEXEC; goto err; goto err; Loading @@ -475,7 +459,7 @@ static int load_flat_file(struct linux_binprm *bprm, /* Don't allow old format executables to use shared libraries */ /* Don't allow old format executables to use shared libraries */ if (rev == OLD_FLAT_VERSION && id != 0) { if (rev == OLD_FLAT_VERSION && id != 0) { printk("BINFMT_FLAT: shared libraries are not available before rev 0x%lx\n", pr_err("shared libraries are not available before rev 0x%lx\n", FLAT_VERSION); FLAT_VERSION); ret = -ENOEXEC; ret = -ENOEXEC; goto err; goto err; Loading @@ -490,7 +474,7 @@ static int load_flat_file(struct linux_binprm *bprm, #ifndef CONFIG_BINFMT_ZFLAT #ifndef CONFIG_BINFMT_ZFLAT if (flags & (FLAT_FLAG_GZIP|FLAT_FLAG_GZDATA)) { if (flags & (FLAT_FLAG_GZIP|FLAT_FLAG_GZDATA)) { printk("Support for ZFLAT executables is not enabled.\n"); pr_err("Support for ZFLAT executables is not enabled.\n"); ret = -ENOEXEC; ret = -ENOEXEC; goto err; goto err; } } Loading Loading @@ -536,7 +520,7 @@ static int load_flat_file(struct linux_binprm *bprm, * this should give us a ROM ptr, but if it doesn't we don't * this should give us a ROM ptr, but if it doesn't we don't * really care * really care */ */ DBG_FLT("BINFMT_FLAT: ROM mapping of file (we hope)\n"); pr_debug("ROM mapping of file (we hope)\n"); textpos = vm_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC, textpos = vm_mmap(bprm->file, 0, text_len, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_EXECUTABLE, 0); MAP_PRIVATE|MAP_EXECUTABLE, 0); Loading @@ -544,7 +528,7 @@ static int load_flat_file(struct linux_binprm *bprm, ret = textpos; ret = textpos; if (!textpos) if (!textpos) ret = -ENOMEM; ret = -ENOMEM; printk("Unable to mmap process text, errno %d\n", ret); pr_err("Unable to mmap process text, errno %d\n", ret); goto err; goto err; } } Loading @@ -557,7 +541,7 @@ static int load_flat_file(struct linux_binprm *bprm, ret = realdatastart; ret = realdatastart; if (!realdatastart) if (!realdatastart) ret = -ENOMEM; ret = -ENOMEM; printk("Unable to allocate RAM for process data, " pr_err("Unable to allocate RAM for process data, " "errno %d\n", ret); "errno %d\n", ret); vm_munmap(textpos, text_len); vm_munmap(textpos, text_len); goto err; goto err; Loading @@ -566,7 +550,7 @@ static int load_flat_file(struct linux_binprm *bprm, MAX_SHARED_LIBS * sizeof(unsigned long), MAX_SHARED_LIBS * sizeof(unsigned long), FLAT_DATA_ALIGN); FLAT_DATA_ALIGN); DBG_FLT("BINFMT_FLAT: Allocated data+bss+stack (%ld bytes): %lx\n", pr_debug("Allocated data+bss+stack (%ld bytes): %lx\n", data_len + bss_len + stack_len, datapos); data_len + bss_len + stack_len, datapos); fpos = ntohl(hdr->data_start); fpos = ntohl(hdr->data_start); Loading @@ -582,7 +566,7 @@ static int load_flat_file(struct linux_binprm *bprm, } } if (IS_ERR_VALUE(result)) { if (IS_ERR_VALUE(result)) { ret = result; ret = result; printk("Unable to read data+bss, errno %d\n", ret); pr_err("Unable to read data+bss, errno %d\n", ret); vm_munmap(textpos, text_len); vm_munmap(textpos, text_len); vm_munmap(realdatastart, len); vm_munmap(realdatastart, len); goto err; goto err; Loading @@ -603,7 +587,7 @@ static int load_flat_file(struct linux_binprm *bprm, ret = textpos; ret = textpos; if (!textpos) if (!textpos) ret = -ENOMEM; ret = -ENOMEM; printk("Unable to allocate RAM for process text/data, " pr_err("Unable to allocate RAM for process text/data, " "errno %d\n", ret); "errno %d\n", ret); goto err; goto err; } } Loading Loading @@ -645,7 +629,7 @@ static int load_flat_file(struct linux_binprm *bprm, } } if (IS_ERR_VALUE(result)) { if (IS_ERR_VALUE(result)) { ret = result; ret = result; printk("Unable to read code+data+bss, errno %d\n", ret); pr_err("Unable to read code+data+bss, errno %d\n", ret); vm_munmap(textpos, text_len + data_len + extra + vm_munmap(textpos, text_len + data_len + extra + MAX_SHARED_LIBS * sizeof(unsigned long)); MAX_SHARED_LIBS * sizeof(unsigned long)); goto err; goto err; Loading Loading @@ -675,9 +659,9 @@ static int load_flat_file(struct linux_binprm *bprm, } } if (flags & FLAT_FLAG_KTRACE) { if (flags & FLAT_FLAG_KTRACE) { printk("Mapping is %lx, Entry point is %x, data_start is %x\n", pr_info("Mapping is %lx, Entry point is %x, data_start is %x\n", textpos, 0x00ffffff&ntohl(hdr->entry), ntohl(hdr->data_start)); textpos, 0x00ffffff&ntohl(hdr->entry), ntohl(hdr->data_start)); printk("%s %s: TEXT=%lx-%lx DATA=%lx-%lx BSS=%lx-%lx\n", pr_info("%s %s: TEXT=%lx-%lx DATA=%lx-%lx BSS=%lx-%lx\n", id ? "Lib" : "Load", bprm->filename, id ? "Lib" : "Load", bprm->filename, start_code, end_code, datapos, datapos + data_len, start_code, end_code, datapos, datapos + data_len, datapos + data_len, (datapos + data_len + bss_len + 3) & ~3); datapos + data_len, (datapos + data_len + bss_len + 3) & ~3); Loading Loading @@ -890,7 +874,7 @@ static int load_flat_binary(struct linux_binprm *bprm) set_binfmt(&flat_format); set_binfmt(&flat_format); p = ((current->mm->context.end_brk + stack_len + 3) & ~3) - 4; p = ((current->mm->context.end_brk + stack_len + 3) & ~3) - 4; DBG_FLT("p=%lx\n", p); pr_debug("p=%lx\n", p); /* copy the arg pages onto the stack, this could be more efficient :-) */ /* copy the arg pages onto the stack, this could be more efficient :-) */ for (i = TOP_OF_ARGS - 1; i >= bprm->p; i--) for (i = TOP_OF_ARGS - 1; i >= bprm->p; i--) Loading Loading @@ -922,7 +906,7 @@ static int load_flat_binary(struct linux_binprm *bprm) FLAT_PLAT_INIT(regs); FLAT_PLAT_INIT(regs); #endif #endif DBG_FLT("start_thread(regs=0x%p, entry=0x%lx, start_stack=0x%lx)\n", pr_debug("start_thread(regs=0x%p, entry=0x%lx, start_stack=0x%lx)\n", regs, start_addr, current->mm->start_stack); regs, start_addr, current->mm->start_stack); start_thread(regs, start_addr, current->mm->start_stack); start_thread(regs, start_addr, current->mm->start_stack); Loading