Skip to content

Commit 5e67208

Browse files
committed
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()
2 parents d1466bc + a64b890 commit 5e67208

6 files changed

Lines changed: 54 additions & 43 deletions

File tree

arch/powerpc/platforms/cell/spufs/coredump.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ static int spufs_arch_write_note(struct spu_context *ctx, int i,
149149
return -EIO;
150150
}
151151

152-
if (!dump_skip(cprm, roundup(cprm->pos - ret + sz, 4) - cprm->pos))
153-
return -EIO;
152+
dump_skip_to(cprm, roundup(cprm->pos - ret + sz, 4));
154153
return 0;
155154
}
156155

fs/binfmt_elf.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,16 +2267,14 @@ static int elf_core_dump(struct coredump_params *cprm)
22672267
goto end_coredump;
22682268

22692269
/* Align to page */
2270-
if (!dump_skip(cprm, dataoff - cprm->pos))
2271-
goto end_coredump;
2270+
dump_skip_to(cprm, dataoff);
22722271

22732272
for (i = 0; i < vma_count; i++) {
22742273
struct core_vma_metadata *meta = vma_meta + i;
22752274

22762275
if (!dump_user_range(cprm, meta->start, meta->dump_size))
22772276
goto end_coredump;
22782277
}
2279-
dump_truncate(cprm);
22802278

22812279
if (!elf_core_write_extra_data(cprm))
22822280
goto end_coredump;

fs/binfmt_elf_fdpic.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,8 +1631,7 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
16311631
goto end_coredump;
16321632
}
16331633

1634-
if (!dump_skip(cprm, dataoff - cprm->pos))
1635-
goto end_coredump;
1634+
dump_skip_to(cprm, dataoff);
16361635

16371636
if (!elf_fdpic_dump_segments(cprm, vma_meta, vma_count))
16381637
goto end_coredump;

fs/coredump.c

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,16 @@ void do_coredump(const kernel_siginfo_t *siginfo)
809809
}
810810
file_start_write(cprm.file);
811811
core_dumped = binfmt->core_dump(&cprm);
812+
/*
813+
* Ensures that file size is big enough to contain the current
814+
* file postion. This prevents gdb from complaining about
815+
* a truncated file if the last "write" to the file was
816+
* dump_skip.
817+
*/
818+
if (cprm.to_skip) {
819+
cprm.to_skip--;
820+
dump_emit(&cprm, "", 1);
821+
}
812822
file_end_write(cprm.file);
813823
}
814824
if (ispipe && core_pipe_limit)
@@ -835,7 +845,7 @@ void do_coredump(const kernel_siginfo_t *siginfo)
835845
* do on a core-file: use only these functions to write out all the
836846
* necessary info.
837847
*/
838-
int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
848+
static int __dump_emit(struct coredump_params *cprm, const void *addr, int nr)
839849
{
840850
struct file *file = cprm->file;
841851
loff_t pos = file->f_pos;
@@ -855,9 +865,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
855865

856866
return 1;
857867
}
858-
EXPORT_SYMBOL(dump_emit);
859868

860-
int dump_skip(struct coredump_params *cprm, size_t nr)
869+
static int __dump_skip(struct coredump_params *cprm, size_t nr)
861870
{
862871
static char zeroes[PAGE_SIZE];
863872
struct file *file = cprm->file;
@@ -869,13 +878,35 @@ int dump_skip(struct coredump_params *cprm, size_t nr)
869878
return 1;
870879
} else {
871880
while (nr > PAGE_SIZE) {
872-
if (!dump_emit(cprm, zeroes, PAGE_SIZE))
881+
if (!__dump_emit(cprm, zeroes, PAGE_SIZE))
873882
return 0;
874883
nr -= PAGE_SIZE;
875884
}
876-
return dump_emit(cprm, zeroes, nr);
885+
return __dump_emit(cprm, zeroes, nr);
877886
}
878887
}
888+
889+
int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
890+
{
891+
if (cprm->to_skip) {
892+
if (!__dump_skip(cprm, cprm->to_skip))
893+
return 0;
894+
cprm->to_skip = 0;
895+
}
896+
return __dump_emit(cprm, addr, nr);
897+
}
898+
EXPORT_SYMBOL(dump_emit);
899+
900+
void dump_skip_to(struct coredump_params *cprm, unsigned long pos)
901+
{
902+
cprm->to_skip = pos - cprm->pos;
903+
}
904+
EXPORT_SYMBOL(dump_skip_to);
905+
906+
void dump_skip(struct coredump_params *cprm, size_t nr)
907+
{
908+
cprm->to_skip += nr;
909+
}
879910
EXPORT_SYMBOL(dump_skip);
880911

881912
#ifdef CONFIG_ELF_CORE
@@ -902,44 +933,27 @@ int dump_user_range(struct coredump_params *cprm, unsigned long start,
902933
stop = !dump_emit(cprm, kaddr, PAGE_SIZE);
903934
kunmap_local(kaddr);
904935
put_page(page);
936+
if (stop)
937+
return 0;
905938
} else {
906-
stop = !dump_skip(cprm, PAGE_SIZE);
939+
dump_skip(cprm, PAGE_SIZE);
907940
}
908-
if (stop)
909-
return 0;
910941
}
911942
return 1;
912943
}
913944
#endif
914945

915946
int dump_align(struct coredump_params *cprm, int align)
916947
{
917-
unsigned mod = cprm->pos & (align - 1);
948+
unsigned mod = (cprm->pos + cprm->to_skip) & (align - 1);
918949
if (align & (align - 1))
919950
return 0;
920-
return mod ? dump_skip(cprm, align - mod) : 1;
951+
if (mod)
952+
cprm->to_skip += align - mod;
953+
return 1;
921954
}
922955
EXPORT_SYMBOL(dump_align);
923956

924-
/*
925-
* Ensures that file size is big enough to contain the current file
926-
* postion. This prevents gdb from complaining about a truncated file
927-
* if the last "write" to the file was dump_skip.
928-
*/
929-
void dump_truncate(struct coredump_params *cprm)
930-
{
931-
struct file *file = cprm->file;
932-
loff_t offset;
933-
934-
if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
935-
offset = file->f_op->llseek(file, 0, SEEK_CUR);
936-
if (i_size_read(file->f_mapping->host) < offset)
937-
do_truncate(file_mnt_user_ns(file), file->f_path.dentry,
938-
offset, 0, file);
939-
}
940-
}
941-
EXPORT_SYMBOL(dump_truncate);
942-
943957
/*
944958
* The purpose of always_dump_vma() is to make sure that special kernel mappings
945959
* that are useful for post-mortem analysis are included in every core dump.

include/linux/binfmts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct coredump_params {
8686
unsigned long mm_flags;
8787
loff_t written;
8888
loff_t pos;
89+
loff_t to_skip;
8990
};
9091

9192
/*

include/linux/coredump.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,34 @@
77
#include <linux/fs.h>
88
#include <asm/siginfo.h>
99

10+
#ifdef CONFIG_COREDUMP
1011
struct core_vma_metadata {
1112
unsigned long start, end;
1213
unsigned long flags;
1314
unsigned long dump_size;
1415
};
1516

17+
extern int core_uses_pid;
18+
extern char core_pattern[];
19+
extern unsigned int core_pipe_limit;
20+
1621
/*
1722
* These are the only things you should do on a core-file: use only these
1823
* functions to write out all the necessary info.
1924
*/
2025
struct coredump_params;
21-
extern int dump_skip(struct coredump_params *cprm, size_t nr);
26+
extern void dump_skip_to(struct coredump_params *cprm, unsigned long to);
27+
extern void dump_skip(struct coredump_params *cprm, size_t nr);
2228
extern int dump_emit(struct coredump_params *cprm, const void *addr, int nr);
2329
extern int dump_align(struct coredump_params *cprm, int align);
24-
extern void dump_truncate(struct coredump_params *cprm);
2530
int dump_user_range(struct coredump_params *cprm, unsigned long start,
2631
unsigned long len);
2732
int dump_vma_snapshot(struct coredump_params *cprm, int *vma_count,
2833
struct core_vma_metadata **vma_meta,
2934
size_t *vma_data_size_ptr);
30-
#ifdef CONFIG_COREDUMP
3135
extern void do_coredump(const kernel_siginfo_t *siginfo);
3236
#else
3337
static inline void do_coredump(const kernel_siginfo_t *siginfo) {}
3438
#endif
3539

36-
extern int core_uses_pid;
37-
extern char core_pattern[];
38-
extern unsigned int core_pipe_limit;
39-
4040
#endif /* _LINUX_COREDUMP_H */

0 commit comments

Comments
 (0)