Blame SOURCES/kexec-tools-2.0.15-makedumpfile-Fix-off-by-one-errors-in-exclude_segment.patch

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