@@ -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+ }
879910EXPORT_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
915946int 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}
922955EXPORT_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.
0 commit comments