[compiler-rt] [HWASan] Delete the print-memory-usage-android.c test (PR #66550)

Mitch Phillips via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 15 14:22:55 PDT 2023


https://github.com/hctim created https://github.com/llvm/llvm-project/pull/66550

This test asserts that HWASan memory usage can be gathered from
/proc/$PID/maps. This worked because the old Android-specific versions
of the anonymous mmap patches functioned by providing a userland cstring
pointer to the kernel, and the underlying cstring was collected from
that pointer address dynamically when /proc/$PID/maps was being
decorated. This had some obvious flaws, you had to keep the string
around for the lifetime of the program.

Now, the official kernel implementation of this is to copy the string
into a kernel struct at prctl()-time. Thus, the name that you give at
prctl()-time sticks around and can't be changed by userspace outside of
another prctl call. This breaks the feature, but this is fine, it's not
like anyone's really relying on it anyway. So, let's make sure we don't
continue failing the test on new versions of Android where the kernel
has the upstream version of the named-anonymous-mappings work.


>From c906a018ad19acb6bff9984ffd401811700c137d Mon Sep 17 00:00:00 2001
From: Mitch Phillips <mitchp at google.com>
Date: Fri, 15 Sep 2023 23:05:59 +0200
Subject: [PATCH] [HWASan] Delete the print-memory-usage-android.c test

This test asserts that HWASan memory usage can be gathered from
/proc/$PID/maps. This worked because the old Android-specific versions
of the anonymous mmap patches functioned by providing a userland cstring
pointer to the kernel, and the underlying cstring was collected from
that pointer address dynamically when /proc/$PID/maps was being
decorated. This had some obvious flaws, you had to keep the string
around for the lifetime of the program.

Now, the official kernel implementation of this is to copy the string
into a kernel struct at prctl()-time. Thus, the name that you give at
prctl()-time sticks around and can't be changed by userspace outside of
another prctl call. This breaks the feature, but this is fine, it's not
like anyone's really relying on it anyway. So, let's make sure we don't
continue failing the test on new versions of Android where the kernel
has the upstream version of the named-anonymous-mappings work.
---
 .../TestCases/print-memory-usage-android.c    | 21 -------------------
 1 file changed, 21 deletions(-)
 delete mode 100644 compiler-rt/test/hwasan/TestCases/print-memory-usage-android.c

diff --git a/compiler-rt/test/hwasan/TestCases/print-memory-usage-android.c b/compiler-rt/test/hwasan/TestCases/print-memory-usage-android.c
deleted file mode 100644
index 5a057928ba7521c..000000000000000
--- a/compiler-rt/test/hwasan/TestCases/print-memory-usage-android.c
+++ /dev/null
@@ -1,21 +0,0 @@
-// Tests __hwasan_print_memory_usage through /proc/$PID/maps.
-// RUN: %clang_hwasan %s -o %t && %env_hwasan_opts=export_memory_stats=1 %run %t 2>&1 | FileCheck %s
-// REQUIRES: android
-
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-// The function needs to be unsanitized in order for &cmd to be untagged. This
-// address is passed to system() and then to execve() syscall. The tests need to
-// run on unpatched linux kernel, which at this time does not accept tagged
-// pointers in system call arguments (but there is hope: see
-// https://lore.kernel.org/patchwork/cover/979328).
-__attribute__((no_sanitize("hwaddress")))
-int main() {
-  char cmd[1024];
-  snprintf(cmd, sizeof(cmd), "cat /proc/%d/maps", getpid());
-  system(cmd);
-  // CHECK: HWASAN pid: [[PID:[0-9]*]] rss: {{.*}} threads: 1 stacks: [[STACKS:[0-9]*]] thr_aux: {{.*}} stack_depot: {{.*}} uniq_stacks: [[UNIQ_STACKS:[0-9]*]] heap: [[HEAP:[0-9]*]]
-}



More information about the llvm-commits mailing list