diff --git a/pwndbg/aglib/kernel/__init__.py b/pwndbg/aglib/kernel/__init__.py index aef9fabaa..6050c9848 100644 --- a/pwndbg/aglib/kernel/__init__.py +++ b/pwndbg/aglib/kernel/__init__.py @@ -131,7 +131,9 @@ def first_kernel_ro_page() -> pwndbg.lib.memory.Page | None: if result: return mapping - for mapping in fallback_mappings: + # optimization: observe that the first Linux kernel region is the kernel text so search it last + # it now finds the first ro page almost instantly even for kernels that are partially initialized + for mapping in fallback_mappings[1:] + [fallback_mappings[0]]: # this loop handles when the kernel has not finished initialization # and the permission of the first ro page has not been properly set result = next(pwndbg.search.search(b"Linux version", mappings=[mapping]), None)