-
Notifications
You must be signed in to change notification settings - Fork 915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port kernel vmmap to aglib #2634
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #2634 +/- ##
=========================================
- Coverage 10.60% 5.36% -5.25%
=========================================
Files 214 218 +4
Lines 23904 24115 +211
Branches 3617 3652 +35
=========================================
- Hits 2535 1293 -1242
- Misses 20917 22633 +1716
+ Partials 452 189 -263 ☔ View full report in Codecov by Sentry. |
72c3137
to
04c5203
Compare
@@ -649,6 +650,10 @@ def paging_enabled() -> bool: | |||
return x86_64Ops.paging_enabled() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Random note: we should reorder this to x86-64, aarch64, rv64, i386
elif arch_name == "rv64": | ||
# https://starfivetech.com/uploads/u74_core_complex_manual_21G1.pdf | ||
# page 41, satp.MODE, bits: 60,61,62,63 | ||
return int(pwndbg.aglib.regs.satp) & (BIT(60) | BIT(61) | BIT(62) | BIT(63)) != 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pwndbg/aglib/kernel/vmmap.py
Outdated
self.pid = QemuMachine.get_qemu_pid() | ||
self.file = None | ||
self.file = os.open(f"/proc/{self.pid}/mem", os.O_RDONLY) | ||
self.mem_size = os.fstat(self.file).st_size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this make sense?
(.venv) root@pwndbg:~# ls -la /proc/self/mem
-rw------- 1 root root 0 Dec 18 13:00 /proc/self/mem
(.venv) root@pwndbg:~# stat /proc/self/mem
File: /proc/self/mem
Size: 0 Blocks: 0 IO Block: 1024 regular empty file
Device: 0,22 Inode: 29332658 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2024-12-18 13:00:15.561108327 +0000
Modify: 2024-12-18 13:00:15.561108327 +0000
Change: 2024-12-18 13:00:15.561108327 +0000
Birth: -
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In [4]: f=os.open('/proc/self/mem', os.O_RDONLY)
In [5]: os.fstat(f).st_size
Out[5]: 0
cc: @martinradev
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f"chardev-add file,id={chardev_id},path={tmpf.name}" | ||
) | ||
pid_found = QemuMachine.search_pids_for_file(pids, tmpf.name) | ||
pwndbg.dbg.selected_inferior().send_monitor(f"chardev-remove {chardev_id}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol this is a smart hack to detect the given QEMU process PID.
Maybe we should implement a monitor command to just return QEMU pid? :D
# Handle disabled PG | ||
# This will prevent a crash on abstract architectures | ||
if len(lines) == 1 and lines[0] == "PG disabled": | ||
return () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's PG disabled, is it paging? Is it only on one or all archs?
Any chance we can support physical addresses here too? or should we handle it elsewhere?
Is there an alternative to copy-pasting the gdb-pt-dump code, and potentially something I could assist with? If the code becomes duplicated, code maintainability for both projects will suffer:
What would be required from gdb-pt-dump side to have the code live in a single place, but have things bundled for a release? |
Changes:
kernel_vmmap_via_monitor_info_mem
toaglib.kernel.vmmap
kernel_vmmap_via_page_tables
toaglib.kernel.vmmap
kernel_vmmap_via_page_tables
kernel_vmmap_via_page_tables