-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Fix some page size assumptions in the HWASan tests. #134941
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
Merged
pcc
merged 2 commits into
main
from
users/pcc/spr/fix-some-page-size-assumptions-in-the-hwasan-tests
Apr 8, 2025
Merged
Fix some page size assumptions in the HWASan tests. #134941
pcc
merged 2 commits into
main
from
users/pcc/spr/fix-some-page-size-assumptions-in-the-hwasan-tests
Apr 8, 2025
Conversation
This file contains hidden or 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
Created using spr 1.3.6-beta.1
Member
|
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Peter Collingbourne (pcc) ChangesFull diff: https://github.com/llvm/llvm-project/pull/134941.diff 3 Files Affected:
diff --git a/compiler-rt/test/hwasan/TestCases/Linux/release-shadow.c b/compiler-rt/test/hwasan/TestCases/Linux/release-shadow.c
index 705f5e6f433cc..988de511ae1af 100644
--- a/compiler-rt/test/hwasan/TestCases/Linux/release-shadow.c
+++ b/compiler-rt/test/hwasan/TestCases/Linux/release-shadow.c
@@ -7,6 +7,7 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/auxv.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -17,17 +18,17 @@
const unsigned char kTag = 42;
const size_t kNumShadowPages = 1024;
const size_t kNumPages = 16 * kNumShadowPages;
-const size_t kPageSize = 4096;
-const size_t kMapSize = kNumPages * kPageSize;
+
+size_t page_size, map_size;
void sync_rss() {
- char *page = (char *)mmap(0, kPageSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+ char *page = (char *)mmap(0, page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
// Linux kernel updates RSS counters after a set number of page faults.
for (int i = 0; i < 100; ++i) {
page[0] = 42;
- madvise(page, kPageSize, MADV_DONTNEED);
+ madvise(page, page_size, MADV_DONTNEED);
}
- munmap(page, kPageSize);
+ munmap(page, page_size);
}
size_t current_rss() {
@@ -45,9 +46,9 @@ size_t current_rss() {
}
int test_rss_difference(void *p) {
- __hwasan_tag_memory(p, kTag, kMapSize);
+ __hwasan_tag_memory(p, kTag, map_size);
size_t rss_before = current_rss();
- __hwasan_tag_memory(p, 0, kMapSize);
+ __hwasan_tag_memory(p, 0, map_size);
size_t rss_after = current_rss();
fprintf(stderr, "%zu -> %zu\n", rss_before, rss_after);
if (rss_before <= rss_after)
@@ -59,10 +60,13 @@ int test_rss_difference(void *p) {
}
int main() {
+ page_size = getauxval(AT_PAGESZ);
+ map_size = kNumPages * page_size;
+
fprintf(stderr, "starting rss %zu\n", current_rss());
fprintf(stderr, "shadow pages: %zu\n", kNumShadowPages);
- void *p = mmap(0, kMapSize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+ void *p = mmap(0, map_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
fprintf(stderr, "p = %p\n", p);
size_t total_count = 10;
diff --git a/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow.c b/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow.c
index d390017dd7555..a4923fa4071cd 100644
--- a/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow.c
+++ b/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow.c
@@ -47,11 +47,11 @@ int main(int argc, char **argv) {
// CHECKm30: Cause: heap-buffer-overflow
// CHECKm30: is located 30 bytes before a 30-byte region
//
- // CHECKMm30: is a large allocated heap chunk; size: 1003520 offset: -30
+ // CHECKMm30: is a large allocated heap chunk; size: {{[0-9]*}} offset: -30
// CHECKMm30: Cause: heap-buffer-overflow
// CHECKMm30: is located 30 bytes before a 1000000-byte region
//
- // CHECKM: is a large allocated heap chunk; size: 1003520 offset: 1000000
+ // CHECKM: is a large allocated heap chunk; size: {{[0-9]*}} offset: 1000000
// CHECKM: Cause: heap-buffer-overflow
// CHECKM: is located 0 bytes after a 1000000-byte region
//
diff --git a/compiler-rt/test/hwasan/TestCases/tag-mismatch-border-address.c b/compiler-rt/test/hwasan/TestCases/tag-mismatch-border-address.c
index bffb8a0dfb042..a9fd7d66d8c10 100644
--- a/compiler-rt/test/hwasan/TestCases/tag-mismatch-border-address.c
+++ b/compiler-rt/test/hwasan/TestCases/tag-mismatch-border-address.c
@@ -7,14 +7,16 @@
#include <sanitizer/hwasan_interface.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/auxv.h>
#include <sys/mman.h>
static volatile char sink;
extern void *__hwasan_shadow_memory_dynamic_address;
int main(int argc, char **argv) {
- void *high_addr = (char *)__hwasan_shadow_memory_dynamic_address - 0x1000;
- void *r = mmap(high_addr, 4096, PROT_READ, MAP_FIXED | MAP_ANON | MAP_PRIVATE,
+ size_t page_size = getauxval(AT_PAGESZ);
+ void *high_addr = (char *)__hwasan_shadow_memory_dynamic_address - page_size;
+ void *r = mmap(high_addr, page_size, PROT_READ, MAP_FIXED | MAP_ANON | MAP_PRIVATE,
-1, 0);
if (r == MAP_FAILED) {
fprintf(stderr, "Failed to mmap\n");
|
vitalybuka
reviewed
Apr 8, 2025
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
fmayer
approved these changes
Apr 8, 2025
vitalybuka
approved these changes
Apr 8, 2025
Contributor
|
Please fix formatting. |
Contributor
Author
Done |
llvm-sync bot
pushed a commit
to arm/arm-toolchain
that referenced
this pull request
Apr 8, 2025
Reviewers: fmayer, vitalybuka Reviewed By: fmayer, vitalybuka Pull Request: llvm/llvm-project#134941
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.