Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hwasan] Always untag short granule in shadow.
Fixes a regression when the allocator is disabled, and a dirty allocation is re-used. This only occurs when the allocator is disabled, so a test-only fix, but still necessary. Reviewed By: eugenis Differential Revision: https://reviews.llvm.org/D108650
- Loading branch information
Showing
2 changed files
with
26 additions
and
2 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
21 changes: 21 additions & 0 deletions
21
compiler-rt/test/hwasan/TestCases/short-granule-disabled.cpp
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,21 @@ | ||
// RUN: %clangxx_hwasan %s -o %t && %run %t 2>&1 | ||
|
||
#include <sanitizer/hwasan_interface.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
// Regression test for https://reviews.llvm.org/D107938#2961070, where, on | ||
// reusing an allocation, we forgot to reset the short granule tag if the | ||
// allocator was disabled. This lead to a false positive magic-string mismatch. | ||
|
||
int main() { | ||
void *p = malloc(16); | ||
memset(p, 0xff, 16); | ||
free(p); | ||
|
||
// Relies on the LRU cache immediately recycling the allocation above. | ||
p = malloc(8); | ||
free(p); // Regression was here, in the magic-string check in the runtime. | ||
return 0; | ||
} |