-
-
Notifications
You must be signed in to change notification settings - Fork 716
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
Fix remote use of gef.memory.maps #1109
base: main
Are you sure you want to change the base?
Conversation
One way to make this commit a little nicer would be to add an interface that both Sections and the GefSessionManager.file property could implement, each providing both a display path (.path) and a local path (.realpath) attribute/property. |
5c68a97
to
2e6166f
Compare
I've rebased this commit on the new main branch. Currently, this patch allows the It could be merged as-is. If you have any suggestions on making it better fit the code style of the project, I can work on those. I could also look for a way to print a warning for files that can't be found (which will probably always be non-canonical paths). At a stretch, I could even try to add some simple searches for likely alternate paths when the realpath isn't present. |
No problem. Cheers |
I added a patch that performs one permutation to find paths that aren't found at the expected path. With that patch, remote debugging against a Red Hat system provides the full expected output for |
(I did not remove the note about the bug from the got documentation, because shared objects that are not found due to other symlinks could still result in their absence from the output.) |
Another way to make this implementation less messy would be to always use maps, rather than using maps for I don't have strong feelings about patch 3, but it's an option. I could squash that and the first, or drop it. |
"you can also assign me for review so I get a notification" @hugsy as a non-project member, I don't think I can. 😆 |
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.
It would be nice to add a test case on this function specifically (i.e. search_for_realpath
)
|
||
remote_path = pathlib.Path(self.path) | ||
# First, try the canonical path in the remote session root. | ||
candidate1 = gef.session.remote.root / remote_path.relative_to(remote_path.anchor) |
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.
you need to check if the session is remote before using gef.session.remote
otherwise, it will throw an exception
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.
Right now, search_for_realpath() is only called after checking if the session is remote (line 718). Would you like an assert here?
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.
(Or just mark the function private, so that it doesn't gain new users which haven't already checked gef.session.remote?)
So I think the outstanding work is test for search_for_realpath, and make that function private (and assert gef.session.remote). If I resolved anything by mistake, please let me know. |
I'll have to think about this some more... The test currently checked in succeeds on ubuntu 22.04, but not 20.04. I could just not assert that a lib in /usr was found, but that opens the possibility of some future test platform not exhibiting this behavior, and the test doing nothing at all. |
What's important to you in these tests? Both Debian and Fedora family systems have the same issue that I originally noticed with remote debugging: /lib and /lib64 are symlinks into /usr, and the files retrieved by gdb haven't been resolved by realpath(), so they don't match the paths indicated in /proc/pid/maps. That makes testing easier, because I don't need to introduce tests on a different platform, nor to I need to modify the local tmp root to reproduce the issue. But Debian also makes ld.so a symlink, and that makes testing on Debian(/Ubuntu) very difficult, because fixing up that path isn't simple and predictable the way that fixing the /usr symlinks is, so remote binaries on Debian systems always have a map that's missing, which looks like a failure in the realpath property of map sections. On both Ubuntu 20.04 and 22.04, the maps file will contain only the binary executable, ld.so, and virtual objects, typically. But if I add I think the right way to do test the realpath property would be an isolated unit test, not a functional test, but gef isn't designed to be imported for unit testing. These tests pass, but only because on Ubuntu 20.04 they don't do anything. |
Description
This change passes both the "display" path and the local "real" path for each section or file to the print_got_for function in GotCommand. Without this change, the
got
command does not work properly in a remote debugging session.Checklist