aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Kleikamp <dave.kleikamp@oracle.com>2017-01-11 14:25:00 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2017-01-14 19:32:40 -0500
commit4d22c75d4c7b5c5f4bd31054f09103ee490878fd (patch)
treea58ff1b3bb440af13026891f6ccb38d36fffcb4c
parenta12f1ae61c489076a9aeb90bddca7722bf330df3 (diff)
coredump: Ensure proper size of sparse core files
If the last section of a core file ends with an unmapped or zero page, the size of the file does not correspond with the last dump_skip() call. gdb complains that the file is truncated and can be confusing to users. After all of the vma sections are written, make sure that the file size is no smaller than the current file position. This problem can be demonstrated with gdb's bigcore testcase on the sparc architecture. Signed-off-by: Dave Kleikamp <dave.kleikamp@oracle.com> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Cc: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--fs/binfmt_elf.c1
-rw-r--r--fs/coredump.c18
-rw-r--r--include/linux/coredump.h1
3 files changed, 20 insertions, 0 deletions
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 29a02daf08a9..422370293cfd 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -2298,6 +2298,7 @@ static int elf_core_dump(struct coredump_params *cprm)
2298 goto end_coredump; 2298 goto end_coredump;
2299 } 2299 }
2300 } 2300 }
2301 dump_truncate(cprm);
2301 2302
2302 if (!elf_core_write_extra_data(cprm)) 2303 if (!elf_core_write_extra_data(cprm))
2303 goto end_coredump; 2304 goto end_coredump;
diff --git a/fs/coredump.c b/fs/coredump.c
index e525b6017cdf..ae6b05629ca1 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -833,3 +833,21 @@ int dump_align(struct coredump_params *cprm, int align)
833 return mod ? dump_skip(cprm, align - mod) : 1; 833 return mod ? dump_skip(cprm, align - mod) : 1;
834} 834}
835EXPORT_SYMBOL(dump_align); 835EXPORT_SYMBOL(dump_align);
836
837/*
838 * Ensures that file size is big enough to contain the current file
839 * postion. This prevents gdb from complaining about a truncated file
840 * if the last "write" to the file was dump_skip.
841 */
842void dump_truncate(struct coredump_params *cprm)
843{
844 struct file *file = cprm->file;
845 loff_t offset;
846
847 if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
848 offset = file->f_op->llseek(file, 0, SEEK_CUR);
849 if (i_size_read(file->f_mapping->host) < offset)
850 do_truncate(file->f_path.dentry, offset, 0, file);
851 }
852}
853EXPORT_SYMBOL(dump_truncate);
diff --git a/include/linux/coredump.h b/include/linux/coredump.h
index d016a121a8c4..28ffa94aed6b 100644
--- a/include/linux/coredump.h
+++ b/include/linux/coredump.h
@@ -14,6 +14,7 @@ struct coredump_params;
14extern int dump_skip(struct coredump_params *cprm, size_t nr); 14extern int dump_skip(struct coredump_params *cprm, size_t nr);
15extern int dump_emit(struct coredump_params *cprm, const void *addr, int nr); 15extern int dump_emit(struct coredump_params *cprm, const void *addr, int nr);
16extern int dump_align(struct coredump_params *cprm, int align); 16extern int dump_align(struct coredump_params *cprm, int align);
17extern void dump_truncate(struct coredump_params *cprm);
17#ifdef CONFIG_COREDUMP 18#ifdef CONFIG_COREDUMP
18extern void do_coredump(const siginfo_t *siginfo); 19extern void do_coredump(const siginfo_t *siginfo);
19#else 20#else