frida / frida-rust

Frida Rust bindings
Other
176 stars 46 forks source link

frida-gum API allows some memory safety mistakes #98

Open lf- opened 1 year ago

lf- commented 1 year ago

Hi! Thank you so much for your work on this library, it seems to be among the highest quality hook implementations available in Rust and this is awesome.

I'm integrating frida_gum into a new project and I found some foot guns. I am not sure if I am going to get around to submitting patches, but I am writing these down for the sake of writing them down. Fixing these is going to need to break API.

I realize that this library exists to do wildly unsafe things, and indeed I intend to do wildly unsafe things with it, but I think that in the business of doing wildly unsafe things, cats can have little a compile-time enforced safety as a treat.

This is a brief list of the things I found while lightly auditing the library to learn how to use it:

s1341 commented 1 year ago

Wow. Thanks for the audit. I think your suggestions are excellent. I’d be happy to see PRs for them. Any chance you will get to it?

meme commented 1 year ago

Hi, I'm glad you have been finding the library helpful.

Module::enumerate_modules() segfaults if you don't initialize Gum but is marked safe.

I agree, this should be addressed by passing a Gum. There are possibly other APIs that don't respect this either that should be fixed.

The Gum destructor deinitializes the Gum library, which should be documented

With the stabilization of OnceCell I was considering rewriting all of the examples we have to use that instead of lazy_static, and in the process fixing issues of this kind.

I think I'd rather change the behaviour to keep Drop for Gum to deinitialize Frida, and instead make multiple uses of obtain invalid (failing with an assertion, and documenting this behaviour). Let me know what you think.

The Interceptor transaction system should probably use a guard object to automatically end the transaction when it falls out of scope

Agreed.

Thanks for the helpful suggestions. Patches are welcome, otherwise one of us will get to it whenever possible.