Commit 68a5dc38 authored by Dave Kleikamp's avatar Dave Kleikamp Committed by Greg Kroah-Hartman
Browse files

coredump: Ensure proper size of sparse core files

[ Upstream commit 4d22c75d


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: default avatarDave Kleikamp <>
Cc: Alexander Viro <>
Signed-off-by: default avatarAl Viro <>
Signed-off-by: default avatarSasha Levin <>
Signed-off-by: default avatarGreg Kroah-Hartman <>
parent d21816c2
......@@ -2296,6 +2296,7 @@ static int elf_core_dump(struct coredump_params *cprm)
goto end_coredump;
if (!elf_core_write_extra_data(cprm))
goto end_coredump;
......@@ -833,3 +833,21 @@ int dump_align(struct coredump_params *cprm, int align)
return mod ? dump_skip(cprm, align - mod) : 1;
* 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);
......@@ -14,6 +14,7 @@ struct coredump_params;
extern int 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_align(struct coredump_params *cprm, int align);
extern void dump_truncate(struct coredump_params *cprm);
extern void do_coredump(const siginfo_t *siginfo);
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