06c2a2
From 590f35e773dcd51a750b9a181863660a25b66f01 Mon Sep 17 00:00:00 2001
06c2a2
From: Petr Tesarik <ptesarik@suse.com>
06c2a2
Date: Fri, 19 Jan 2018 20:46:19 +0900
06c2a2
Subject: [PATCH 1/2] [PATCH 1/2] Fix off-by-one errors in exclude_segment()
06c2a2
06c2a2
The crashed reserved memory end offset is the last address within
06c2a2
range, whereas the end offset in the pt_loads[] denotes the first
06c2a2
address past the range. This has caused a number of off-by-one
06c2a2
errors in exclude_segment().
06c2a2
06c2a2
First, let's unify the meaning of "end" to be the first out-of-range
06c2a2
address, i.e. start + size. Thanks to that, no +1 or -1 adjustments
06c2a2
are needed in exclude_segment().
06c2a2
06c2a2
Second, since the value read from /proc/iomem is the last address
06c2a2
within range, add one when passing it as an argument to
06c2a2
exclude_segment(). This is now the only adjustment by one.
06c2a2
06c2a2
Signed-off-by: Petr Tesarik <ptesarik@suse.com>
06c2a2
Tested-by: Bhupesh Sharma <bhsharma@redhat.com>
06c2a2
---
06c2a2
 elf_info.c | 18 +++++++++---------
06c2a2
 1 file changed, 9 insertions(+), 9 deletions(-)
06c2a2
06c2a2
diff --git a/makedumpfile-1.6.2/elf_info.c b/makedumpfile-1.6.2/elf_info.c
06c2a2
index 69b1719b020f..1eaddd968826 100644
06c2a2
--- a/makedumpfile-1.6.2/elf_info.c
06c2a2
+++ b/makedumpfile-1.6.2/elf_info.c
06c2a2
@@ -820,26 +820,26 @@ static int exclude_segment(struct pt_load_segment **pt_loads,
06c2a2
 		if (kvstart <  vend && kvend > vstart) {
06c2a2
 			if (kvstart != vstart && kvend != vend) {
06c2a2
 				/* Split load segment */
06c2a2
-				temp_seg.phys_start = end + 1;
06c2a2
+				temp_seg.phys_start = end;
06c2a2
 				temp_seg.phys_end = (*pt_loads)[i].phys_end;
06c2a2
-				temp_seg.virt_start = kvend + 1;
06c2a2
+				temp_seg.virt_start = kvend;
06c2a2
 				temp_seg.virt_end = vend;
06c2a2
 				temp_seg.file_offset = (*pt_loads)[i].file_offset
06c2a2
 					+ temp_seg.virt_start - (*pt_loads)[i].virt_start;
06c2a2
 				temp_seg.file_size = temp_seg.phys_end
06c2a2
 					- temp_seg.phys_start;
06c2a2
 
06c2a2
-				(*pt_loads)[i].virt_end = kvstart - 1;
06c2a2
-				(*pt_loads)[i].phys_end =  start - 1;
06c2a2
+				(*pt_loads)[i].virt_end = kvstart;
06c2a2
+				(*pt_loads)[i].phys_end =  start;
06c2a2
 				(*pt_loads)[i].file_size -= temp_seg.file_size;
06c2a2
 
06c2a2
 				tidx = i+1;
06c2a2
 			} else if (kvstart != vstart) {
06c2a2
-				(*pt_loads)[i].phys_end = start - 1;
06c2a2
-				(*pt_loads)[i].virt_end = kvstart - 1;
06c2a2
+				(*pt_loads)[i].phys_end = start;
06c2a2
+				(*pt_loads)[i].virt_end = kvstart;
06c2a2
 			} else {
06c2a2
-				(*pt_loads)[i].phys_start = end + 1;
06c2a2
-				(*pt_loads)[i].virt_start = kvend + 1;
06c2a2
+				(*pt_loads)[i].phys_start = end;
06c2a2
+				(*pt_loads)[i].virt_start = kvend;
06c2a2
 			}
06c2a2
 			(*pt_loads)[i].file_size -= (end -start);
06c2a2
 		}
06c2a2
@@ -917,7 +917,7 @@ int get_kcore_dump_loads(void)
06c2a2
 
06c2a2
 	for (i = 0; i < crash_reserved_mem_nr; i++)	{
06c2a2
 		exclude_segment(&pt_loads, &num_pt_loads,
06c2a2
-				crash_reserved_mem[i].start, crash_reserved_mem[i].end);
06c2a2
+				crash_reserved_mem[i].start, crash_reserved_mem[i].end + 1);
06c2a2
 	}
06c2a2
 
06c2a2
 	max_file_offset = 0;
06c2a2
-- 
06c2a2
2.7.4
06c2a2