-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Asan delays reallocation to increase the likelyhood of catching a UAF. This adds a simple free list allocator that tries to reuse allocations quickly to increase the chance of an ABA problem being detected.
- Loading branch information
Showing
5 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright Microsoft and Project Verona Contributors. | ||
// SPDX-License-Identifier: MIT | ||
|
||
#define USE_REPLAY_ALLOCATOR | ||
|
||
#include <debug/harness.h> | ||
#include <test/opt.h> | ||
|
||
/** | ||
* Tests heap replay functionality with systematic testing. | ||
* | ||
* We count each time alloc returns the value just freed, this should | ||
* be possible, but not guaranteed. | ||
**/ | ||
|
||
size_t count = 0; | ||
|
||
void test_replay() | ||
{ | ||
size_t size = 16; | ||
void* p = heap::alloc(size); | ||
uintptr_t p_addr = (uintptr_t)p; | ||
heap::dealloc(p, size); | ||
|
||
void* p2 = heap::alloc(size); | ||
uintptr_t p2_addr = (uintptr_t)p2; | ||
heap::dealloc(p2, size); | ||
|
||
if (p_addr == p2_addr) | ||
{ | ||
std::cout << "*" << std::flush; | ||
count ++; | ||
} | ||
else | ||
{ | ||
std::cout << "." << std::flush; | ||
} | ||
} | ||
|
||
|
||
int main(int argc, char** argv) | ||
{ | ||
auto t = Aal::tick(); | ||
size_t repeats = 1000; | ||
for (size_t i = 0; i < repeats; i++) | ||
{ | ||
heap::set_seed(i + t); | ||
test_replay(); | ||
heap::debug_check_empty(); | ||
if (i % 64 == 0) | ||
{ | ||
std::cout << std::endl; | ||
} | ||
} | ||
|
||
std::cout << std::endl << "count: " << count << std::endl; | ||
|
||
// We should have at least one replay | ||
check(count != 0); | ||
// We should not have all replays | ||
check(count != repeats); | ||
|
||
return 0; | ||
} |