Skip to content

Commit

Permalink
elfdump: Fix page bitmaps for overlapping segments
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ptesarik committed Nov 18, 2023
1 parent e05d1ba commit 5830785
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/kdumpfile/elfdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down Expand Up @@ -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;
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
66 changes: 66 additions & 0 deletions tests/elf-overlap
Original file line number Diff line number Diff line change
@@ -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" <<EOF
# first LOAD |####|
# second LOAD |####|
@phdr type=LOAD offset=0x1000 vaddr=0x1000 paddr=0x1000 memsz=0x4000
55*0x1000
@phdr type=LOAD vaddr=0x3000 paddr=0x3000 memsz=0x4000
# first LOAD |########|
# second LOAD |####|
@phdr type=LOAD vaddr=0xa000 paddr=0xa000 memsz=0x8000
55*0x2000
@phdr type=LOAD vaddr=0xc000 paddr=0xc000 memsz=0x4000
aa*0x2000
# first LOAD |####|
# second LOAD |##|
@phdr type=LOAD vaddr=0x18000 paddr=0x18000 memsz=0x4000
@phdr type=LOAD vaddr=0x1c000 paddr=0x1c000 memsz=0x2000
aa*0x1000
EOF

./mkelf "$dumpfile" <<EOF
ei_class = 2
ei_data = 1
e_machine = 62
e_phoff = 64
DATA = $datafile
EOF
rc=$?
if [ $rc -ne 0 ]; then
echo "Cannot create ELF file" >&2
exit $rc
fi
echo "Created ELF dump: $dumpfile"

./checkattr "$dumpfile" <<EOF
file = directory:
file.set.number = number:1
file.set.0 = directory:
file.set.0.fd = number
file.format = string: elf
file.pagemap = bitmap:0x02 0x3c 0x00 0x10
memory.pagemap = bitmap:0x7e 0xfc 0x03 0x3f
EOF
rc=$?
if [ $rc -ne 0 ]; then
echo "Attribute check failed" >&2
exit $rc
fi

exit 0

0 comments on commit 5830785

Please sign in to comment.