Skip to content

Commit

Permalink
drgn.helpers.common.memory: fix identify_address vmap identification …
Browse files Browse the repository at this point in the history
…with CONFIG_VMAP_STACK=n

In the uncached case, the task variable is supposed to be the task that
matched the vm area. But, if we detect that CONFIG_VMAP_STACK is
disabled, we break without clearing the task variable. Fix that, and
also make sure to test both the cached and uncached cases.

Closes #414.

Fixes: 69bd07d ("drgn.helpers.common.memory: add optional cache to identify_address()")
Reported-by: Sourabh Jain <[email protected]>
Signed-off-by: Omar Sandoval <[email protected]>
  • Loading branch information
osandov committed Jul 25, 2024
1 parent 1832240 commit 9ad29fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions drgn/helpers/common/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def _identify_kernel_vmap(
break
except AttributeError:
# CONFIG_VMAP_STACK must be disabled.
task = None
break
except FaultError:
continue
Expand Down
26 changes: 17 additions & 9 deletions tests/linux_kernel/helpers/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,28 @@ def test_identify_slab_cache(self):

@skip_unless_have_test_kmod
def test_identify_vmap(self):
self.assertTrue(
identify_address(self.prog["drgn_test_vmalloc_va"]).startswith("vmap: 0x")
)
for cache in (None, {}):
with self.subTest("uncached" if cache is None else "cached"):
self.assertTrue(
identify_address(
self.prog["drgn_test_vmalloc_va"], cache=cache
).startswith("vmap: 0x")
)

@skip_unless_have_test_kmod
def test_identify_vmap_stack(self):
if not self.prog["drgn_test_vmap_stack_enabled"]:
self.skipTest("kernel does not use vmap stacks (CONFIG_VMAP_STACK)")
self.assertEqual(
identify_address(
self.prog, self.prog["drgn_test_kthread"].stack.value_() + 1234
),
f"vmap stack: {self.prog['drgn_test_kthread'].pid.value_()} (drgn_test_kthre) +0x4d2",
)
for cache in (None, {}):
with self.subTest("uncached" if cache is None else "cached"):
self.assertEqual(
identify_address(
self.prog,
self.prog["drgn_test_kthread"].stack.value_() + 1234,
cache=cache,
),
f"vmap stack: {self.prog['drgn_test_kthread'].pid.value_()} (drgn_test_kthre) +0x4d2",
)

@skip_unless_have_full_mm_support
@skip_unless_have_test_kmod
Expand Down

0 comments on commit 9ad29fd

Please sign in to comment.