@@ -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
481471static 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-
828774close_fail :
829775 if (cprm .file )
830776 filp_close (cprm .file , NULL );
@@ -839,7 +785,7 @@ int do_coredump(const kernel_siginfo_t *siginfo)
839785fail_creds :
840786 put_cred (cred );
841787fail :
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 {
0 commit comments