@@ -465,17 +465,7 @@ static bool dump_interrupted(void)
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 )
@@ -530,15 +520,15 @@ static int umh_pipe_setup(struct subprocess_info *info, struct cred *new)
530
520
return err ;
531
521
}
532
522
533
- int do_coredump (const kernel_siginfo_t * siginfo )
523
+ void do_coredump (const kernel_siginfo_t * siginfo )
534
524
{
535
525
struct core_state core_state ;
536
526
struct core_name cn ;
537
527
struct mm_struct * mm = current -> mm ;
538
528
struct linux_binfmt * binfmt ;
539
529
const struct cred * old_cred ;
540
530
struct cred * cred ;
541
- int retval ;
531
+ int retval = 0 ;
542
532
int ispipe ;
543
533
size_t * argv = NULL ;
544
534
int argc = 0 ;
@@ -562,20 +552,14 @@ int do_coredump(const kernel_siginfo_t *siginfo)
562
552
audit_core_dumps (siginfo -> si_signo );
563
553
564
554
binfmt = mm -> binfmt ;
565
- if (!binfmt || !binfmt -> core_dump ) {
566
- retval = - ENOEXEC ;
555
+ if (!binfmt || !binfmt -> core_dump )
567
556
goto fail ;
568
- }
569
- if (!__get_dumpable (cprm .mm_flags )) {
570
- retval = - EACCES ;
557
+ if (!__get_dumpable (cprm .mm_flags ))
571
558
goto fail ;
572
- }
573
559
574
560
cred = prepare_creds ();
575
- if (!cred ) {
576
- retval = - EPERM ;
561
+ if (!cred )
577
562
goto fail ;
578
- }
579
563
/*
580
564
* We cannot trust fsuid as being the "true" uid of the process
581
565
* 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)
604
588
605
589
if (ispipe < 0 ) {
606
590
coredump_report_failure ("format_corename failed, aborting core" );
607
- retval = ispipe ;
608
591
goto fail_unlock ;
609
592
}
610
593
@@ -625,23 +608,20 @@ int do_coredump(const kernel_siginfo_t *siginfo)
625
608
* core_pattern process dies.
626
609
*/
627
610
coredump_report_failure ("RLIMIT_CORE is set to 1, aborting core" );
628
- retval = - EPERM ;
629
611
goto fail_unlock ;
630
612
}
631
613
cprm .limit = RLIM_INFINITY ;
632
614
633
615
dump_count = atomic_inc_return (& core_dump_count );
634
616
if (core_pipe_limit && (core_pipe_limit < dump_count )) {
635
617
coredump_report_failure ("over core_pipe_limit, skipping core dump" );
636
- retval = - E2BIG ;
637
618
goto fail_dropcount ;
638
619
}
639
620
640
621
helper_argv = kmalloc_array (argc + 1 , sizeof (* helper_argv ),
641
622
GFP_KERNEL );
642
623
if (!helper_argv ) {
643
624
coredump_report_failure ("%s failed to allocate memory" , __func__ );
644
- retval = - ENOMEM ;
645
625
goto fail_dropcount ;
646
626
}
647
627
for (argi = 0 ; argi < argc ; argi ++ )
@@ -667,16 +647,12 @@ int do_coredump(const kernel_siginfo_t *siginfo)
667
647
int open_flags = O_CREAT | O_WRONLY | O_NOFOLLOW |
668
648
O_LARGEFILE | O_EXCL ;
669
649
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 )
673
651
goto fail_unlock ;
674
- }
675
652
676
653
if (need_suid_safe && cn .corename [0 ] != '/' ) {
677
654
coredump_report_failure (
678
655
"this process can only dump core to a fully qualified path, skipping core dump" );
679
- retval = - EPERM ;
680
656
goto fail_unlock ;
681
657
}
682
658
@@ -722,28 +698,20 @@ int do_coredump(const kernel_siginfo_t *siginfo)
722
698
} else {
723
699
cprm .file = filp_open (cn .corename , open_flags , 0600 );
724
700
}
725
- if (IS_ERR (cprm .file )) {
726
- retval = PTR_ERR (cprm .file );
701
+ if (IS_ERR (cprm .file ))
727
702
goto fail_unlock ;
728
- }
729
703
730
704
inode = file_inode (cprm .file );
731
- if (inode -> i_nlink > 1 ) {
732
- retval = - EMLINK ;
705
+ if (inode -> i_nlink > 1 )
733
706
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 ))
737
708
goto close_fail ;
738
- }
739
709
/*
740
710
* AK: actually i see no reason to not allow this for named
741
711
* pipes etc, but keep the previous behaviour for now.
742
712
*/
743
- if (!S_ISREG (inode -> i_mode )) {
744
- retval = - EISDIR ;
713
+ if (!S_ISREG (inode -> i_mode ))
745
714
goto close_fail ;
746
- }
747
715
/*
748
716
* Don't dump core if the filesystem changed owner or mode
749
717
* of the file during file creation. This is an issue when
@@ -755,22 +723,17 @@ int do_coredump(const kernel_siginfo_t *siginfo)
755
723
current_fsuid ())) {
756
724
coredump_report_failure ("Core dump to %s aborted: "
757
725
"cannot preserve file owner" , cn .corename );
758
- retval = - EPERM ;
759
726
goto close_fail ;
760
727
}
761
728
if ((inode -> i_mode & 0677 ) != 0600 ) {
762
729
coredump_report_failure ("Core dump to %s aborted: "
763
730
"cannot preserve file permissions" , cn .corename );
764
- retval = - EPERM ;
765
731
goto close_fail ;
766
732
}
767
- if (!(cprm .file -> f_mode & FMODE_CAN_WRITE )) {
768
- retval = - EACCES ;
733
+ if (!(cprm .file -> f_mode & FMODE_CAN_WRITE ))
769
734
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 ))
774
737
goto close_fail ;
775
738
}
776
739
@@ -786,15 +749,10 @@ int do_coredump(const kernel_siginfo_t *siginfo)
786
749
*/
787
750
if (!cprm .file ) {
788
751
coredump_report_failure ("Core dump to |%s disabled" , cn .corename );
789
- retval = - EPERM ;
790
752
goto close_fail ;
791
753
}
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 ))
796
755
goto close_fail ;
797
- }
798
756
799
757
file_start_write (cprm .file );
800
758
core_dumped = binfmt -> core_dump (& cprm );
@@ -810,21 +768,9 @@ int do_coredump(const kernel_siginfo_t *siginfo)
810
768
}
811
769
file_end_write (cprm .file );
812
770
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 ;
818
771
}
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 );
823
772
if (ispipe && core_pipe_limit )
824
773
wait_for_dump_helpers (cprm .file );
825
-
826
- retval = 0 ;
827
-
828
774
close_fail :
829
775
if (cprm .file )
830
776
filp_close (cprm .file , NULL );
@@ -839,7 +785,7 @@ int do_coredump(const kernel_siginfo_t *siginfo)
839
785
fail_creds :
840
786
put_cred (cred );
841
787
fail :
842
- return retval ;
788
+ return ;
843
789
}
844
790
845
791
/*
@@ -859,16 +805,8 @@ static int __dump_emit(struct coredump_params *cprm, const void *addr, int nr)
859
805
if (dump_interrupted ())
860
806
return 0 ;
861
807
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 )
870
809
return 0 ;
871
- }
872
810
file -> f_pos = pos ;
873
811
cprm -> written += n ;
874
812
cprm -> pos += n ;
@@ -881,16 +819,9 @@ static int __dump_skip(struct coredump_params *cprm, size_t nr)
881
819
static char zeroes [PAGE_SIZE ];
882
820
struct file * file = cprm -> file ;
883
821
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 )
887
824
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
- }
894
825
cprm -> pos += nr ;
895
826
return 1 ;
896
827
} else {
0 commit comments