-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
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
Bypass PagedAllocator/PagedArrayPool by default for ASan build #94906
base: master
Are you sure you want to change the base?
Bypass PagedAllocator/PagedArrayPool by default for ASan build #94906
Conversation
I had ideas about this in the back of my mind and I'm happy there's a PR for it! Thoughts:
|
Looks like it could. Do you want me to do it in the same PR?
Well, poisoning may still catch something and it's not like an expensive operation anyway. It also doesn't interfere with other types of tracking (in theory).
ASan requires a speciality build. Having command line flags that normally doesn't do anything doesn't seem useful. Unless you want to be able to bypass PagedAllocator even on a normal build? Still doesn't seem very useful. The concern is that the option needs to be set before the very first allocation, and must not change during the lifetime of the process. If the allocator is used at all before or when parsing the command line, then using a command line flag wouldn't work (I don't know if this actually happens or not.) |
That'd be great.
No strong opinions here. Just wanted to discuss it a bit. Sounds good to keep it.
Certain CLI arguments we already have are restricted to build types ( All this said, I'd like to hear more opinions. Let's summon @Calinou, for instance. |
Forward allocations to ASan malloc directly so that they can be more effectively tested by ASan. This can be disabled by setting the environment variable `ALLOCATORS_DO_NOT_USE_ASAN_MALLOC=1`. When disabled, PagedAllocator will manually poison unallocated chunks instead. Though this is not very effective in detecting memory errors.
This is less of a straightforward bypass compared to PagedAllocator, because we need to keep track of the allocated memory by its page_id to be able to free the allocation.
c1ed04e
to
0fe14ca
Compare
Forward allocations to ASan malloc directly so that they can be more effectively tested by ASan. This can be disabled by setting the environment variable
ALLOCATORS_DO_NOT_USE_ASAN_MALLOC=1
.When disabled, PagedAllocator will manually poison unallocated chunks instead. Though this is not very effective in detecting memory errors.
This change only affects building with ASan enabled.
PagedAllocator
keeps its own memory pool and hand allocations out by pieces. This prevents ASan from working effectively for allocations handled byPagedAllocator
. Even if it poisons the unallocated chunks, it hinders these checks:PagedAllocator
hands out pieces from contiguous pages without redzones in between pieces, so there is a high chance any overflow or underflow will end up accessing memory of neighbouring pieces which does not trip ASan. (Though there is little reason for code to index into the these allocations, so overflow/underflow normally should not happen for them.)PagedAllocator
does not have a quarantine – in fact it prefers handing out pieces that was most recently freed.PagedAllocator
will have to check this manually.In addition, ASan poisoning/unpoisoning does not keep the stack traces, so if the code does hit an error that poisoning is able to catch, you can only see the backtrace of where the whole page was allocated (which can be anywhere), instead of the more helpful backtraces of where the memory was allocated and freed that ASan can provide.
This had managed to catch a use-after-free: #94832.