I recently found an use-after-free in opentelemetry-zig that flew under the radar because DebugAllocator has no way to poison unused memory slots. The bug in question triggered reliably when switching to a page_allocator since it immediately unmaps pages associated to an allocation upon freeing.
I found this somewhat unintuitive as I needed to switch away from DebugAllocator to find the bug. Does it make sense to modify the DebugAllocator in order to catch this type of issues?
If so, there are 2 ways I see this could be done:
- Add a configuration that causes
DebugAllocator to behave similarly to page_allocator
- Annotate memory regions as unreachable using the APIs in
std.valgrind.memcheck. This is less intrusive but only works when running the program under valgrind
It's also worth noting that address sanitizer has an API to poison arbitrary memory regions with a granularity of 8 bytes, but I'm assuming that would be much more involved.
Cheers!
I recently found an use-after-free in [opentelemetry-zig](https://github.com/open-telemetry/opentelemetry-zig/issues/29) that flew under the radar because `DebugAllocator` has no way to poison unused memory slots. The bug in question triggered reliably when switching to a `page_allocator` since it immediately unmaps pages associated to an allocation upon freeing.
I found this somewhat unintuitive as I needed to switch away from `DebugAllocator` to find the bug. Does it make sense to modify the `DebugAllocator` in order to catch this type of issues?
If so, there are 2 ways I see this could be done:
1. Add a configuration that causes `DebugAllocator` to behave similarly to `page_allocator`
2. Annotate memory regions as unreachable using the APIs in `std.valgrind.memcheck`. This is less intrusive but only works when running the program under valgrind
It's also worth noting that address sanitizer has an API to poison arbitrary memory regions with a granularity of 8 bytes, but I'm assuming that would be much more involved.
Cheers!