-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hwasan] Fixing false invalid-free with disabled tagging (#67169)
This problem was accidentally discovered by the internal symbolizer, but it's relevant for external one as well, see the test. If we just disable tagging, there may still be tagged allocations that have already been freed. After disabling tagging, these tagged allocations can be released to the user as-is, which would later break the "invalid-free" check. We cannot just disable the "invalid-free" check with disabled tagging, because if we re-enable tagging, the issue still applies to allocations created when it was disabled. The fix is to continue tagging with zero even if tagging is disabled. This makes the "disabled" mode less efficient, but this is not the primary use case.
- Loading branch information
1 parent
7ca8c21
commit 43aa6e6
Showing
2 changed files
with
57 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Test that disabling/enabling tagging does not trigger false reports on | ||
// allocations happened in a different state. | ||
|
||
// RUN: %clang_hwasan -O1 %s -o %t && %run %t 2>&1 | ||
|
||
#include <assert.h> | ||
#include <sanitizer/hwasan_interface.h> | ||
#include <stdlib.h> | ||
|
||
enum { | ||
COUNT = 5, | ||
SZ = 10, | ||
}; | ||
void *x[COUNT]; | ||
|
||
int main() { | ||
__hwasan_enable_allocator_tagging(); | ||
for (unsigned i = 0; i < COUNT; ++i) { | ||
x[i] = malloc(SZ); | ||
assert(__hwasan_test_shadow(x[i], SZ) == -1); | ||
} | ||
for (unsigned i = 0; i < COUNT; ++i) | ||
free(x[i]); | ||
|
||
__hwasan_disable_allocator_tagging(); | ||
for (unsigned i = 0; i < COUNT; ++i) { | ||
x[i] = malloc(SZ); | ||
assert(__hwasan_tag_pointer(x[i], 0) == x[i]); | ||
assert(__hwasan_test_shadow(x[i], SZ) == -1); | ||
} | ||
for (unsigned i = 0; i < COUNT; ++i) | ||
free(x[i]); | ||
|
||
__hwasan_enable_allocator_tagging(); | ||
for (unsigned i = 0; i < COUNT; ++i) { | ||
x[i] = malloc(SZ); | ||
assert(__hwasan_test_shadow(x[i], SZ) == -1); | ||
} | ||
for (unsigned i = 0; i < COUNT; ++i) | ||
free(x[i]); | ||
return 0; | ||
} |