From 5830785322060ddd97b6baf7d8711a13738f61b5 Mon Sep 17 00:00:00 2001 From: Petr Tesarik Date: Sat, 18 Nov 2023 22:09:50 +0100 Subject: [PATCH] elfdump: Fix page bitmaps for overlapping segments When enumerating LOAD segments, do not update the current PFN position if a previous segment ended on a higher address. Signed-off-by: Petr Tesarik --- src/kdumpfile/elfdump.c | 12 ++++---- tests/Makefile.am | 1 + tests/elf-overlap | 66 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 5 deletions(-) create mode 100755 tests/elf-overlap diff --git a/src/kdumpfile/elfdump.c b/src/kdumpfile/elfdump.c index e4dee2ff..bd5b791e 100644 --- a/src/kdumpfile/elfdump.c +++ b/src/kdumpfile/elfdump.c @@ -462,9 +462,10 @@ elf_get_bits(struct kdump_shared *shared, set_bits(bits, cur - first, last - first); return; } - set_bits(bits, cur - first, next - first); - - cur = next + 1; + if (cur <= next) { + set_bits(bits, cur - first, next - first); + cur = next + 1; + } ++pls; } while (pls < &edp->load_sorted[edp->num_load_sorted]); @@ -560,8 +561,9 @@ elf_find_clear(kdump_errmsg_t *err, struct kdump_shared *shared, while (pls < &edp->load_sorted[edp->num_load_sorted] && *idx >= addr_to_pfn(shared, pls->phys)) { kdump_paddr_t size = ismem ? pls->memsz : pls->filesz; - *idx = addr_to_pfn(shared, pls->phys + size - 1); - ++(*idx); + kdump_paddr_t pfn = addr_to_pfn(shared, pls->phys + size - 1); + if (pfn >= *idx) + *idx = pfn + 1; ++pls; } } diff --git a/tests/Makefile.am b/tests/Makefile.am index 2f5f3c61..0c03b20b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -232,6 +232,7 @@ test_scripts = \ elf-partial \ elf-fractional \ elf-multiread \ + elf-overlap \ elf-virt-phys-clash \ elf-vmcoreinfo \ elf-dom0-no-phys_base \ diff --git a/tests/elf-overlap b/tests/elf-overlap new file mode 100755 index 00000000..af5b9f2b --- /dev/null +++ b/tests/elf-overlap @@ -0,0 +1,66 @@ +#! /bin/sh + +# +# Create an ELF file with overlapping LOAD segments and verify that +# the page map is merged correctly +# + +mkdir -p out || exit 99 + +name=$( basename "$0" ) +datafile="out/${name}.data" +dumpfile="out/${name}.dump" + +cat >"$datafile" <&2 + exit $rc +fi +echo "Created ELF dump: $dumpfile" + +./checkattr "$dumpfile" <&2 + exit $rc +fi + +exit 0