Skip to content

Commit

Permalink
debuginfo: kernel modules with hyphen in filename
Browse files Browse the repository at this point in the history
The module debuginfo code is already written to be careful with respect
to module names that have hyphens and underscores. The filenames may not
match the name that the kernel uses (e.g. filenames may contain hyphens,
while the kernel's name contains underscores).

However, we were clearly not careful enough. When kernel module
debuginfo is installed directly on the system, the loader did not search
for the hyphenated version of module names with underscores. This led to
missing debuginfo for modules like "dm_mod" (whose filename is
dm-mod.ko.debug). Notably, the error did not occur on systems where
drgn-tools extracts the RPM, since we take pains to rename all modules
so their filename uses underscores instead of hyphens. The result is
that this bug only really occurs when the debuginfo package is installed
on the system.

Update the _find_debuginfo() function to allow hyphens or underscores,
and check for the existence of both.

Signed-off-by: Stephen Brennan <[email protected]>
  • Loading branch information
brenns10 committed Nov 29, 2023
1 parent 05c701d commit d553087
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions drgn_tools/debuginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,19 +310,22 @@ def _get_debuginfo_paths(


def _find_debuginfo(paths: List[Path], mod: str) -> Optional[Path]:
replace_pat = re.compile(r"[_-]")
for search_dir in paths:
if "lib/modules" in str(search_dir) and mod != "vmlinux":
# If the path contains "lib/modules", it's likely the result of
# extracting an RPM. That means that we'll have a nested directory
# structure to search for modules. Be lenient on hyphens and
# underscores too.
mod_pat = mod.replace("-", "[_-]")
mod_pat = replace_pat.sub("[_-]", mod)
for candidate in search_dir.glob(f"**/{mod_pat}.ko.debug*"):
return candidate
else:
name_no_hyphen = None
name_alt = None
if "-" in mod:
name_no_hyphen = mod.replace("-", "_")
name_alt = mod.replace("-", "_")
elif "_" in mod:
name_alt = mod.replace("_", "-")
exts = (
("",) if mod == "vmlinux" else (".ko.debug", ".ko", ".ko.xz")
)
Expand All @@ -335,10 +338,9 @@ def _find_debuginfo(paths: List[Path], mod: str) -> Optional[Path]:
candidate = search_dir / f"{mod}{ext}"
if candidate.exists():
return candidate
# try the standardized underscore
if name_no_hyphen:
candidate = search_dir / f"{name_no_hyphen}{ext}"
print(candidate)
# try the alternative name (hyphen or underscore)
if name_alt:
candidate = search_dir / f"{name_alt}{ext}"
if candidate.exists():
return candidate
return None
Expand Down

0 comments on commit d553087

Please sign in to comment.