-
-
Notifications
You must be signed in to change notification settings - Fork 741
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
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
)
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. |
Checking in: Let me know if you'd like any more work on this PR. |
Hi @gordonmessmer ! I haven't forgotten, but I cannot easily review/test your PR. |
NP. I just like to check in on open PRs every week or two to make sure that I know if someone is waiting on me. :) |
Could you come up with step to repro the issue so that I can test it? Let's get this merged :) |
The shortest reproduction case is probably simply: In one terminal, run In a second terminal, run You'll see the error:
That's because the Section.realpath property is broken, and attempts to use |
Interestingly, while trying to repro I couldn't get even the format string error. I was sourcing an old work tree, but that means that this is some sort of regression. On main I can repro and on your branch things mostly look good, but I only get output for the binary e.g. the same output as when I don't use |
If you don't get any additional libraries, then most likely the paths provided by gdbserver do not match the canonical path for some reason other than a /usr prefix. Looking at this again, I see that the suffix is also likely to be not canonical due to minor-version sonames, so I'll have to add more code to prune numeric suffixes during the realpath search. On your system, take a look at /proc/pid/maps for the process you're debugging, and compare the paths that appear in that file to the paths that appear in the gdb session remote root to see if your system has issues other than symlinks to I'll send another patch asap, but if you see something not covered yet, we'd need to expand the search function further. |
I am testing with a local gdb server so shouldn’t they match?
…On Mon, Jul 22, 2024 at 9:12 PM Gordon Messmer ***@***.***> wrote:
If you don't get any additional libraries, then most likely the paths
provided by gdbserver do not match the canonical path for some reason other
than a /usr prefix.
Looking at this again, I see that the suffix is *also* likely to be not
canonical due to minor-version sonames, so I'll have to add more code to
prune numeric suffixes during the realpath search.
On your system, take a look at /proc/pid/maps for the process you're
debugging, and compare the paths that appear in that file to the paths that
appear in the gdb session remote root to see if your system has issues
other than symlinks to /usr/lib* or the numeric suffixes.
I'll send another patch asap, but if you see something not covered yet,
we'd need to expand the search function further.
—
Reply to this email directly, view it on GitHub
<#1109 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADZNHQW2L3IG7SMVZCTYX3ZNWUXPAVCNFSM6AAAAABIN74GRKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBUGA3DONJWGM>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Paths will often not match due to the bug we discussed in #1101 (comment) |
Thanks. I’ll take a look and try to debug when I’m at a computer.
…On Mon, Jul 22, 2024 at 11:06 PM Gordon Messmer ***@***.***> wrote:
Paths will often not match due to the bug we discussed in #1101 (comment)
<#1101 (comment)>
—
Reply to this email directly, view it on GitHub
<#1109 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADZNHS6TTZNPJU7DLWWGNTZNXCDJAVCNFSM6AAAAABIN74GRKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBUGE3DENBVGI>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
I've added another function which should improve the realpath search success rate. I'd like to believe that this is good enough for now, fixing the vast majority of cases. It's definitely significantly better than the status quo. If more symlinks are identified in the future that the realpath search should test, the function can always be expanded. |
Part of my issue was that I was testing on It's looking good now! |
071fa4b
to
9ee31c4
Compare
Any way this is related to #1070 that went stale? The library loading part is what makes me think so. |
Yes and no. Yes: If the issue that 1070 was intended to fix were fixed, then the tests introduced by this PR would (I think) operate identically on Ubuntu 20.04 and 22.04. And if that happened, then the tests could require that some library realpath was fixed in a remote session. That would be an improvement. And it's possible that this PR will not improve the status quo on Ubuntu 20.04 because the maps file is simply out of date and doesn't refresh. But otherwise, no. There's minimal relation between the two PRs. Neither PR is a substitute for the other. |
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.
Tests are green all across, so LGTM. Just a few minor code quality comments
Thank you for the review. Feedback should be addressed in the new commit. |
Sweet, I'll merge right after then! Thanks @gordonmessmer |
Sorry, I meant 6e5a96d |
All merged, great work again @gordonmessmer 🎉 |
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