Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Comments

Improving kmod#3254

Merged
disconnect3d merged 14 commits intopwndbg:devfrom
jxuanli:kmod-improv-2
Aug 22, 2025
Merged

Improving kmod#3254
disconnect3d merged 14 commits intopwndbg:devfrom
jxuanli:kmod-improv-2

Conversation

@jxuanli
Copy link
Member

@jxuanli jxuanli commented Aug 20, 2025

  • supporting kmod without provided typeinfo
  • supporting kmod for all kernel versions >= 5.0
  • supporting loading module symbol files (without needing to specify base address)
  • including kernel module symbols in kallsyms (klookup)

demo

image


def modules() -> pwndbg.dbg_mod.Value:
if arch_symbols() is not None:
return arch_symbols().modules()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this?:

if syms := arch_symbols() is not None:
    return syms.modules()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is cached so would be the same

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure but it's still Python which cannot into nice optimisations (hopefully yet?)

Not like it matters a lot in this case but still :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the kmod command by supporting kernel module operations without requiring debug type information, expanding compatibility to all kernel versions >= 5.0, and adding functionality to load module symbol files automatically. The changes also integrate kernel module symbols into the kallsyms system for better symbol lookup.

Key changes:

  • Enhanced kmod command to work without debug type information by implementing fallback mechanisms
  • Added support for loading module symbol files with automatic base address detection
  • Integrated kernel module symbols into the kallsyms system for comprehensive symbol lookup

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
pwndbg/commands/kmod.py Enhanced to support both typeinfo and non-typeinfo modes, added module loading functionality
pwndbg/aglib/kernel/kmod.py New module providing kernel module parsing utilities without requiring debug symbols
pwndbg/aglib/kernel/symbol.py Added modules() method and architecture-specific implementations for finding module lists
pwndbg/aglib/kernel/kallsyms.py Integrated kernel module symbols into the kallsyms system
pwndbg/dbg/__init__.py Added abstract add_symbol_file method to the debugger interface
pwndbg/dbg/gdb/__init__.py Implemented GDB-specific add_symbol_file functionality
pwndbg/commands/kbase.py Refactored to use the new debugger interface for adding symbol files
tests/library/qemu_system/tests/test_commands_kernel.py Updated test to check for specific debug symbols instead of general debug info
docs/commands/kernel/kmod.md Updated documentation to reflect new -l/--load option

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

self.kernel_addresses = self.get_kernel_addresses()
self.parse_symbol_table()
for sym_name, sym_addr, sym_type in pwndbg.aglib.kernel.kmod.all_modules_kallsyms():
self.kallsyms[sym_name] = (sym_addr, sym_type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do it like this?:

self.kallsyms = {
    sym_name: (sym_addr, sym_type) for sym_name, sym_addr, sym_type in pwndbg.aglib.kernel.kmod.all_modules_kallsyms()
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.kallsyms is likely not empty by this point

return ()
modules = int(modules)
result = []
cur = pwndbg.aglib.memory.read_pointer_width(int(modules))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modules is already an int

print(M.warn("Cound not find modules"))
return None
module = pwndbg.aglib.memory.read_pointer_width(int(modules))
for i in range(0x100):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 0x100? is this arbitrary? can we add a comment saying why this number?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is arbitrary

found = False
break
size_offset = pwndbg.aglib.arch.ptrsize
if pwndbg.aglib.kernel.krelease() >= (6, 13):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any link to source why?

m = pattern.search(disass)
if m is None:
return None
return sum([int(m.group(i), 16) for i in [2, 3, 4]])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return sum([int(m.group(i), 16) for i in [2, 3, 4]])
return sum(int(m.group(i), 16) for i in [2, 3, 4])

if pwndbg.aglib.memory.peek(symtab) is None:
continue
num_symtab = pwndbg.aglib.memory.read_pointer_width(
kallsyms + pwndbg.aglib.arch.ptrsize * 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
kallsyms + pwndbg.aglib.arch.ptrsize * 1
kallsyms + pwndbg.aglib.arch.ptrsize

min_size + 0x38,
):
found = True
for mem_type in range(mod_mem_type.MOD_MEM_NUM_TYPES.value - 1):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -1 is here because MOD_MEM_NUM_TYPES is just number of all items and we want to skip it, is that right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we actually need to skip MOD_RO_AFTER_INIT because the entry might be empty

@jxuanli
Copy link
Member Author

jxuanli commented Aug 20, 2025

@disconnect3d could you check again

@disconnect3d disconnect3d merged commit 41c8bc7 into pwndbg:dev Aug 22, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants