-
-
Notifications
You must be signed in to change notification settings - Fork 368
librasan: Use musl implementations of some libc functions #3175
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
Conversation
I've also added a LibAFL/utils/libafl_repo_tools/src/main.rs Lines 296 to 307 in 9771891
|
Nice. Looks good. |
Thanks! Why put the libc stuff in a |
To be fair to @wfdewith the folder was already there in the original implementation, he just added some files in there. I don't have any problem with it being renamed though. |
I prefer libc as the name as well, and it better documents the purpose of the included C code. |
I double checked whether the optimized C implementations don't suffer from buffer overreads similarly to the assembly implementions, as mentioned above.
Luckily, the optimized part of |
The asan library itself is excluded when injecting TCG to check for overruns. Therefore such benign over-reads from load widening shouldn't be any issue here. |
I know this is the case for |
I've not tried librasan with system mode, I only designed it for use with user mode qemu. I guess the modular nature might mean that parts can be re-used? Maybe just add a comment warning of the potential problem of load widening and keep the current optimised implementation? Then if it is integrated with system mode later, it should be easy to detect and fix? |
I don't understand, I thought the difference between Also keep in mind that this |
Ah gotcha. Sorry got confused by the naming. I think AsanModule (qemu-user but with the shadow maps in the host) should also exclude the DSO from instrumentation. qemu_launcher also supports configuration of excluded ranges via command line options. That should also work for both guest and host modes. That's not to say that is what it does though. |
Yeah, it's just not excluded in LibAFL/libafl_qemu/src/modules/usermode/asan.rs Lines 1162 to 1181 in 62d9485
But it is in LibAFL/libafl_qemu/src/modules/usermode/asan_guest.rs Lines 118 to 126 in 62d9485
I really can't think of a reason why it shouldn't be handled exactly the same in both modules. Should I open a PR for that? I guess that if load widening isn't a problem, I could also include the handwritten optimized assembly implementations from musl, because why would we leave performance on the table. |
Yeah. Please PR that. No reason not to have the optimised versions i guess. I'd be inclined to put them behind a feature (that's enabled by default) just in case they do cause some problems so integrations can opt out. |
By the way, you should be able to profile your target running in the "runner" (included with librasan) to find any more potential areas for improvement. I used samply along with the Firefox-profiler. |
Actually, thinking about it, I don't think this is the first time I've had to implement |
I was actually thinking about whether it is possible to compile the librasan crates with Rust's We'd need to do some linker tricks to avoid linking |
The only issue I can see is availability of rust target support for musl. What can be done for target architectures where there is no musl rust target? |
Can |
Also it could cause problems when using it on bare metal systems. |
Good point, actually, I assumed this was more supported than it actually is. Looking at Platform Support, the following targets exist in Tier 2:
So this would already be a problem for PowerPC as it stands, because PowerPC 64 LE is not the same as PowerPC. There is Tier 3 support for PowerPC (and PowerPC 64) with musl and for a couple other architectures with musl as well, but those require building your own
Not really, there is no existing crate for this because it is normally bundled with the standard library anyway. Setting up a build environment for creating such a crate would be pretty complex and that time would probably be better spent just compiling the Tier 3 targets and getting them working.
I wouldn't expect trouble, since we're compiling the whole thing with Anyway, it seems that this idea is dead on arrival because of PowerPC, so let's disregard it for now and just use the few select functions from musl.
Maybe, but I prefer leaving that to you because you have a better idea of what you need. So, my current plan is as follows:
|
Sounds good. Only thing I'd add is putting the assembly implementations behind a default enabled feature in case there's issues with them on exotic targets. |
How does this look? https://crates.io/crates/nostd-musl |
I realized that the Rust compiler already can almost do what we're trying to achieve when it compiles for freestanding targets. For that purpose,
Long story short, the current idea, and as such your crate, seems to be the best fit for this project. Should this PR be ported to that crate? |
I think so, but worth seeing what the rest of the maintainers think. |
Sounds good to me |
Great thanks. Happy to give anyone else privs for the repo or crates.io BTW. Or even move the repo into AFLplusplus org if you'd rather. Just didn't want to necessarily tie the release schedule of the crate to that of libafl. |
Whatever you like best :) |
Ok. I'll leave it as is for now then if nobody feels strongly either way. |
Ok this should be good to supersede this commit now. #3188. Happy if you want to spin up a new PR to integrate calls into the new |
Description
As discussed in #3173, this PR replaces all
libc
functions required to compile librasan with their implementations from musl. This also fixes the unaligned memory access inmemset
that #3173 was intended to fix.Musl does offer handwritten optimized versions in assembly for some of these functions for some architectures, but these implementations might overread buffers, which would trip up the address sanitizer on its own code. I have no interest at the moment to manually verify and tweak the assembly code (and test those adjustments thoroughly!), so I'm leaving them out for now.
Checklist
./scripts/precommit.sh
and addressed all comments