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

Memory safety issue in frida fuzzer breaks Windows CI #1383

Closed
Mrmaxmeier opened this issue Jul 28, 2023 · 5 comments · Fixed by #1385
Closed

Memory safety issue in frida fuzzer breaks Windows CI #1383

Mrmaxmeier opened this issue Jul 28, 2023 · 5 comments · Fixed by #1385
Labels
bug Something isn't working

Comments

@Mrmaxmeier
Copy link
Contributor

Windows CI is sad at the moment. I tried investigating and found a gnarly UB issue in the frida fuzzer:

Due to an unsound API in frida-gum (frida/frida-rust#102), this callback references a dangling stack object (helper):

let transformer = Transformer::from_callback(gum, |basic_block, output| {

Unfortunately this is not trivial to fix, as helper is returned (and thus moved) later as part of the FridaInstrumentationHelper::new API.

It seems like this was noticed previously (#992), but it is still an issue.

@Mrmaxmeier Mrmaxmeier added the bug Something isn't working label Jul 28, 2023
@tokatoka
Copy link
Member

thanks for the investigation

do you think this is related? i feel it is.
#1053

here i tried to make FridaInstrumentationHelper return Result<>, but it simply doesn't work (which is suprising)

@Mrmaxmeier
Copy link
Contributor Author

Mrmaxmeier commented Jul 28, 2023

Using a Result<> instead wouldn't fix the underlying issue. The closure passed to Transformer::from_callback needs to move || its context (currently it's not moving but referencing it). In order to do so the helper object would need be refactored into something that's reference-counted because we need to move it both into the closure context and return it from the Helper::new function.

@tokatoka
Copy link
Member

Yeah i know. I mean Making it return Result<> simply make the entire frida_fuzzer break, which makes no sense.
So I guess the root cause of my issue is the same as yours.

@domenukk
Copy link
Member

Any chance you can open a PR for that against frida @Mrmaxmeier ? I'd be more than happy to get frida fixed at some point :D

@Mrmaxmeier
Copy link
Contributor Author

So I guess the root cause of my issue is the same as yours.

Yes, wrapping the Helper in a Result probably changed the layout on the stack, which messes up the dangling reference in the callback closure. It still feels a bit like a miracle though that the code has ever worked correctly. 🙃

Any chance you can open a PR for that against frida?

I've opened frida/frida-rust#103, but the PR is not required to fix the issue on LibAFL's side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants