Revert "binfmt_elf, coredump: Log the reason of the failed core dumps"

This reverts commit fb97d2eb542faf19a8725afbd75cbc2518903210.

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>

+34 -150
+12 -36
fs/binfmt_elf.c
··· 2032 2032 * Collect all the non-memory information about the process for the 2033 2033 * notes. This also sets up the file header. 2034 2034 */ 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)) 2037 2036 goto end_coredump; 2038 - } 2039 2037 2040 2038 has_dumped = 1; 2041 2039 ··· 2048 2050 sz += elf_coredump_extra_notes_size(); 2049 2051 2050 2052 phdr4note = kmalloc(sizeof(*phdr4note), GFP_KERNEL); 2051 - if (!phdr4note) { 2052 - coredump_report_failure("Error allocating program headers note entry"); 2053 + if (!phdr4note) 2053 2054 goto end_coredump; 2054 - } 2055 2055 2056 2056 fill_elf_note_phdr(phdr4note, sz, offset); 2057 2057 offset += sz; ··· 2063 2067 2064 2068 if (e_phnum == PN_XNUM) { 2065 2069 shdr4extnum = kmalloc(sizeof(*shdr4extnum), GFP_KERNEL); 2066 - if (!shdr4extnum) { 2067 - coredump_report_failure("Error allocating extra program headers"); 2070 + if (!shdr4extnum) 2068 2071 goto end_coredump; 2069 - } 2070 2072 fill_extnum_info(&elf, shdr4extnum, e_shoff, segs); 2071 2073 } 2072 2074 2073 2075 offset = dataoff; 2074 2076 2075 - if (!dump_emit(cprm, &elf, sizeof(elf))) { 2076 - coredump_report_failure("Error emitting the ELF headers"); 2077 + if (!dump_emit(cprm, &elf, sizeof(elf))) 2077 2078 goto end_coredump; 2078 - } 2079 2079 2080 - if (!dump_emit(cprm, phdr4note, sizeof(*phdr4note))) { 2081 - coredump_report_failure("Error emitting the program header for notes"); 2080 + if (!dump_emit(cprm, phdr4note, sizeof(*phdr4note))) 2082 2081 goto end_coredump; 2083 - } 2084 2082 2085 2083 /* Write program headers for segments dump */ 2086 2084 for (i = 0; i < cprm->vma_count; i++) { ··· 2097 2107 phdr.p_flags |= PF_X; 2098 2108 phdr.p_align = ELF_EXEC_PAGESIZE; 2099 2109 2100 - if (!dump_emit(cprm, &phdr, sizeof(phdr))) { 2101 - coredump_report_failure("Error emitting program headers"); 2110 + if (!dump_emit(cprm, &phdr, sizeof(phdr))) 2102 2111 goto end_coredump; 2103 - } 2104 2112 } 2105 2113 2106 - if (!elf_core_write_extra_phdrs(cprm, offset)) { 2107 - coredump_report_failure("Error writing out extra program headers"); 2114 + if (!elf_core_write_extra_phdrs(cprm, offset)) 2108 2115 goto end_coredump; 2109 - } 2110 2116 2111 2117 /* write out the notes section */ 2112 - if (!write_note_info(&info, cprm)) { 2113 - coredump_report_failure("Error writing out notes"); 2118 + if (!write_note_info(&info, cprm)) 2114 2119 goto end_coredump; 2115 - } 2116 2120 2117 2121 /* For cell spufs and x86 xstate */ 2118 - if (elf_coredump_extra_notes_write(cprm)) { 2119 - coredump_report_failure("Error writing out extra notes"); 2122 + if (elf_coredump_extra_notes_write(cprm)) 2120 2123 goto end_coredump; 2121 - } 2122 2124 2123 2125 /* Align to page */ 2124 2126 dump_skip_to(cprm, dataoff); ··· 2118 2136 for (i = 0; i < cprm->vma_count; i++) { 2119 2137 struct core_vma_metadata *meta = cprm->vma_meta + i; 2120 2138 2121 - if (!dump_user_range(cprm, meta->start, meta->dump_size)) { 2122 - coredump_report_failure("Error writing out the process memory"); 2139 + if (!dump_user_range(cprm, meta->start, meta->dump_size)) 2123 2140 goto end_coredump; 2124 - } 2125 2141 } 2126 2142 2127 - if (!elf_core_write_extra_data(cprm)) { 2128 - coredump_report_failure("Error writing out extra data"); 2143 + if (!elf_core_write_extra_data(cprm)) 2129 2144 goto end_coredump; 2130 - } 2131 2145 2132 2146 if (e_phnum == PN_XNUM) { 2133 - if (!dump_emit(cprm, shdr4extnum, sizeof(*shdr4extnum))) { 2134 - coredump_report_failure("Error emitting extra program headers"); 2147 + if (!dump_emit(cprm, shdr4extnum, sizeof(*shdr4extnum))) 2135 2148 goto end_coredump; 2136 - } 2137 2149 } 2138 2150 2139 2151 end_coredump:
+19 -88
fs/coredump.c
··· 465 465 * but then we need to teach dump_write() to restart and clear 466 466 * TIF_SIGPENDING. 467 467 */ 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); 479 469 } 480 470 481 471 static void wait_for_dump_helpers(struct file *file) ··· 520 530 return err; 521 531 } 522 532 523 - int do_coredump(const kernel_siginfo_t *siginfo) 533 + void do_coredump(const kernel_siginfo_t *siginfo) 524 534 { 525 535 struct core_state core_state; 526 536 struct core_name cn; ··· 528 538 struct linux_binfmt * binfmt; 529 539 const struct cred *old_cred; 530 540 struct cred *cred; 531 - int retval; 541 + int retval = 0; 532 542 int ispipe; 533 543 size_t *argv = NULL; 534 544 int argc = 0; ··· 552 562 audit_core_dumps(siginfo->si_signo); 553 563 554 564 binfmt = mm->binfmt; 555 - if (!binfmt || !binfmt->core_dump) { 556 - retval = -ENOEXEC; 565 + if (!binfmt || !binfmt->core_dump) 557 566 goto fail; 558 - } 559 - if (!__get_dumpable(cprm.mm_flags)) { 560 - retval = -EACCES; 567 + if (!__get_dumpable(cprm.mm_flags)) 561 568 goto fail; 562 - } 563 569 564 570 cred = prepare_creds(); 565 - if (!cred) { 566 - retval = -EPERM; 571 + if (!cred) 567 572 goto fail; 568 - } 569 573 /* 570 574 * We cannot trust fsuid as being the "true" uid of the process 571 575 * nor do we know its entire history. We only know it was tainted ··· 588 604 589 605 if (ispipe < 0) { 590 606 coredump_report_failure("format_corename failed, aborting core"); 591 - retval = ispipe; 592 607 goto fail_unlock; 593 608 } 594 609 ··· 608 625 * core_pattern process dies. 609 626 */ 610 627 coredump_report_failure("RLIMIT_CORE is set to 1, aborting core"); 611 - retval = -EPERM; 612 628 goto fail_unlock; 613 629 } 614 630 cprm.limit = RLIM_INFINITY; ··· 615 633 dump_count = atomic_inc_return(&core_dump_count); 616 634 if (core_pipe_limit && (core_pipe_limit < dump_count)) { 617 635 coredump_report_failure("over core_pipe_limit, skipping core dump"); 618 - retval = -E2BIG; 619 636 goto fail_dropcount; 620 637 } 621 638 ··· 622 641 GFP_KERNEL); 623 642 if (!helper_argv) { 624 643 coredump_report_failure("%s failed to allocate memory", __func__); 625 - retval = -ENOMEM; 626 644 goto fail_dropcount; 627 645 } 628 646 for (argi = 0; argi < argc; argi++) ··· 647 667 int open_flags = O_CREAT | O_WRONLY | O_NOFOLLOW | 648 668 O_LARGEFILE | O_EXCL; 649 669 650 - if (cprm.limit < binfmt->min_coredump) { 651 - coredump_report_failure("over coredump resource limit, skipping core dump"); 652 - retval = -E2BIG; 670 + if (cprm.limit < binfmt->min_coredump) 653 671 goto fail_unlock; 654 - } 655 672 656 673 if (need_suid_safe && cn.corename[0] != '/') { 657 674 coredump_report_failure( 658 675 "this process can only dump core to a fully qualified path, skipping core dump"); 659 - retval = -EPERM; 660 676 goto fail_unlock; 661 677 } 662 678 ··· 698 722 } else { 699 723 cprm.file = filp_open(cn.corename, open_flags, 0600); 700 724 } 701 - if (IS_ERR(cprm.file)) { 702 - retval = PTR_ERR(cprm.file); 725 + if (IS_ERR(cprm.file)) 703 726 goto fail_unlock; 704 - } 705 727 706 728 inode = file_inode(cprm.file); 707 - if (inode->i_nlink > 1) { 708 - retval = -EMLINK; 729 + if (inode->i_nlink > 1) 709 730 goto close_fail; 710 - } 711 - if (d_unhashed(cprm.file->f_path.dentry)) { 712 - retval = -EEXIST; 731 + if (d_unhashed(cprm.file->f_path.dentry)) 713 732 goto close_fail; 714 - } 715 733 /* 716 734 * AK: actually i see no reason to not allow this for named 717 735 * pipes etc, but keep the previous behaviour for now. 718 736 */ 719 - if (!S_ISREG(inode->i_mode)) { 720 - retval = -EISDIR; 737 + if (!S_ISREG(inode->i_mode)) 721 738 goto close_fail; 722 - } 723 739 /* 724 740 * Don't dump core if the filesystem changed owner or mode 725 741 * of the file during file creation. This is an issue when ··· 723 755 current_fsuid())) { 724 756 coredump_report_failure("Core dump to %s aborted: " 725 757 "cannot preserve file owner", cn.corename); 726 - retval = -EPERM; 727 758 goto close_fail; 728 759 } 729 760 if ((inode->i_mode & 0677) != 0600) { 730 761 coredump_report_failure("Core dump to %s aborted: " 731 762 "cannot preserve file permissions", cn.corename); 732 - retval = -EPERM; 733 763 goto close_fail; 734 764 } 735 - if (!(cprm.file->f_mode & FMODE_CAN_WRITE)) { 736 - retval = -EACCES; 765 + if (!(cprm.file->f_mode & FMODE_CAN_WRITE)) 737 766 goto close_fail; 738 - } 739 - retval = do_truncate(idmap, cprm.file->f_path.dentry, 740 - 0, 0, cprm.file); 741 - if (retval) 767 + if (do_truncate(idmap, cprm.file->f_path.dentry, 768 + 0, 0, cprm.file)) 742 769 goto close_fail; 743 770 } 744 771 ··· 749 786 */ 750 787 if (!cprm.file) { 751 788 coredump_report_failure("Core dump to |%s disabled", cn.corename); 752 - retval = -EPERM; 753 789 goto close_fail; 754 790 } 755 - if (!dump_vma_snapshot(&cprm)) { 756 - coredump_report_failure("Can't get VMA snapshot for core dump |%s", 757 - cn.corename); 758 - retval = -EACCES; 791 + if (!dump_vma_snapshot(&cprm)) 759 792 goto close_fail; 760 - } 761 793 762 794 file_start_write(cprm.file); 763 795 core_dumped = binfmt->core_dump(&cprm); ··· 768 810 } 769 811 file_end_write(cprm.file); 770 812 free_vma_snapshot(&cprm); 771 - } else { 772 - coredump_report_failure("Core dump to %s%s has been interrupted", 773 - ispipe ? "|" : "", cn.corename); 774 - retval = -EAGAIN; 775 - goto fail; 776 813 } 777 - coredump_report( 778 - "written to %s%s: VMAs: %d, size %zu; core: %lld bytes, pos %lld", 779 - ispipe ? "|" : "", cn.corename, 780 - cprm.vma_count, cprm.vma_data_size, cprm.written, cprm.pos); 781 814 if (ispipe && core_pipe_limit) 782 815 wait_for_dump_helpers(cprm.file); 783 - 784 - retval = 0; 785 - 786 816 close_fail: 787 817 if (cprm.file) 788 818 filp_close(cprm.file, NULL); ··· 785 839 fail_creds: 786 840 put_cred(cred); 787 841 fail: 788 - return retval; 842 + return; 789 843 } 790 844 791 845 /* ··· 805 859 if (dump_interrupted()) 806 860 return 0; 807 861 n = __kernel_write(file, addr, nr, &pos); 808 - if (n != nr) { 809 - if (n < 0) 810 - coredump_report_failure("failed when writing out, error %zd", n); 811 - else 812 - coredump_report_failure( 813 - "partially written out, only %zd(of %d) bytes written", 814 - n, nr); 815 - 862 + if (n != nr) 816 863 return 0; 817 - } 818 864 file->f_pos = pos; 819 865 cprm->written += n; 820 866 cprm->pos += n; ··· 819 881 static char zeroes[PAGE_SIZE]; 820 882 struct file *file = cprm->file; 821 883 if (file->f_mode & FMODE_LSEEK) { 822 - int ret; 823 - 824 - if (dump_interrupted()) 884 + if (dump_interrupted() || 885 + vfs_llseek(file, nr, SEEK_CUR) < 0) 825 886 return 0; 826 - 827 - ret = vfs_llseek(file, nr, SEEK_CUR); 828 - if (ret < 0) { 829 - coredump_report_failure("failed when seeking, error %d", ret); 830 - return 0; 831 - } 832 887 cprm->pos += nr; 833 888 return 1; 834 889 } else {
+2 -6
include/linux/coredump.h
··· 42 42 extern int dump_align(struct coredump_params *cprm, int align); 43 43 int dump_user_range(struct coredump_params *cprm, unsigned long start, 44 44 unsigned long len); 45 - extern int do_coredump(const kernel_siginfo_t *siginfo); 45 + extern void do_coredump(const kernel_siginfo_t *siginfo); 46 46 47 47 /* 48 48 * Logging for the coredump code, ratelimited. ··· 62 62 #define coredump_report_failure(fmt, ...) __COREDUMP_PRINTK(KERN_WARNING, fmt, ##__VA_ARGS__) 63 63 64 64 #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) {} 70 66 71 67 #define coredump_report(...) 72 68 #define coredump_report_failure(...)
+1 -20
kernel/signal.c
··· 2888 2888 current->flags |= PF_SIGNALED; 2889 2889 2890 2890 if (sig_kernel_coredump(signr)) { 2891 - int ret; 2892 - 2893 2891 if (print_fatal_signals) 2894 2892 print_fatal_signal(signr); 2895 2893 proc_coredump_connector(current); ··· 2899 2901 * first and our do_group_exit call below will use 2900 2902 * that value and ignore the one we pass it. 2901 2903 */ 2902 - ret = do_coredump(&ksig->info); 2903 - if (ret) 2904 - coredump_report_failure("coredump has not been created, error %d", 2905 - ret); 2906 - else if (!IS_ENABLED(CONFIG_COREDUMP)) { 2907 - /* 2908 - * Coredumps are not available, can't fail collecting 2909 - * the coredump. 2910 - * 2911 - * Leave a note though that the coredump is going to be 2912 - * not created. This is not an error or a warning as disabling 2913 - * support in the kernel for coredumps isn't commonplace, and 2914 - * the user must've built the kernel with the custom config so 2915 - * let them know all works as desired. 2916 - */ 2917 - coredump_report("no coredump collected as " 2918 - "that is disabled in the kernel configuration"); 2919 - } 2904 + do_coredump(&ksig->info); 2920 2905 } 2921 2906 2922 2907 /*