Skip to content

Commit 68a5dc3

Browse files
kleikampgregkh
authored andcommitted
coredump: Ensure proper size of sparse core files
[ Upstream commit 4d22c75 ] 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d21816c commit 68a5dc3

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

fs/binfmt_elf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,6 +2296,7 @@ static int elf_core_dump(struct coredump_params *cprm)
22962296
goto end_coredump;
22972297
}
22982298
}
2299+
dump_truncate(cprm);
22992300

23002301
if (!elf_core_write_extra_data(cprm))
23012302
goto end_coredump;

fs/coredump.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,3 +833,21 @@ int dump_align(struct coredump_params *cprm, int align)
833833
return mod ? dump_skip(cprm, align - mod) : 1;
834834
}
835835
EXPORT_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+
*/
842+
void 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+
}
853+
EXPORT_SYMBOL(dump_truncate);

include/linux/coredump.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct coredump_params;
1414
extern int dump_skip(struct coredump_params *cprm, size_t nr);
1515
extern int dump_emit(struct coredump_params *cprm, const void *addr, int nr);
1616
extern int dump_align(struct coredump_params *cprm, int align);
17+
extern void dump_truncate(struct coredump_params *cprm);
1718
#ifdef CONFIG_COREDUMP
1819
extern void do_coredump(const siginfo_t *siginfo);
1920
#else

0 commit comments

Comments
 (0)