Skip to content

Commit

Permalink
tests: don't clobber file in use by libelf
Browse files Browse the repository at this point in the history
Overwriting a file that libelf has already mmap'd can confuse it and
cause it to crash. In particular, libelf/elf_begin.c::file_read_elf()
initializes Elf_Scn::rawdata_base and Elf_Scn::data_base from the mmap'd
file. libelf/elf_getdata.c::__libelf_set_rawdata_wrlock() also sets
Elf_Scn::rawdata_base from the mmap'd file. If the file changes between
those two events, then Elf_Scn::rawdata_base will change. Then, the
following line in libelf/elf_end.c::elf_end() will try to free an mmap'd
pointer:

	if (scn->data_base != scn->rawdata_base)
	  free (scn->data_base);

Stephen reported crashes like this from
test_gnu_debugaltlink_debug_directories() while testing a patch that
inadvertently caused debug info to be indexed on module creation.

Reported-by: Stephen Brennan <stephen.s.brennan@oracle.com>
Signed-off-by: Omar Sandoval <osandov@osandov.com>
  • Loading branch information
osandov committed Dec 19, 2024
1 parent 4e83130 commit 3ce0fee
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions tests/test_debug_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2283,8 +2283,6 @@ def test_gnu_debugaltlink_debug_directories(self):
alt_path.parent.mkdir()
alt_path.write_bytes(compile_dwarf((), build_id=alt_build_id))

binary_path = bin_dir / "binary"

self.prog.debug_info_path = ":.debug:" + str(debug_dir)
for i, debugaltlink in enumerate(
(
Expand All @@ -2293,6 +2291,7 @@ def test_gnu_debugaltlink_debug_directories(self):
)
):
with self.subTest(debugaltlink=debugaltlink):
binary_path = bin_dir / f"binary{i}"
binary_path.write_bytes(
compile_dwarf(
(),
Expand All @@ -2303,9 +2302,7 @@ def test_gnu_debugaltlink_debug_directories(self):
)
)

module = self.prog.extra_module(bin_dir / "binary", i, create=True)[
0
]
module = self.prog.extra_module(binary_path, create=True)[0]
self.prog.load_module_debug_info(module)
self.assertEqual(module.loaded_file_status, ModuleFileStatus.HAVE)
self.assertEqual(module.debug_file_status, ModuleFileStatus.HAVE)
Expand Down

0 comments on commit 3ce0fee

Please sign in to comment.