diff options
author | Stephen Rothwell <sfr@canb.auug.org.au> | 2013-08-09 11:13:16 +1000 |
---|---|---|
committer | Stephen Rothwell <sfr@canb.auug.org.au> | 2013-08-09 11:13:16 +1000 |
commit | 5af7cf3a8ca95eff9a6cdfafeeb7bdba3a38e748 (patch) | |
tree | d2d3499646443b414b696e4cf4c485448a4777e1 /fs | |
parent | 5c6c11534be75e034e2e246dbb136fb07067af80 (diff) | |
parent | d405be48a4c3f37f7a8e5648a5db204738272c61 (diff) |
Merge remote-tracking branch 'vfs/for-next'
Conflicts:
fs/ext4/namei.c
mm/shmem.c
Diffstat (limited to 'fs')
-rw-r--r-- | fs/binfmt_aout.c | 9 | ||||
-rw-r--r-- | fs/binfmt_elf.c | 84 | ||||
-rw-r--r-- | fs/binfmt_elf_fdpic.c | 87 | ||||
-rw-r--r-- | fs/coredump.c | 62 |
4 files changed, 106 insertions, 136 deletions
diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c index 89dec7f789a4..b3192da97cab 100644 --- a/fs/binfmt_aout.c +++ b/fs/binfmt_aout.c @@ -45,7 +45,6 @@ static int load_aout_library(struct file*); */ static int aout_core_dump(struct coredump_params *cprm) { - struct file *file = cprm->file; mm_segment_t fs; int has_dumped = 0; void __user *dump_start; @@ -85,10 +84,10 @@ static int aout_core_dump(struct coredump_params *cprm) set_fs(KERNEL_DS); /* struct user */ - if (!dump_write(file, &dump, sizeof(dump))) + if (!dump_emit(cprm, &dump, sizeof(dump))) goto end_coredump; /* Now dump all of the user data. Include malloced stuff as well */ - if (!dump_seek(cprm->file, PAGE_SIZE - sizeof(dump))) + if (!dump_align(cprm, PAGE_SIZE)) goto end_coredump; /* now we start writing out the user space info */ set_fs(USER_DS); @@ -96,14 +95,14 @@ static int aout_core_dump(struct coredump_params *cprm) if (dump.u_dsize != 0) { dump_start = START_DATA(dump); dump_size = dump.u_dsize << PAGE_SHIFT; - if (!dump_write(file, dump_start, dump_size)) + if (!dump_emit(cprm, dump_start, dump_size)) goto end_coredump; } /* Now prepare to dump the stack area */ if (dump.u_ssize != 0) { dump_start = START_STACK(dump); dump_size = dump.u_ssize << PAGE_SHIFT; - if (!dump_write(file, dump_start, dump_size)) + if (!dump_emit(cprm, dump_start, dump_size)) goto end_coredump; } end_coredump: diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 100edcc5e312..7d863a4de5a5 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1225,35 +1225,32 @@ static int notesize(struct memelfnote *en) return sz; } -#define DUMP_WRITE(addr, nr, foffset) \ - do { if (!dump_write(file, (addr), (nr))) return 0; *foffset += (nr); } while(0) - -static int alignfile(struct file *file, loff_t *foffset) +static int alignfile(struct coredump_params *cprm) { static const char buf[4] = { 0, }; - DUMP_WRITE(buf, roundup(*foffset, 4) - *foffset, foffset); - return 1; + return dump_emit(cprm, buf, roundup(cprm->written, 4) - cprm->written); } -static int writenote(struct memelfnote *men, struct file *file, - loff_t *foffset) +static int writenote(struct memelfnote *men, struct coredump_params *cprm) { struct elf_note en; en.n_namesz = strlen(men->name) + 1; en.n_descsz = men->datasz; en.n_type = men->type; - DUMP_WRITE(&en, sizeof(en), foffset); - DUMP_WRITE(men->name, en.n_namesz, foffset); - if (!alignfile(file, foffset)) + if (!dump_emit(cprm, &en, sizeof(en))) + return 0; + if (!dump_emit(cprm, men->name, en.n_namesz)) + return 0; + if (!alignfile(cprm)) return 0; - DUMP_WRITE(men->data, men->datasz, foffset); - if (!alignfile(file, foffset)) + if (!dump_emit(cprm, men->data, men->datasz)) + return 0; + if (!alignfile(cprm)) return 0; return 1; } -#undef DUMP_WRITE static void fill_elf_header(struct elfhdr *elf, int segs, u16 machine, u32 flags) @@ -1702,7 +1699,7 @@ static size_t get_note_info_size(struct elf_note_info *info) * process-wide notes are interleaved after the first thread-specific note. */ static int write_note_info(struct elf_note_info *info, - struct file *file, loff_t *foffset) + struct coredump_params *cprm) { bool first = 1; struct elf_thread_core_info *t = info->thread; @@ -1710,21 +1707,21 @@ static int write_note_info(struct elf_note_info *info, do { int i; - if (!writenote(&t->notes[0], file, foffset)) + if (!writenote(&t->notes[0], cprm)) return 0; - if (first && !writenote(&info->psinfo, file, foffset)) + if (first && !writenote(&info->psinfo, cprm)) return 0; - if (first && !writenote(&info->signote, file, foffset)) + if (first && !writenote(&info->signote, cprm)) return 0; - if (first && !writenote(&info->auxv, file, foffset)) + if (first && !writenote(&info->auxv, cprm)) return 0; - if (first && !writenote(&info->files, file, foffset)) + if (first && !writenote(&info->files, cprm)) return 0; for (i = 1; i < info->thread_notes; ++i) if (t->notes[i].data && - !writenote(&t->notes[i], file, foffset)) + !writenote(&t->notes[i], cprm)) return 0; first = 0; @@ -1930,13 +1927,13 @@ static size_t get_note_info_size(struct elf_note_info *info) } static int write_note_info(struct elf_note_info *info, - struct file *file, loff_t *foffset) + struct coredump_params *cprm) { int i; struct list_head *t; for (i = 0; i < info->numnote; i++) - if (!writenote(info->notes + i, file, foffset)) + if (!writenote(info->notes + i, cprm)) return 0; /* write out the thread status notes section */ @@ -1945,7 +1942,7 @@ static int write_note_info(struct elf_note_info *info, list_entry(t, struct elf_thread_status, list); for (i = 0; i < tmp->num_notes; i++) - if (!writenote(&tmp->notes[i], file, foffset)) + if (!writenote(&tmp->notes[i], cprm)) return 0; } @@ -2040,10 +2037,9 @@ static int elf_core_dump(struct coredump_params *cprm) int has_dumped = 0; mm_segment_t fs; int segs; - size_t size = 0; struct vm_area_struct *vma, *gate_vma; struct elfhdr *elf = NULL; - loff_t offset = 0, dataoff, foffset; + loff_t offset = 0, dataoff; struct elf_note_info info; struct elf_phdr *phdr4note = NULL; struct elf_shdr *shdr4extnum = NULL; @@ -2099,7 +2095,6 @@ static int elf_core_dump(struct coredump_params *cprm) offset += sizeof(*elf); /* Elf header */ offset += segs * sizeof(struct elf_phdr); /* Program headers */ - foffset = offset; /* Write notes phdr entry */ { @@ -2130,13 +2125,10 @@ static int elf_core_dump(struct coredump_params *cprm) offset = dataoff; - size += sizeof(*elf); - if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf))) + if (!dump_emit(cprm, elf, sizeof(*elf))) goto end_coredump; - size += sizeof(*phdr4note); - if (size > cprm->limit - || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note))) + if (!dump_emit(cprm, phdr4note, sizeof(*phdr4note))) goto end_coredump; /* Write program headers for segments dump */ @@ -2158,24 +2150,22 @@ static int elf_core_dump(struct coredump_params *cprm) phdr.p_flags |= PF_X; phdr.p_align = ELF_EXEC_PAGESIZE; - size += sizeof(phdr); - if (size > cprm->limit - || !dump_write(cprm->file, &phdr, sizeof(phdr))) + if (!dump_emit(cprm, &phdr, sizeof(phdr))) goto end_coredump; } - if (!elf_core_write_extra_phdrs(cprm->file, offset, &size, cprm->limit)) + if (!elf_core_write_extra_phdrs(cprm, offset)) goto end_coredump; /* write out the notes section */ - if (!write_note_info(&info, cprm->file, &foffset)) + if (!write_note_info(&info, cprm)) goto end_coredump; - if (elf_coredump_extra_notes_write(cprm->file, &foffset)) + if (elf_coredump_extra_notes_write(cprm)) goto end_coredump; /* Align to page */ - if (!dump_seek(cprm->file, dataoff - foffset)) + if (!dump_align(cprm, ELF_EXEC_PAGESIZE)) goto end_coredump; for (vma = first_vma(current, gate_vma); vma != NULL; @@ -2192,28 +2182,22 @@ static int elf_core_dump(struct coredump_params *cprm) page = get_dump_page(addr); if (page) { void *kaddr = kmap(page); - stop = ((size += PAGE_SIZE) > cprm->limit) || - !dump_write(cprm->file, kaddr, - PAGE_SIZE); + stop = !dump_emit(cprm, kaddr, PAGE_SIZE); kunmap(page); page_cache_release(page); } else - stop = !dump_seek(cprm->file, PAGE_SIZE); + stop = !dump_skip(cprm, PAGE_SIZE); if (stop) goto end_coredump; } } - if (!elf_core_write_extra_data(cprm->file, &size, cprm->limit)) + if (!elf_core_write_extra_data(cprm)) goto end_coredump; - if (e_phnum == PN_XNUM) { - size += sizeof(*shdr4extnum); - if (size > cprm->limit - || !dump_write(cprm->file, shdr4extnum, - sizeof(*shdr4extnum))) + if (e_phnum == PN_XNUM) + if (!dump_emit(cprm, shdr4extnum, sizeof(*shdr4extnum))) goto end_coredump; - } end_coredump: set_fs(fs); diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index c166f325a183..85c23c496999 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -1207,7 +1207,7 @@ static int maydump(struct vm_area_struct *vma, unsigned long mm_flags) } /* If we may not read the contents, don't allow us to dump - * them either. "dump_write()" can't handle it anyway. + * them either. "dump_emit()" can't handle it anyway. */ if (!(vma->vm_flags & VM_READ)) { kdcore("%08lx: %08lx: no (!read)", vma->vm_start, vma->vm_flags); @@ -1267,35 +1267,26 @@ static int notesize(struct memelfnote *en) /* #define DEBUG */ -#define DUMP_WRITE(addr, nr, foffset) \ - 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, }; - DUMP_WRITE(buf, roundup(*foffset, 4) - *foffset, foffset); - return 1; -} - -static int writenote(struct memelfnote *men, struct file *file, - loff_t *foffset) +static int writenote(struct memelfnote *men, struct coredump_params *cprm) { struct elf_note en; en.n_namesz = strlen(men->name) + 1; en.n_descsz = men->datasz; en.n_type = men->type; - DUMP_WRITE(&en, sizeof(en), foffset); - DUMP_WRITE(men->name, en.n_namesz, foffset); - if (!alignfile(file, foffset)) + if (!dump_emit(cprm, &en, sizeof(en))) return 0; - DUMP_WRITE(men->data, men->datasz, foffset); - if (!alignfile(file, foffset)) + if (!dump_emit(cprm, men->name, en.n_namesz)) + return 0; + if (!dump_align(cprm, 4)) + return 0; + if (!dump_emit(cprm, men->data, men->datasz)) + return 0; + if (!dump_align(cprm, 4)) return 0; return 1; } -#undef DUMP_WRITE static inline void fill_elf_fdpic_header(struct elfhdr *elf, int segs) { @@ -1501,8 +1492,7 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum, * dump the segments for an MMU process */ #ifdef CONFIG_MMU -static int elf_fdpic_dump_segments(struct file *file, size_t *size, - unsigned long *limit, unsigned long mm_flags) +static int elf_fdpic_dump_segments(struct coredump_params *cprm) { struct vm_area_struct *vma; int err = 0; @@ -1510,7 +1500,7 @@ static int elf_fdpic_dump_segments(struct file *file, size_t *size, for (vma = current->mm->mmap; vma; vma = vma->vm_next) { unsigned long addr; - if (!maydump(vma, mm_flags)) + if (!maydump(vma, cprm->mm_flags)) continue; for (addr = vma->vm_start; addr < vma->vm_end; @@ -1518,14 +1508,11 @@ static int elf_fdpic_dump_segments(struct file *file, size_t *size, struct page *page = get_dump_page(addr); if (page) { void *kaddr = kmap(page); - *size += PAGE_SIZE; - if (*size > *limit) - err = -EFBIG; - else if (!dump_write(file, kaddr, PAGE_SIZE)) + if (!dump_emit(cprm, kaddr, PAGE_SIZE)) err = -EIO; kunmap(page); page_cache_release(page); - } else if (!dump_seek(file, PAGE_SIZE)) + } else if (!dump_skip(cprm, PAGE_SIZE)) err = -EFBIG; if (err) goto out; @@ -1540,19 +1527,15 @@ out: * 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) +static int elf_fdpic_dump_segments(struct coredump_params *cprm) { struct vm_area_struct *vma; for (vma = current->mm->mmap; vma; vma = vma->vm_next) { - if (!maydump(vma, mm_flags)) + if (!maydump(vma, cprm->mm_flags)) continue; - if ((*size += PAGE_SIZE) > *limit) - return -EFBIG; - - if (!dump_write(file, (void *) vma->vm_start, + if (!dump_emit(cprm, (void *) vma->vm_start, vma->vm_end - vma->vm_start)) return -EIO; } @@ -1585,7 +1568,6 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm) int has_dumped = 0; mm_segment_t fs; int segs; - size_t size = 0; int i; struct vm_area_struct *vma; struct elfhdr *elf = NULL; @@ -1755,13 +1737,10 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm) offset = dataoff; - size += sizeof(*elf); - if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf))) + if (!dump_emit(cprm, elf, sizeof(*elf))) goto end_coredump; - size += sizeof(*phdr4note); - if (size > cprm->limit - || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note))) + if (!dump_emit(cprm, phdr4note, sizeof(*phdr4note))) goto end_coredump; /* write program headers for segments dump */ @@ -1785,18 +1764,16 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm) phdr.p_flags |= PF_X; phdr.p_align = ELF_EXEC_PAGESIZE; - size += sizeof(phdr); - if (size > cprm->limit - || !dump_write(cprm->file, &phdr, sizeof(phdr))) + if (!dump_emit(cprm, &phdr, sizeof(phdr))) goto end_coredump; } - if (!elf_core_write_extra_phdrs(cprm->file, offset, &size, cprm->limit)) + if (!elf_core_write_extra_phdrs(cprm, offset)) goto end_coredump; /* write out the notes section */ for (i = 0; i < numnote; i++) - if (!writenote(notes + i, cprm->file, &foffset)) + if (!writenote(notes + i, cprm)) goto end_coredump; /* write out the thread status notes section */ @@ -1805,33 +1782,29 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm) list_entry(t, struct elf_thread_status, list); 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; } - if (!dump_seek(cprm->file, dataoff - foffset)) + if (!dump_align(cprm, ELF_EXEC_PAGESIZE)) goto end_coredump; - if (elf_fdpic_dump_segments(cprm->file, &size, &cprm->limit, - cprm->mm_flags) < 0) + if (elf_fdpic_dump_segments(cprm) < 0) goto end_coredump; - if (!elf_core_write_extra_data(cprm->file, &size, cprm->limit)) + if (!elf_core_write_extra_data(cprm)) goto end_coredump; if (e_phnum == PN_XNUM) { - size += sizeof(*shdr4extnum); - if (size > cprm->limit - || !dump_write(cprm->file, shdr4extnum, - sizeof(*shdr4extnum))) + if (!dump_emit(cprm, shdr4extnum, sizeof(*shdr4extnum))) goto end_coredump; } - if (cprm->file->f_pos != offset) { + if (cprm->written != offset) { /* Sanity check */ printk(KERN_WARNING - "elf_core_dump: file->f_pos (%lld) != offset (%lld)\n", - cprm->file->f_pos, offset); + "elf_core_dump: cprm->written (%lld) != offset (%lld)\n", + (long long)cprm->written, offset); } end_coredump: diff --git a/fs/coredump.c b/fs/coredump.c index 72f816d6cad9..fb4e2b7ea07b 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -675,45 +675,59 @@ fail: return; } -/* - * Core dumping helper functions. These are the only things you should - * do on a core-file: use only these functions to write out all the - * necessary info. - */ -int dump_write(struct file *file, const void *addr, int nr) +bool dump_emit(struct coredump_params *cprm, const void *addr, size_t size) { - return !dump_interrupted() && - access_ok(VERIFY_READ, addr, nr) && - file->f_op->write(file, addr, nr, &file->f_pos) == nr; + struct file *file; + loff_t pos; + if (size > cprm->limit - cprm->written || dump_interrupted() || + !access_ok(VERIFY_READ, addr, size)) + return false; + file = cprm->file; + pos = file->f_pos; + if (file->f_op->write(file, addr, size, &pos) != size) + return false; + file->f_pos = pos; + cprm->written += size; + return true; } -EXPORT_SYMBOL(dump_write); +EXPORT_SYMBOL(dump_emit); -int dump_seek(struct file *file, loff_t off) +bool dump_skip(struct coredump_params *cprm, size_t off) { - int ret = 1; + loff_t new = cprm->written + off; + struct file *file = cprm->file; + + if (!off) + return true; + + if (new > cprm->limit) + return false; if (file->f_op->llseek && file->f_op->llseek != no_llseek) { if (dump_interrupted() || - file->f_op->llseek(file, off, SEEK_CUR) < 0) - return 0; + file->f_op->llseek(file, new, SEEK_SET) < 0) + return false; + cprm->written = new; } else { char *buf = (char *)get_zeroed_page(GFP_KERNEL); - if (!buf) - return 0; - while (off > 0) { + return false; + while (off) { unsigned long n = off; - if (n > PAGE_SIZE) n = PAGE_SIZE; - if (!dump_write(file, buf, n)) { - ret = 0; - break; - } + if (!dump_emit(cprm, buf, n)) + return false; off -= n; } free_page((unsigned long)buf); } - return ret; + return true; +} +EXPORT_SYMBOL(dump_skip); + +bool dump_align(struct coredump_params *cprm, int align) +{ + return dump_skip(cprm, roundup(cprm->written, align) - cprm->written); } -EXPORT_SYMBOL(dump_seek); +EXPORT_SYMBOL(dump_align); |