Commit 5e672088 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'work.coredump' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull coredump updates from Al Viro:
 "Just a couple of patches this cycle: use of seek + write instead of
  expanding truncate and minor header cleanup"

* 'work.coredump' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  coredump.h: move CONFIG_COREDUMP-only stuff inside the ifdef
  coredump: don't bother with do_truncate()
parents d1466bc5 a64b8908
...@@ -149,8 +149,7 @@ static int spufs_arch_write_note(struct spu_context *ctx, int i, ...@@ -149,8 +149,7 @@ static int spufs_arch_write_note(struct spu_context *ctx, int i,
return -EIO; return -EIO;
} }
if (!dump_skip(cprm, roundup(cprm->pos - ret + sz, 4) - cprm->pos)) dump_skip_to(cprm, roundup(cprm->pos - ret + sz, 4));
return -EIO;
return 0; return 0;
} }
......
...@@ -2267,8 +2267,7 @@ static int elf_core_dump(struct coredump_params *cprm) ...@@ -2267,8 +2267,7 @@ static int elf_core_dump(struct coredump_params *cprm)
goto end_coredump; goto end_coredump;
/* Align to page */ /* Align to page */
if (!dump_skip(cprm, dataoff - cprm->pos)) dump_skip_to(cprm, dataoff);
goto end_coredump;
for (i = 0; i < vma_count; i++) { for (i = 0; i < vma_count; i++) {
struct core_vma_metadata *meta = vma_meta + i; struct core_vma_metadata *meta = vma_meta + i;
...@@ -2276,7 +2275,6 @@ static int elf_core_dump(struct coredump_params *cprm) ...@@ -2276,7 +2275,6 @@ static int elf_core_dump(struct coredump_params *cprm)
if (!dump_user_range(cprm, meta->start, meta->dump_size)) if (!dump_user_range(cprm, meta->start, meta->dump_size))
goto end_coredump; goto end_coredump;
} }
dump_truncate(cprm);
if (!elf_core_write_extra_data(cprm)) if (!elf_core_write_extra_data(cprm))
goto end_coredump; goto end_coredump;
......
...@@ -1631,8 +1631,7 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm) ...@@ -1631,8 +1631,7 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
goto end_coredump; goto end_coredump;
} }
if (!dump_skip(cprm, dataoff - cprm->pos)) dump_skip_to(cprm, dataoff);
goto end_coredump;
if (!elf_fdpic_dump_segments(cprm, vma_meta, vma_count)) if (!elf_fdpic_dump_segments(cprm, vma_meta, vma_count))
goto end_coredump; goto end_coredump;
......
...@@ -809,6 +809,16 @@ void do_coredump(const kernel_siginfo_t *siginfo) ...@@ -809,6 +809,16 @@ void do_coredump(const kernel_siginfo_t *siginfo)
} }
file_start_write(cprm.file); file_start_write(cprm.file);
core_dumped = binfmt->core_dump(&cprm); core_dumped = binfmt->core_dump(&cprm);
/*
* Ensures that file size is big enough to contain the current
* file postion. This prevents gdb from complaining about
* a truncated file if the last "write" to the file was
* dump_skip.
*/
if (cprm.to_skip) {
cprm.to_skip--;
dump_emit(&cprm, "", 1);
}
file_end_write(cprm.file); file_end_write(cprm.file);
} }
if (ispipe && core_pipe_limit) if (ispipe && core_pipe_limit)
...@@ -835,7 +845,7 @@ void do_coredump(const kernel_siginfo_t *siginfo) ...@@ -835,7 +845,7 @@ void do_coredump(const kernel_siginfo_t *siginfo)
* do on a core-file: use only these functions to write out all the * do on a core-file: use only these functions to write out all the
* necessary info. * necessary info.
*/ */
int dump_emit(struct coredump_params *cprm, const void *addr, int nr) static int __dump_emit(struct coredump_params *cprm, const void *addr, int nr)
{ {
struct file *file = cprm->file; struct file *file = cprm->file;
loff_t pos = file->f_pos; loff_t pos = file->f_pos;
...@@ -855,9 +865,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr) ...@@ -855,9 +865,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
return 1; return 1;
} }
EXPORT_SYMBOL(dump_emit);
int dump_skip(struct coredump_params *cprm, size_t nr) static int __dump_skip(struct coredump_params *cprm, size_t nr)
{ {
static char zeroes[PAGE_SIZE]; static char zeroes[PAGE_SIZE];
struct file *file = cprm->file; struct file *file = cprm->file;
...@@ -869,12 +878,34 @@ int dump_skip(struct coredump_params *cprm, size_t nr) ...@@ -869,12 +878,34 @@ int dump_skip(struct coredump_params *cprm, size_t nr)
return 1; return 1;
} else { } else {
while (nr > PAGE_SIZE) { while (nr > PAGE_SIZE) {
if (!dump_emit(cprm, zeroes, PAGE_SIZE)) if (!__dump_emit(cprm, zeroes, PAGE_SIZE))
return 0; return 0;
nr -= PAGE_SIZE; nr -= PAGE_SIZE;
} }
return dump_emit(cprm, zeroes, nr); return __dump_emit(cprm, zeroes, nr);
}
}
int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
{
if (cprm->to_skip) {
if (!__dump_skip(cprm, cprm->to_skip))
return 0;
cprm->to_skip = 0;
} }
return __dump_emit(cprm, addr, nr);
}
EXPORT_SYMBOL(dump_emit);
void dump_skip_to(struct coredump_params *cprm, unsigned long pos)
{
cprm->to_skip = pos - cprm->pos;
}
EXPORT_SYMBOL(dump_skip_to);
void dump_skip(struct coredump_params *cprm, size_t nr)
{
cprm->to_skip += nr;
} }
EXPORT_SYMBOL(dump_skip); EXPORT_SYMBOL(dump_skip);
...@@ -902,11 +933,11 @@ int dump_user_range(struct coredump_params *cprm, unsigned long start, ...@@ -902,11 +933,11 @@ int dump_user_range(struct coredump_params *cprm, unsigned long start,
stop = !dump_emit(cprm, kaddr, PAGE_SIZE); stop = !dump_emit(cprm, kaddr, PAGE_SIZE);
kunmap_local(kaddr); kunmap_local(kaddr);
put_page(page); put_page(page);
} else {
stop = !dump_skip(cprm, PAGE_SIZE);
}
if (stop) if (stop)
return 0; return 0;
} else {
dump_skip(cprm, PAGE_SIZE);
}
} }
return 1; return 1;
} }
...@@ -914,32 +945,15 @@ int dump_user_range(struct coredump_params *cprm, unsigned long start, ...@@ -914,32 +945,15 @@ int dump_user_range(struct coredump_params *cprm, unsigned long start,
int dump_align(struct coredump_params *cprm, int align) int dump_align(struct coredump_params *cprm, int align)
{ {
unsigned mod = cprm->pos & (align - 1); unsigned mod = (cprm->pos + cprm->to_skip) & (align - 1);
if (align & (align - 1)) if (align & (align - 1))
return 0; return 0;
return mod ? dump_skip(cprm, align - mod) : 1; if (mod)
cprm->to_skip += align - mod;
return 1;
} }
EXPORT_SYMBOL(dump_align); EXPORT_SYMBOL(dump_align);
/*
* Ensures that file size is big enough to contain the current file
* postion. This prevents gdb from complaining about a truncated file
* if the last "write" to the file was dump_skip.
*/
void dump_truncate(struct coredump_params *cprm)
{
struct file *file = cprm->file;
loff_t offset;
if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
offset = file->f_op->llseek(file, 0, SEEK_CUR);
if (i_size_read(file->f_mapping->host) < offset)
do_truncate(file_mnt_user_ns(file), file->f_path.dentry,
offset, 0, file);
}
}
EXPORT_SYMBOL(dump_truncate);
/* /*
* The purpose of always_dump_vma() is to make sure that special kernel mappings * The purpose of always_dump_vma() is to make sure that special kernel mappings
* that are useful for post-mortem analysis are included in every core dump. * that are useful for post-mortem analysis are included in every core dump.
......
...@@ -86,6 +86,7 @@ struct coredump_params { ...@@ -86,6 +86,7 @@ struct coredump_params {
unsigned long mm_flags; unsigned long mm_flags;
loff_t written; loff_t written;
loff_t pos; loff_t pos;
loff_t to_skip;
}; };
/* /*
......
...@@ -7,34 +7,34 @@ ...@@ -7,34 +7,34 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <asm/siginfo.h> #include <asm/siginfo.h>
#ifdef CONFIG_COREDUMP
struct core_vma_metadata { struct core_vma_metadata {
unsigned long start, end; unsigned long start, end;
unsigned long flags; unsigned long flags;
unsigned long dump_size; unsigned long dump_size;
}; };
extern int core_uses_pid;
extern char core_pattern[];
extern unsigned int core_pipe_limit;
/* /*
* These are the only things you should do on a core-file: use only these * These are the only things you should do on a core-file: use only these
* functions to write out all the necessary info. * functions to write out all the necessary info.
*/ */
struct coredump_params; struct coredump_params;
extern int dump_skip(struct coredump_params *cprm, size_t nr); extern void dump_skip_to(struct coredump_params *cprm, unsigned long to);
extern void dump_skip(struct coredump_params *cprm, size_t nr);
extern int dump_emit(struct coredump_params *cprm, const void *addr, int nr); extern int dump_emit(struct coredump_params *cprm, const void *addr, int nr);
extern int dump_align(struct coredump_params *cprm, int align); extern int dump_align(struct coredump_params *cprm, int align);
extern void dump_truncate(struct coredump_params *cprm);
int dump_user_range(struct coredump_params *cprm, unsigned long start, int dump_user_range(struct coredump_params *cprm, unsigned long start,
unsigned long len); unsigned long len);
int dump_vma_snapshot(struct coredump_params *cprm, int *vma_count, int dump_vma_snapshot(struct coredump_params *cprm, int *vma_count,
struct core_vma_metadata **vma_meta, struct core_vma_metadata **vma_meta,
size_t *vma_data_size_ptr); size_t *vma_data_size_ptr);
#ifdef CONFIG_COREDUMP
extern void do_coredump(const kernel_siginfo_t *siginfo); extern void do_coredump(const kernel_siginfo_t *siginfo);
#else #else
static inline void do_coredump(const kernel_siginfo_t *siginfo) {} static inline void do_coredump(const kernel_siginfo_t *siginfo) {}
#endif #endif
extern int core_uses_pid;
extern char core_pattern[];
extern unsigned int core_pipe_limit;
#endif /* _LINUX_COREDUMP_H */ #endif /* _LINUX_COREDUMP_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment