[compiler-rt] f1a4718 - [hwasan] Remove untagging of kernel-consumed memory

Mitch Phillips via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 23 11:05:02 PDT 2021


Author: Mitch Phillips
Date: 2021-04-23T11:04:36-07:00
New Revision: f1a47181f5c6b3d5ef4040ab889c3aa0cfdae297

URL: https://github.com/llvm/llvm-project/commit/f1a47181f5c6b3d5ef4040ab889c3aa0cfdae297
DIFF: https://github.com/llvm/llvm-project/commit/f1a47181f5c6b3d5ef4040ab889c3aa0cfdae297.diff

LOG: [hwasan] Remove untagging of kernel-consumed memory

Now that page aliasing for x64 has landed, we don't need to worry about
passing tagged pointers to libc, and thus D98875 removed it.
Unfortunately, we still test on aarch64 devices that don't have the
kernel tagged address ABI (https://reviews.llvm.org/D98875#2649269).

All the memory that we pass to the kernel in these tests is from global
variables. Instead of having architecture-specific untagging mechanisms
for this memory, let's just not tag the globals.

Reviewed By: eugenis, morehouse

Differential Revision: https://reviews.llvm.org/D101121

Added: 
    

Modified: 
    compiler-rt/test/hwasan/TestCases/Linux/decorate-proc-maps.c
    compiler-rt/test/hwasan/TestCases/Linux/release-shadow.c
    compiler-rt/test/hwasan/TestCases/Linux/reuse-threads.cpp

Removed: 
    compiler-rt/test/hwasan/TestCases/Linux/utils.h


################################################################################
diff  --git a/compiler-rt/test/hwasan/TestCases/Linux/decorate-proc-maps.c b/compiler-rt/test/hwasan/TestCases/Linux/decorate-proc-maps.c
index 26babb1addc56..4657dd000336c 100644
--- a/compiler-rt/test/hwasan/TestCases/Linux/decorate-proc-maps.c
+++ b/compiler-rt/test/hwasan/TestCases/Linux/decorate-proc-maps.c
@@ -1,4 +1,4 @@
-// RUN: %clang_hwasan -g %s -o %t
+// RUN: %clang_hwasan -mllvm -hwasan-globals=0  -g %s -o %t
 // RUN: %env_hwasan_opts=decorate_proc_maps=1 %run %t 2>&1 | FileCheck %s --check-prefix=A
 // RUN: %env_hwasan_opts=decorate_proc_maps=1 %run %t 2>&1 | FileCheck %s --check-prefix=B
 
@@ -16,21 +16,18 @@
 #include <fcntl.h>
 #include <pthread.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include <pthread.h>
-#include <stdlib.h>
-
-#include "utils.h"
 
 void CopyFdToFd(int in_fd, int out_fd) {
   const size_t kBufSize = 0x10000;
   static char buf[kBufSize];
   while (1) {
-    ssize_t got = read(in_fd, UNTAG(buf), kBufSize);
+    ssize_t got = read(in_fd, buf, kBufSize);
     if (got > 0) {
-      write(out_fd, UNTAG(buf), got);
+      write(out_fd, buf, got);
     } else if (got == 0) {
       break;
     } else if (errno != EAGAIN || errno != EWOULDBLOCK || errno != EINTR) {
@@ -42,7 +39,7 @@ void CopyFdToFd(int in_fd, int out_fd) {
 
 void *ThreadFn(void *arg) {
   (void)arg;
-  int fd = open(UNTAG("/proc/self/maps"), O_RDONLY);
+  int fd = open("/proc/self/maps", O_RDONLY);
   CopyFdToFd(fd, 2);
   close(fd);
   return NULL;

diff  --git a/compiler-rt/test/hwasan/TestCases/Linux/release-shadow.c b/compiler-rt/test/hwasan/TestCases/Linux/release-shadow.c
index 948bacb7090d7..bceb37d8f4f16 100644
--- a/compiler-rt/test/hwasan/TestCases/Linux/release-shadow.c
+++ b/compiler-rt/test/hwasan/TestCases/Linux/release-shadow.c
@@ -1,5 +1,5 @@
 // Test that tagging a large region to 0 reduces RSS.
-// RUN: %clang_hwasan -mllvm -hwasan-instrument-stack=0 %s -o %t && %run %t 2>&1
+// RUN: %clang_hwasan -mllvm -hwasan-globals=0 -mllvm -hwasan-instrument-stack=0 %s -o %t && %run %t 2>&1
 
 #include <assert.h>
 #include <fcntl.h>
@@ -12,8 +12,6 @@
 
 #include <sanitizer/hwasan_interface.h>
 
-#include "utils.h"
-
 const unsigned char kTag = 42;
 const size_t kNumShadowPages = 256;
 const size_t kNumPages = 16 * kNumShadowPages;
@@ -32,7 +30,7 @@ void sync_rss() {
 
 size_t current_rss() {
   sync_rss();
-  int statm_fd = open(UNTAG("/proc/self/statm"), O_RDONLY);
+  int statm_fd = open("/proc/self/statm", O_RDONLY);
   assert(statm_fd >= 0);
 
   char buf[100];

diff  --git a/compiler-rt/test/hwasan/TestCases/Linux/reuse-threads.cpp b/compiler-rt/test/hwasan/TestCases/Linux/reuse-threads.cpp
index 865b7b2a7097c..cb77e93e15f32 100644
--- a/compiler-rt/test/hwasan/TestCases/Linux/reuse-threads.cpp
+++ b/compiler-rt/test/hwasan/TestCases/Linux/reuse-threads.cpp
@@ -1,5 +1,5 @@
 // Test that Thread objects are reused.
-// RUN: %clangxx_hwasan -mllvm -hwasan-instrument-stack=0 %s -o %t && %env_hwasan_opts=verbose_threads=1 %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_hwasan -mllvm -hwasan-globals=0 -mllvm -hwasan-instrument-stack=0 %s -o %t && %env_hwasan_opts=verbose_threads=1 %run %t 2>&1 | FileCheck %s
 
 #include <assert.h>
 #include <fcntl.h>
@@ -10,12 +10,10 @@
 
 #include <sanitizer/hwasan_interface.h>
 
-#include "utils.h"
-
 pthread_barrier_t bar;
 
 void *threadfn(void *) {
-  pthread_barrier_wait(UNTAG(&bar));
+  pthread_barrier_wait(&bar);
   return nullptr;
 }
 
@@ -23,15 +21,15 @@ void start_stop_threads() {
   constexpr int N = 2;
   pthread_t threads[N];
 
-  pthread_barrier_init(UNTAG(&bar), nullptr, N + 1);
+  pthread_barrier_init(&bar, nullptr, N + 1);
   for (auto &t : threads)
     pthread_create(&t, nullptr, threadfn, nullptr);
 
-  pthread_barrier_wait(UNTAG(&bar));
+  pthread_barrier_wait(&bar);
 
   for (auto &t : threads)
     pthread_join(t, nullptr);
-  pthread_barrier_destroy(UNTAG(&bar));
+  pthread_barrier_destroy(&bar);
 }
 
 int main() {

diff  --git a/compiler-rt/test/hwasan/TestCases/Linux/utils.h b/compiler-rt/test/hwasan/TestCases/Linux/utils.h
deleted file mode 100644
index 46ece2df5b48e..0000000000000
--- a/compiler-rt/test/hwasan/TestCases/Linux/utils.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#pragma once
-
-#include <stdint.h>
-
-#if defined(__x86_64__)
-#define UNTAG(x) (x)
-#else
-#define UNTAG(x) (typeof((x) + 0))(((uintptr_t)(x)) & 0xffffffffffffff)
-#endif


        


More information about the llvm-commits mailing list