Blame kexec-tools-2.0.23-makedumpfile-Avoid_false_positive_mem_section_validation_with_vmlinux.patch

Philipp Rudo 634888
 commit 6d0d95ecc04a70f8448d562ff0fbbae237f5c929
Philipp Rudo 634888
 Author: Kazuhito Hagio <k-hagio-ab@nec.com>
Philipp Rudo 634888
 Date:   Thu Apr 21 08:58:29 2022 +0900
Philipp Rudo 634888
 
Philipp Rudo 634888
     [PATCH] Avoid false-positive mem_section validation with vmlinux
Philipp Rudo 634888
     
Philipp Rudo 634888
     Currently get_mem_section() validates if SYMBOL(mem_section) is the address
Philipp Rudo 634888
     of the mem_section array first.  But there was a report that the first
Philipp Rudo 634888
     validation wrongly returned TRUE with -x vmlinux and SPARSEMEM_EXTREME
Philipp Rudo 634888
     (4.15+) on s390x.  This leads to crash failing statup with the following
Philipp Rudo 634888
     seek error:
Philipp Rudo 634888
     
Philipp Rudo 634888
       crash: seek error: kernel virtual address: 67fffc2800  type: "memory section root table"
Philipp Rudo 634888
     
Philipp Rudo 634888
     Skip the first validation when satisfying the conditions.
Philipp Rudo 634888
     
Philipp Rudo 634888
     Reported-by: Dave Wysochanski <dwysocha@redhat.com>
Philipp Rudo 634888
     Signed-off-by: Kazuhito Hagio <k-hagio-ab@nec.com>
Philipp Rudo 634888
     Reviewed-and-Tested-by: Philipp Rudo <prudo@redhat.com>
Philipp Rudo 634888
     Reviewed-by: Pingfan Liu <piliu@redhat.com>
Philipp Rudo 634888
 
d180b0
 diff --git a/makedumpfile-1.7.1/makedumpfile.c b/makedumpfile-1.7.1/makedumpfile.c
Philipp Rudo 634888
 index a2f45c84cee3ba57ce3d3cf3f1905e6a03f4fd09..65d1c7c2f02c9ae8ead9de0f0217235fe72b3ca7 100644
d180b0
 --- a/makedumpfile-1.7.1/makedumpfile.c
d180b0
 +++ b/makedumpfile-1.7.1/makedumpfile.c
Philipp Rudo 634888
 @@ -3698,6 +3698,22 @@ validate_mem_section(unsigned long *mem_sec,
Philipp Rudo 634888
  	return ret;
Philipp Rudo 634888
  }
Philipp Rudo 634888
  
Philipp Rudo 634888
 +/*
Philipp Rudo 634888
 + * SYMBOL(mem_section) varies with the combination of memory model and
Philipp Rudo 634888
 + * its source:
Philipp Rudo 634888
 + *
Philipp Rudo 634888
 + * SPARSEMEM
Philipp Rudo 634888
 + *   vmcoreinfo: address of mem_section root array
Philipp Rudo 634888
 + *   -x vmlinux: address of mem_section root array
Philipp Rudo 634888
 + *
Philipp Rudo 634888
 + * SPARSEMEM_EXTREME v1
Philipp Rudo 634888
 + *   vmcoreinfo: address of mem_section root array
Philipp Rudo 634888
 + *   -x vmlinux: address of mem_section root array
Philipp Rudo 634888
 + *
Philipp Rudo 634888
 + * SPARSEMEM_EXTREME v2 (with 83e3c48729d9 and a0b1280368d1) 4.15+
Philipp Rudo 634888
 + *   vmcoreinfo: address of mem_section root array
Philipp Rudo 634888
 + *   -x vmlinux: address of pointer to mem_section root array
Philipp Rudo 634888
 + */
Philipp Rudo 634888
  static int
Philipp Rudo 634888
  get_mem_section(unsigned int mem_section_size, unsigned long *mem_maps,
Philipp Rudo 634888
  		unsigned int num_section)
Philipp Rudo 634888
 @@ -3710,12 +3726,27 @@ get_mem_section(unsigned int mem_section_size, unsigned long *mem_maps,
Philipp Rudo 634888
  		    strerror(errno));
Philipp Rudo 634888
  		return FALSE;
Philipp Rudo 634888
  	}
Philipp Rudo 634888
 +
Philipp Rudo 634888
 +	/*
Philipp Rudo 634888
 +	 * There was a report that the first validation wrongly returned TRUE
Philipp Rudo 634888
 +	 * with -x vmlinux and SPARSEMEM_EXTREME v2 on s390x, so skip it.
Philipp Rudo 634888
 +	 * Howerver, leave the fallback validation as it is for the -i option.
Philipp Rudo 634888
 +	 */
Philipp Rudo 634888
 +	if (is_sparsemem_extreme() && info->name_vmlinux) {
Philipp Rudo 634888
 +		unsigned long flag = 0;
Philipp Rudo 634888
 +		if (get_symbol_type_name("mem_section", DWARF_INFO_GET_SYMBOL_TYPE,
Philipp Rudo 634888
 +					NULL, &flag)
Philipp Rudo 634888
 +		    && !(flag & TYPE_ARRAY))
Philipp Rudo 634888
 +			goto skip_1st_validation;
Philipp Rudo 634888
 +	}
Philipp Rudo 634888
 +
Philipp Rudo 634888
  	ret = validate_mem_section(mem_sec, SYMBOL(mem_section),
Philipp Rudo 634888
  				   mem_section_size, mem_maps, num_section);
Philipp Rudo 634888
  
Philipp Rudo 634888
  	if (!ret && is_sparsemem_extreme()) {
Philipp Rudo 634888
  		unsigned long mem_section_ptr;
Philipp Rudo 634888
  
Philipp Rudo 634888
 +skip_1st_validation:
Philipp Rudo 634888
  		if (!readmem(VADDR, SYMBOL(mem_section), &mem_section_ptr,
Philipp Rudo 634888
  			     sizeof(mem_section_ptr)))
Philipp Rudo 634888
  			goto out;