Skip to content
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

QEMUTracerAnalyzer Improvements #99

Merged
merged 8 commits into from
Oct 9, 2021

Conversation

trentn
Copy link
Contributor

@trentn trentn commented Oct 5, 2021

I've made some improvements/modifications to the QEMUTracerAnalyzer to support some projects. These changes seemed worth submitting as a PR.

Most notably I've added strace log parsing to the QEMUTracerAnalyzer as there can be useful information gleaned from tracking various syscalls. I didn't find a parser simple enough to more easily integrate, and the information I wanted to track called for a complex enough regex system that building a simple parser was actually easier to do and understand

The main capability I've built using the strace parser is to track file mappings made using the mmap syscall. This required parsing multiple syscalls (hence the strace parser) to track filenames and open/closed file descriptors to obtain the correct mappings.
I am using this to feed the exact addresses used by shared libraries back into angr to help sort out address synchronization issues.

I also record the image base address as opposed to just the executable segment address for the same reason.

And to get the address used by QEMU for the runtime linker I am recording the entry point from the QEMU logs.

Trent Novelly added 3 commits October 5, 2021 13:51
Add strace parsing capability
	Enables the strace logging capability in QEMU
	Filters and parses the strace entries into python objects

Record file mappings (uses the strace parsing capability)
	Tracks filenames to open file descriptors through the open/close syscalls
	Records the memory mappings for those files through the mmap syscalls

Some additional smaller changes:
	Record the image base directly, parsed from the QEMU page dump

	Record the entry point used by QEMU
	The entry point for a binary which is not always the same address as what is extracted from the ELF
	For example in dynamically linked binary, the entry point logged by QEMU is from the runtime linker
@trentn trentn marked this pull request as ready for review October 5, 2021 22:48
@rhelmot
Copy link
Member

rhelmot commented Oct 6, 2021

This is excellent! Can you write a testcase for this? I'd love to merge this as soon as I have some sort of guarantee it won't just break in the future.

@trentn
Copy link
Contributor Author

trentn commented Oct 6, 2021

Sure thing! I can do that.

Trent Novelly added 2 commits October 7, 2021 10:47
add new tests for new strace capabilities
    tests the file mapping capability since the strace data isn't exposed directly
    new docker build with small program to test file mapping
    mapped_file is just some random data

also add asserts for new trace properties (image_base and entry_point)
@trentn
Copy link
Contributor Author

trentn commented Oct 7, 2021

I've added two tests for the file mapping recording - one for the DockerTarget and one for the LocalTarget
Both pass on my development VM, but the LocalTarget version is what's causing all the tests to fail in the Github checks.

I'm not sure how to debug what's going on, or if I should just remove the LocalTarget version (since it's just calling the same internal function as the DockerTarget version)

I've also added a couple of assertions to an existing test for the other new properties I've added to the QemuTraceResult class.

@trentn
Copy link
Contributor Author

trentn commented Oct 8, 2021

Eh... I was able to replicate the issue locally. I'll see if I can sort out the necessary paths for both Targets to work.

@trentn
Copy link
Contributor Author

trentn commented Oct 8, 2021

Alrighty, I've got the tests working. Looks like the remaining failures are related to the QTraceAnalyzer.

@rhelmot rhelmot merged commit 8c39294 into angr:master Oct 9, 2021
@rhelmot
Copy link
Member

rhelmot commented Oct 9, 2021

Thanks! I'll see about fixing the remaining CI failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants