Loading fs/binfmt_elf_fdpic.c +31 −79 Original line number Original line Diff line number Diff line Loading @@ -1267,35 +1267,23 @@ static int notesize(struct memelfnote *en) /* #define DEBUG */ /* #define DEBUG */ #define DUMP_WRITE(addr, nr, foffset) \ static int alignfile(struct coredump_params *cprm) do { if (!dump_write(file, (addr), (nr))) return 0; *foffset += (nr); } while(0) static int alignfile(struct file *file, loff_t *foffset) { { static const char buf[4] = { 0, }; static const char buf[4] = { 0, }; DUMP_WRITE(buf, roundup(*foffset, 4) - *foffset, foffset); return dump_emit(cprm, buf, roundup(cprm->written, 4) - cprm->written); return 1; } } static int writenote(struct memelfnote *men, struct file *file, static int writenote(struct memelfnote *men, struct coredump_params *cprm) loff_t *foffset) { { struct elf_note en; struct elf_note en; en.n_namesz = strlen(men->name) + 1; en.n_namesz = strlen(men->name) + 1; en.n_descsz = men->datasz; en.n_descsz = men->datasz; en.n_type = men->type; en.n_type = men->type; DUMP_WRITE(&en, sizeof(en), foffset); return dump_emit(cprm, &en, sizeof(en)) && DUMP_WRITE(men->name, en.n_namesz, foffset); dump_emit(cprm, men->name, en.n_namesz) && alignfile(cprm) && if (!alignfile(file, foffset)) dump_emit(cprm, men->data, men->datasz) && alignfile(cprm); return 0; DUMP_WRITE(men->data, men->datasz, foffset); if (!alignfile(file, foffset)) return 0; return 1; } } #undef DUMP_WRITE static inline void fill_elf_fdpic_header(struct elfhdr *elf, int segs) static inline void fill_elf_fdpic_header(struct elfhdr *elf, int segs) { { Loading Loading @@ -1500,66 +1488,40 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum, /* /* * dump the segments for an MMU process * dump the segments for an MMU process */ */ #ifdef CONFIG_MMU static bool elf_fdpic_dump_segments(struct coredump_params *cprm) static int elf_fdpic_dump_segments(struct file *file, size_t *size, unsigned long *limit, unsigned long mm_flags) { { struct vm_area_struct *vma; struct vm_area_struct *vma; int err = 0; for (vma = current->mm->mmap; vma; vma = vma->vm_next) { for (vma = current->mm->mmap; vma; vma = vma->vm_next) { unsigned long addr; unsigned long addr; if (!maydump(vma, mm_flags)) if (!maydump(vma, cprm->mm_flags)) continue; continue; #ifdef CONFIG_MMU for (addr = vma->vm_start; addr < vma->vm_end; for (addr = vma->vm_start; addr < vma->vm_end; addr += PAGE_SIZE) { addr += PAGE_SIZE) { bool res; struct page *page = get_dump_page(addr); struct page *page = get_dump_page(addr); if (page) { if (page) { void *kaddr = kmap(page); void *kaddr = kmap(page); *size += PAGE_SIZE; res = dump_emit(cprm, kaddr, PAGE_SIZE); if (*size > *limit) err = -EFBIG; else if (!dump_write(file, kaddr, PAGE_SIZE)) err = -EIO; kunmap(page); kunmap(page); page_cache_release(page); page_cache_release(page); } else if (!dump_seek(file, PAGE_SIZE)) } else { err = -EFBIG; res = dump_seek(file, PAGE_SIZE); if (err) goto out; } } } out: if (!res) return err; return false; } } #endif #else if (!dump_emit(cprm, (void *) vma->vm_start, /* * dump the segments for a NOMMU process */ #ifndef CONFIG_MMU static int elf_fdpic_dump_segments(struct file *file, size_t *size, unsigned long *limit, unsigned long mm_flags) { struct vm_area_struct *vma; for (vma = current->mm->mmap; vma; vma = vma->vm_next) { if (!maydump(vma, mm_flags)) continue; if ((*size += PAGE_SIZE) > *limit) return -EFBIG; if (!dump_write(file, (void *) vma->vm_start, vma->vm_end - vma->vm_start)) vma->vm_end - vma->vm_start)) return -EIO; return false; #endif } } return true; return 0; } } #endif static size_t elf_core_vma_data_size(unsigned long mm_flags) static size_t elf_core_vma_data_size(unsigned long mm_flags) { { Loading Loading @@ -1755,13 +1717,10 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm) offset = dataoff; offset = dataoff; size += sizeof(*elf); if (!dump_emit(cprm, elf, sizeof(*elf))) if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf))) goto end_coredump; goto end_coredump; size += sizeof(*phdr4note); if (!dump_emit(cprm, phdr4note, sizeof(*phdr4note))) if (size > cprm->limit || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note))) goto end_coredump; goto end_coredump; /* write program headers for segments dump */ /* write program headers for segments dump */ Loading @@ -1785,20 +1744,18 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm) phdr.p_flags |= PF_X; phdr.p_flags |= PF_X; phdr.p_align = ELF_EXEC_PAGESIZE; phdr.p_align = ELF_EXEC_PAGESIZE; size += sizeof(phdr); if (!dump_emit(cprm, &phdr, sizeof(phdr))) if (size > cprm->limit || !dump_write(cprm->file, &phdr, sizeof(phdr))) goto end_coredump; goto end_coredump; } } cprm->written = size; if (!elf_core_write_extra_phdrs(cprm, offset)) if (!elf_core_write_extra_phdrs(cprm, offset)) goto end_coredump; goto end_coredump; size = cprm->written; size = cprm->written; cprm->written = foffset; /* write out the notes section */ /* write out the notes section */ for (i = 0; i < numnote; i++) for (i = 0; i < numnote; i++) if (!writenote(notes + i, cprm->file, &foffset)) if (!writenote(notes + i, cprm)) goto end_coredump; goto end_coredump; /* write out the thread status notes section */ /* write out the thread status notes section */ Loading @@ -1807,27 +1764,22 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm) list_entry(t, struct elf_thread_status, list); list_entry(t, struct elf_thread_status, list); for (i = 0; i < tmp->num_notes; i++) for (i = 0; i < tmp->num_notes; i++) if (!writenote(&tmp->notes[i], cprm->file, &foffset)) if (!writenote(&tmp->notes[i], cprm)) goto end_coredump; goto end_coredump; } } if (!dump_seek(cprm->file, dataoff - foffset)) if (!dump_seek(cprm->file, dataoff - cprm->written)) goto end_coredump; goto end_coredump; if (elf_fdpic_dump_segments(cprm->file, &size, &cprm->limit, cprm->written = size; cprm->mm_flags) < 0) if (!elf_fdpic_dump_segments(cprm)) goto end_coredump; goto end_coredump; cprm->written = size; if (!elf_core_write_extra_data(cprm)) if (!elf_core_write_extra_data(cprm)) goto end_coredump; goto end_coredump; size = cprm->written; if (e_phnum == PN_XNUM) { if (e_phnum == PN_XNUM) { size += sizeof(*shdr4extnum); if (!dump_emit(cprm, shdr4extnum, sizeof(*shdr4extnum))) if (size > cprm->limit || !dump_write(cprm->file, shdr4extnum, sizeof(*shdr4extnum))) goto end_coredump; goto end_coredump; } } Loading Loading
fs/binfmt_elf_fdpic.c +31 −79 Original line number Original line Diff line number Diff line Loading @@ -1267,35 +1267,23 @@ static int notesize(struct memelfnote *en) /* #define DEBUG */ /* #define DEBUG */ #define DUMP_WRITE(addr, nr, foffset) \ static int alignfile(struct coredump_params *cprm) do { if (!dump_write(file, (addr), (nr))) return 0; *foffset += (nr); } while(0) static int alignfile(struct file *file, loff_t *foffset) { { static const char buf[4] = { 0, }; static const char buf[4] = { 0, }; DUMP_WRITE(buf, roundup(*foffset, 4) - *foffset, foffset); return dump_emit(cprm, buf, roundup(cprm->written, 4) - cprm->written); return 1; } } static int writenote(struct memelfnote *men, struct file *file, static int writenote(struct memelfnote *men, struct coredump_params *cprm) loff_t *foffset) { { struct elf_note en; struct elf_note en; en.n_namesz = strlen(men->name) + 1; en.n_namesz = strlen(men->name) + 1; en.n_descsz = men->datasz; en.n_descsz = men->datasz; en.n_type = men->type; en.n_type = men->type; DUMP_WRITE(&en, sizeof(en), foffset); return dump_emit(cprm, &en, sizeof(en)) && DUMP_WRITE(men->name, en.n_namesz, foffset); dump_emit(cprm, men->name, en.n_namesz) && alignfile(cprm) && if (!alignfile(file, foffset)) dump_emit(cprm, men->data, men->datasz) && alignfile(cprm); return 0; DUMP_WRITE(men->data, men->datasz, foffset); if (!alignfile(file, foffset)) return 0; return 1; } } #undef DUMP_WRITE static inline void fill_elf_fdpic_header(struct elfhdr *elf, int segs) static inline void fill_elf_fdpic_header(struct elfhdr *elf, int segs) { { Loading Loading @@ -1500,66 +1488,40 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum, /* /* * dump the segments for an MMU process * dump the segments for an MMU process */ */ #ifdef CONFIG_MMU static bool elf_fdpic_dump_segments(struct coredump_params *cprm) static int elf_fdpic_dump_segments(struct file *file, size_t *size, unsigned long *limit, unsigned long mm_flags) { { struct vm_area_struct *vma; struct vm_area_struct *vma; int err = 0; for (vma = current->mm->mmap; vma; vma = vma->vm_next) { for (vma = current->mm->mmap; vma; vma = vma->vm_next) { unsigned long addr; unsigned long addr; if (!maydump(vma, mm_flags)) if (!maydump(vma, cprm->mm_flags)) continue; continue; #ifdef CONFIG_MMU for (addr = vma->vm_start; addr < vma->vm_end; for (addr = vma->vm_start; addr < vma->vm_end; addr += PAGE_SIZE) { addr += PAGE_SIZE) { bool res; struct page *page = get_dump_page(addr); struct page *page = get_dump_page(addr); if (page) { if (page) { void *kaddr = kmap(page); void *kaddr = kmap(page); *size += PAGE_SIZE; res = dump_emit(cprm, kaddr, PAGE_SIZE); if (*size > *limit) err = -EFBIG; else if (!dump_write(file, kaddr, PAGE_SIZE)) err = -EIO; kunmap(page); kunmap(page); page_cache_release(page); page_cache_release(page); } else if (!dump_seek(file, PAGE_SIZE)) } else { err = -EFBIG; res = dump_seek(file, PAGE_SIZE); if (err) goto out; } } } out: if (!res) return err; return false; } } #endif #else if (!dump_emit(cprm, (void *) vma->vm_start, /* * dump the segments for a NOMMU process */ #ifndef CONFIG_MMU static int elf_fdpic_dump_segments(struct file *file, size_t *size, unsigned long *limit, unsigned long mm_flags) { struct vm_area_struct *vma; for (vma = current->mm->mmap; vma; vma = vma->vm_next) { if (!maydump(vma, mm_flags)) continue; if ((*size += PAGE_SIZE) > *limit) return -EFBIG; if (!dump_write(file, (void *) vma->vm_start, vma->vm_end - vma->vm_start)) vma->vm_end - vma->vm_start)) return -EIO; return false; #endif } } return true; return 0; } } #endif static size_t elf_core_vma_data_size(unsigned long mm_flags) static size_t elf_core_vma_data_size(unsigned long mm_flags) { { Loading Loading @@ -1755,13 +1717,10 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm) offset = dataoff; offset = dataoff; size += sizeof(*elf); if (!dump_emit(cprm, elf, sizeof(*elf))) if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf))) goto end_coredump; goto end_coredump; size += sizeof(*phdr4note); if (!dump_emit(cprm, phdr4note, sizeof(*phdr4note))) if (size > cprm->limit || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note))) goto end_coredump; goto end_coredump; /* write program headers for segments dump */ /* write program headers for segments dump */ Loading @@ -1785,20 +1744,18 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm) phdr.p_flags |= PF_X; phdr.p_flags |= PF_X; phdr.p_align = ELF_EXEC_PAGESIZE; phdr.p_align = ELF_EXEC_PAGESIZE; size += sizeof(phdr); if (!dump_emit(cprm, &phdr, sizeof(phdr))) if (size > cprm->limit || !dump_write(cprm->file, &phdr, sizeof(phdr))) goto end_coredump; goto end_coredump; } } cprm->written = size; if (!elf_core_write_extra_phdrs(cprm, offset)) if (!elf_core_write_extra_phdrs(cprm, offset)) goto end_coredump; goto end_coredump; size = cprm->written; size = cprm->written; cprm->written = foffset; /* write out the notes section */ /* write out the notes section */ for (i = 0; i < numnote; i++) for (i = 0; i < numnote; i++) if (!writenote(notes + i, cprm->file, &foffset)) if (!writenote(notes + i, cprm)) goto end_coredump; goto end_coredump; /* write out the thread status notes section */ /* write out the thread status notes section */ Loading @@ -1807,27 +1764,22 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm) list_entry(t, struct elf_thread_status, list); list_entry(t, struct elf_thread_status, list); for (i = 0; i < tmp->num_notes; i++) for (i = 0; i < tmp->num_notes; i++) if (!writenote(&tmp->notes[i], cprm->file, &foffset)) if (!writenote(&tmp->notes[i], cprm)) goto end_coredump; goto end_coredump; } } if (!dump_seek(cprm->file, dataoff - foffset)) if (!dump_seek(cprm->file, dataoff - cprm->written)) goto end_coredump; goto end_coredump; if (elf_fdpic_dump_segments(cprm->file, &size, &cprm->limit, cprm->written = size; cprm->mm_flags) < 0) if (!elf_fdpic_dump_segments(cprm)) goto end_coredump; goto end_coredump; cprm->written = size; if (!elf_core_write_extra_data(cprm)) if (!elf_core_write_extra_data(cprm)) goto end_coredump; goto end_coredump; size = cprm->written; if (e_phnum == PN_XNUM) { if (e_phnum == PN_XNUM) { size += sizeof(*shdr4extnum); if (!dump_emit(cprm, shdr4extnum, sizeof(*shdr4extnum))) if (size > cprm->limit || !dump_write(cprm->file, shdr4extnum, sizeof(*shdr4extnum))) goto end_coredump; goto end_coredump; } } Loading