summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorDave Kleikamp <dave.kleikamp@oracle.com>2017-01-11 13:25:00 -0600
committerSasha Levin <alexander.levin@verizon.com>2017-07-31 13:37:51 -0400
commitc83f147d84835966faadb9caab0845427fdce3dc (patch)
treeffa264049790edebee7b458e1336217845feb8b6 /fs
parent35b2db6733db25e607a7a2637a7f68165e4c979d (diff)
coredump: Ensure proper size of sparse core files
[ Upstream commit 4d22c75d4c7b5c5f4bd31054f09103ee490878fd ] 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> Signed-off-by: Sasha Levin <alexander.levin@verizon.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/binfmt_elf.c1
-rw-r--r--fs/coredump.c18
2 files changed, 19 insertions, 0 deletions
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index cd46e4158830..5d6427a00b10 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -2285,6 +2285,7 @@ static int elf_core_dump(struct coredump_params *cprm)
goto end_coredump;
}
}
+ dump_truncate(cprm);
if (!elf_core_write_extra_data(cprm))
goto end_coredump;
diff --git a/fs/coredump.c b/fs/coredump.c
index 26d05e3bc6db..e07cbb629f1c 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -803,3 +803,21 @@ int dump_align(struct coredump_params *cprm, int align)
return mod ? dump_skip(cprm, align - mod) : 1;
}
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->f_path.dentry, offset, 0, file);
+ }
+}
+EXPORT_SYMBOL(dump_truncate);