Skip to content

Commit a78282e

Browse files
committed
Revert "binfmt_elf, coredump: Log the reason of the failed core dumps"
This reverts commit fb97d2e. The logging was questionable to begin with, but it seems to actively deadlock on the task lock. "On second thought, let's not log core dump failures. 'Tis a silly place" because if you can't tell your core dump is truncated, maybe you should just fix your debugger instead of adding bugs to the kernel. Reported-by: Vegard Nossum <vegard.nossum@oracle.com> Link: https://lore.kernel.org/all/d122ece6-3606-49de-ae4d-8da88846bef2@oracle.com/ Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 62a0e2f commit a78282e

File tree

4 files changed

+34
-150
lines changed

4 files changed

+34
-150
lines changed

fs/binfmt_elf.c

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,10 +2032,8 @@ static int elf_core_dump(struct coredump_params *cprm)
20322032
* Collect all the non-memory information about the process for the
20332033
* notes. This also sets up the file header.
20342034
*/
2035-
if (!fill_note_info(&elf, e_phnum, &info, cprm)) {
2036-
coredump_report_failure("Error collecting note info");
2035+
if (!fill_note_info(&elf, e_phnum, &info, cprm))
20372036
goto end_coredump;
2038-
}
20392037

20402038
has_dumped = 1;
20412039

@@ -2050,10 +2048,8 @@ static int elf_core_dump(struct coredump_params *cprm)
20502048
sz += elf_coredump_extra_notes_size();
20512049

20522050
phdr4note = kmalloc(sizeof(*phdr4note), GFP_KERNEL);
2053-
if (!phdr4note) {
2054-
coredump_report_failure("Error allocating program headers note entry");
2051+
if (!phdr4note)
20552052
goto end_coredump;
2056-
}
20572053

20582054
fill_elf_note_phdr(phdr4note, sz, offset);
20592055
offset += sz;
@@ -2067,24 +2063,18 @@ static int elf_core_dump(struct coredump_params *cprm)
20672063

20682064
if (e_phnum == PN_XNUM) {
20692065
shdr4extnum = kmalloc(sizeof(*shdr4extnum), GFP_KERNEL);
2070-
if (!shdr4extnum) {
2071-
coredump_report_failure("Error allocating extra program headers");
2066+
if (!shdr4extnum)
20722067
goto end_coredump;
2073-
}
20742068
fill_extnum_info(&elf, shdr4extnum, e_shoff, segs);
20752069
}
20762070

20772071
offset = dataoff;
20782072

2079-
if (!dump_emit(cprm, &elf, sizeof(elf))) {
2080-
coredump_report_failure("Error emitting the ELF headers");
2073+
if (!dump_emit(cprm, &elf, sizeof(elf)))
20812074
goto end_coredump;
2082-
}
20832075

2084-
if (!dump_emit(cprm, phdr4note, sizeof(*phdr4note))) {
2085-
coredump_report_failure("Error emitting the program header for notes");
2076+
if (!dump_emit(cprm, phdr4note, sizeof(*phdr4note)))
20862077
goto end_coredump;
2087-
}
20882078

20892079
/* Write program headers for segments dump */
20902080
for (i = 0; i < cprm->vma_count; i++) {
@@ -2107,51 +2097,37 @@ static int elf_core_dump(struct coredump_params *cprm)
21072097
phdr.p_flags |= PF_X;
21082098
phdr.p_align = ELF_EXEC_PAGESIZE;
21092099

2110-
if (!dump_emit(cprm, &phdr, sizeof(phdr))) {
2111-
coredump_report_failure("Error emitting program headers");
2100+
if (!dump_emit(cprm, &phdr, sizeof(phdr)))
21122101
goto end_coredump;
2113-
}
21142102
}
21152103

2116-
if (!elf_core_write_extra_phdrs(cprm, offset)) {
2117-
coredump_report_failure("Error writing out extra program headers");
2104+
if (!elf_core_write_extra_phdrs(cprm, offset))
21182105
goto end_coredump;
2119-
}
21202106

21212107
/* write out the notes section */
2122-
if (!write_note_info(&info, cprm)) {
2123-
coredump_report_failure("Error writing out notes");
2108+
if (!write_note_info(&info, cprm))
21242109
goto end_coredump;
2125-
}
21262110

21272111
/* For cell spufs and x86 xstate */
2128-
if (elf_coredump_extra_notes_write(cprm)) {
2129-
coredump_report_failure("Error writing out extra notes");
2112+
if (elf_coredump_extra_notes_write(cprm))
21302113
goto end_coredump;
2131-
}
21322114

21332115
/* Align to page */
21342116
dump_skip_to(cprm, dataoff);
21352117

21362118
for (i = 0; i < cprm->vma_count; i++) {
21372119
struct core_vma_metadata *meta = cprm->vma_meta + i;
21382120

2139-
if (!dump_user_range(cprm, meta->start, meta->dump_size)) {
2140-
coredump_report_failure("Error writing out the process memory");
2121+
if (!dump_user_range(cprm, meta->start, meta->dump_size))
21412122
goto end_coredump;
2142-
}
21432123
}
21442124

2145-
if (!elf_core_write_extra_data(cprm)) {
2146-
coredump_report_failure("Error writing out extra data");
2125+
if (!elf_core_write_extra_data(cprm))
21472126
goto end_coredump;
2148-
}
21492127

21502128
if (e_phnum == PN_XNUM) {
2151-
if (!dump_emit(cprm, shdr4extnum, sizeof(*shdr4extnum))) {
2152-
coredump_report_failure("Error emitting extra program headers");
2129+
if (!dump_emit(cprm, shdr4extnum, sizeof(*shdr4extnum)))
21532130
goto end_coredump;
2154-
}
21552131
}
21562132

21572133
end_coredump:

fs/coredump.c

Lines changed: 19 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -465,17 +465,7 @@ static bool dump_interrupted(void)
465465
* but then we need to teach dump_write() to restart and clear
466466
* TIF_SIGPENDING.
467467
*/
468-
if (fatal_signal_pending(current)) {
469-
coredump_report_failure("interrupted: fatal signal pending");
470-
return true;
471-
}
472-
473-
if (freezing(current)) {
474-
coredump_report_failure("interrupted: freezing");
475-
return true;
476-
}
477-
478-
return false;
468+
return fatal_signal_pending(current) || freezing(current);
479469
}
480470

481471
static void wait_for_dump_helpers(struct file *file)
@@ -530,15 +520,15 @@ static int umh_pipe_setup(struct subprocess_info *info, struct cred *new)
530520
return err;
531521
}
532522

533-
int do_coredump(const kernel_siginfo_t *siginfo)
523+
void do_coredump(const kernel_siginfo_t *siginfo)
534524
{
535525
struct core_state core_state;
536526
struct core_name cn;
537527
struct mm_struct *mm = current->mm;
538528
struct linux_binfmt * binfmt;
539529
const struct cred *old_cred;
540530
struct cred *cred;
541-
int retval;
531+
int retval = 0;
542532
int ispipe;
543533
size_t *argv = NULL;
544534
int argc = 0;
@@ -562,20 +552,14 @@ int do_coredump(const kernel_siginfo_t *siginfo)
562552
audit_core_dumps(siginfo->si_signo);
563553

564554
binfmt = mm->binfmt;
565-
if (!binfmt || !binfmt->core_dump) {
566-
retval = -ENOEXEC;
555+
if (!binfmt || !binfmt->core_dump)
567556
goto fail;
568-
}
569-
if (!__get_dumpable(cprm.mm_flags)) {
570-
retval = -EACCES;
557+
if (!__get_dumpable(cprm.mm_flags))
571558
goto fail;
572-
}
573559

574560
cred = prepare_creds();
575-
if (!cred) {
576-
retval = -EPERM;
561+
if (!cred)
577562
goto fail;
578-
}
579563
/*
580564
* We cannot trust fsuid as being the "true" uid of the process
581565
* nor do we know its entire history. We only know it was tainted
@@ -604,7 +588,6 @@ int do_coredump(const kernel_siginfo_t *siginfo)
604588

605589
if (ispipe < 0) {
606590
coredump_report_failure("format_corename failed, aborting core");
607-
retval = ispipe;
608591
goto fail_unlock;
609592
}
610593

@@ -625,23 +608,20 @@ int do_coredump(const kernel_siginfo_t *siginfo)
625608
* core_pattern process dies.
626609
*/
627610
coredump_report_failure("RLIMIT_CORE is set to 1, aborting core");
628-
retval = -EPERM;
629611
goto fail_unlock;
630612
}
631613
cprm.limit = RLIM_INFINITY;
632614

633615
dump_count = atomic_inc_return(&core_dump_count);
634616
if (core_pipe_limit && (core_pipe_limit < dump_count)) {
635617
coredump_report_failure("over core_pipe_limit, skipping core dump");
636-
retval = -E2BIG;
637618
goto fail_dropcount;
638619
}
639620

640621
helper_argv = kmalloc_array(argc + 1, sizeof(*helper_argv),
641622
GFP_KERNEL);
642623
if (!helper_argv) {
643624
coredump_report_failure("%s failed to allocate memory", __func__);
644-
retval = -ENOMEM;
645625
goto fail_dropcount;
646626
}
647627
for (argi = 0; argi < argc; argi++)
@@ -667,16 +647,12 @@ int do_coredump(const kernel_siginfo_t *siginfo)
667647
int open_flags = O_CREAT | O_WRONLY | O_NOFOLLOW |
668648
O_LARGEFILE | O_EXCL;
669649

670-
if (cprm.limit < binfmt->min_coredump) {
671-
coredump_report_failure("over coredump resource limit, skipping core dump");
672-
retval = -E2BIG;
650+
if (cprm.limit < binfmt->min_coredump)
673651
goto fail_unlock;
674-
}
675652

676653
if (need_suid_safe && cn.corename[0] != '/') {
677654
coredump_report_failure(
678655
"this process can only dump core to a fully qualified path, skipping core dump");
679-
retval = -EPERM;
680656
goto fail_unlock;
681657
}
682658

@@ -722,28 +698,20 @@ int do_coredump(const kernel_siginfo_t *siginfo)
722698
} else {
723699
cprm.file = filp_open(cn.corename, open_flags, 0600);
724700
}
725-
if (IS_ERR(cprm.file)) {
726-
retval = PTR_ERR(cprm.file);
701+
if (IS_ERR(cprm.file))
727702
goto fail_unlock;
728-
}
729703

730704
inode = file_inode(cprm.file);
731-
if (inode->i_nlink > 1) {
732-
retval = -EMLINK;
705+
if (inode->i_nlink > 1)
733706
goto close_fail;
734-
}
735-
if (d_unhashed(cprm.file->f_path.dentry)) {
736-
retval = -EEXIST;
707+
if (d_unhashed(cprm.file->f_path.dentry))
737708
goto close_fail;
738-
}
739709
/*
740710
* AK: actually i see no reason to not allow this for named
741711
* pipes etc, but keep the previous behaviour for now.
742712
*/
743-
if (!S_ISREG(inode->i_mode)) {
744-
retval = -EISDIR;
713+
if (!S_ISREG(inode->i_mode))
745714
goto close_fail;
746-
}
747715
/*
748716
* Don't dump core if the filesystem changed owner or mode
749717
* of the file during file creation. This is an issue when
@@ -755,22 +723,17 @@ int do_coredump(const kernel_siginfo_t *siginfo)
755723
current_fsuid())) {
756724
coredump_report_failure("Core dump to %s aborted: "
757725
"cannot preserve file owner", cn.corename);
758-
retval = -EPERM;
759726
goto close_fail;
760727
}
761728
if ((inode->i_mode & 0677) != 0600) {
762729
coredump_report_failure("Core dump to %s aborted: "
763730
"cannot preserve file permissions", cn.corename);
764-
retval = -EPERM;
765731
goto close_fail;
766732
}
767-
if (!(cprm.file->f_mode & FMODE_CAN_WRITE)) {
768-
retval = -EACCES;
733+
if (!(cprm.file->f_mode & FMODE_CAN_WRITE))
769734
goto close_fail;
770-
}
771-
retval = do_truncate(idmap, cprm.file->f_path.dentry,
772-
0, 0, cprm.file);
773-
if (retval)
735+
if (do_truncate(idmap, cprm.file->f_path.dentry,
736+
0, 0, cprm.file))
774737
goto close_fail;
775738
}
776739

@@ -786,15 +749,10 @@ int do_coredump(const kernel_siginfo_t *siginfo)
786749
*/
787750
if (!cprm.file) {
788751
coredump_report_failure("Core dump to |%s disabled", cn.corename);
789-
retval = -EPERM;
790752
goto close_fail;
791753
}
792-
if (!dump_vma_snapshot(&cprm)) {
793-
coredump_report_failure("Can't get VMA snapshot for core dump |%s",
794-
cn.corename);
795-
retval = -EACCES;
754+
if (!dump_vma_snapshot(&cprm))
796755
goto close_fail;
797-
}
798756

799757
file_start_write(cprm.file);
800758
core_dumped = binfmt->core_dump(&cprm);
@@ -810,21 +768,9 @@ int do_coredump(const kernel_siginfo_t *siginfo)
810768
}
811769
file_end_write(cprm.file);
812770
free_vma_snapshot(&cprm);
813-
} else {
814-
coredump_report_failure("Core dump to %s%s has been interrupted",
815-
ispipe ? "|" : "", cn.corename);
816-
retval = -EAGAIN;
817-
goto fail;
818771
}
819-
coredump_report(
820-
"written to %s%s: VMAs: %d, size %zu; core: %lld bytes, pos %lld",
821-
ispipe ? "|" : "", cn.corename,
822-
cprm.vma_count, cprm.vma_data_size, cprm.written, cprm.pos);
823772
if (ispipe && core_pipe_limit)
824773
wait_for_dump_helpers(cprm.file);
825-
826-
retval = 0;
827-
828774
close_fail:
829775
if (cprm.file)
830776
filp_close(cprm.file, NULL);
@@ -839,7 +785,7 @@ int do_coredump(const kernel_siginfo_t *siginfo)
839785
fail_creds:
840786
put_cred(cred);
841787
fail:
842-
return retval;
788+
return;
843789
}
844790

845791
/*
@@ -859,16 +805,8 @@ static int __dump_emit(struct coredump_params *cprm, const void *addr, int nr)
859805
if (dump_interrupted())
860806
return 0;
861807
n = __kernel_write(file, addr, nr, &pos);
862-
if (n != nr) {
863-
if (n < 0)
864-
coredump_report_failure("failed when writing out, error %zd", n);
865-
else
866-
coredump_report_failure(
867-
"partially written out, only %zd(of %d) bytes written",
868-
n, nr);
869-
808+
if (n != nr)
870809
return 0;
871-
}
872810
file->f_pos = pos;
873811
cprm->written += n;
874812
cprm->pos += n;
@@ -881,16 +819,9 @@ static int __dump_skip(struct coredump_params *cprm, size_t nr)
881819
static char zeroes[PAGE_SIZE];
882820
struct file *file = cprm->file;
883821
if (file->f_mode & FMODE_LSEEK) {
884-
int ret;
885-
886-
if (dump_interrupted())
822+
if (dump_interrupted() ||
823+
vfs_llseek(file, nr, SEEK_CUR) < 0)
887824
return 0;
888-
889-
ret = vfs_llseek(file, nr, SEEK_CUR);
890-
if (ret < 0) {
891-
coredump_report_failure("failed when seeking, error %d", ret);
892-
return 0;
893-
}
894825
cprm->pos += nr;
895826
return 1;
896827
} else {

include/linux/coredump.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extern int dump_emit(struct coredump_params *cprm, const void *addr, int nr);
4242
extern int dump_align(struct coredump_params *cprm, int align);
4343
int dump_user_range(struct coredump_params *cprm, unsigned long start,
4444
unsigned long len);
45-
extern int do_coredump(const kernel_siginfo_t *siginfo);
45+
extern void do_coredump(const kernel_siginfo_t *siginfo);
4646

4747
/*
4848
* Logging for the coredump code, ratelimited.
@@ -62,11 +62,7 @@ extern int do_coredump(const kernel_siginfo_t *siginfo);
6262
#define coredump_report_failure(fmt, ...) __COREDUMP_PRINTK(KERN_WARNING, fmt, ##__VA_ARGS__)
6363

6464
#else
65-
static inline int do_coredump(const kernel_siginfo_t *siginfo)
66-
{
67-
/* Coredump support is not available, can't fail. */
68-
return 0;
69-
}
65+
static inline void do_coredump(const kernel_siginfo_t *siginfo) {}
7066

7167
#define coredump_report(...)
7268
#define coredump_report_failure(...)

0 commit comments

Comments
 (0)