[PATCH] D68794: libhwasan initialisation include kernel syscall ABI relaxation
Matthew Malcomson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 10 08:33:04 PDT 2019
mmalcomson created this revision.
mmalcomson added reviewers: eugenis, kcc, pcc.
mmalcomson added a project: Sanitizers.
Herald added subscribers: llvm-commits, Sanitizers, kristof.beyls, srhines.
Herald added a project: LLVM.
Until now AArch64 development has been on patched kernels that have an always
on relaxed syscall ABI where tagged pointers are accepted.
The patches that have gone into the mainline kernel rely on each process opting
in to this relaxed ABI.
This commit adds code to choose that ABI into __hwasan_init.
The idea has already been agreed with one of the hwasan developers
(http://lists.llvm.org/pipermail/llvm-dev/2019-September/135328.html).
The patch currently avoids doing anything for Android, but that's
temporary until I get some feedback about whether and when
the mainline kernel patches using `prctl` go into the Android kernel.
I've tested this on an AArch64 VM running a kernel that requires this
prctl, having compiled both with clang and gcc.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D68794
Files:
compiler-rt/lib/hwasan/hwasan.cpp
compiler-rt/lib/hwasan/hwasan.h
compiler-rt/lib/hwasan/hwasan_linux.cpp
Index: compiler-rt/lib/hwasan/hwasan_linux.cpp
===================================================================
--- compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -34,6 +34,7 @@
#include <sys/time.h>
#include <unistd.h>
#include <unwind.h>
+#include <sys/prctl.h>
#include "sanitizer_common/sanitizer_common.h"
#include "sanitizer_common/sanitizer_procmaps.h"
@@ -144,6 +145,30 @@
FindDynamicShadowStart(shadow_size_bytes);
}
+void InitPrctl() {
+ /* This function uses the prctl interface to ask the kernel to accept
+ tagged pointers. This is only needed on linux that is not Android,
+ since the android kernel does not have this interface to choosing the
+ syscall ABI.
+
+ Here we unconditionally request that the PR_TAGGED_ADDR_ENABLE value is
+ turned on, there is nothing else that can be done.
+ */
+#if !SANITIZER_ANDROID
+#define PR_SET_TAGGED_ADDR_CTRL 55
+#define PR_GET_TAGGED_ADDR_CTRL 56
+#define PR_TAGGED_ADDR_ENABLE (1UL << 0)
+ if (prctl(PR_SET_TAGGED_ADDR_CTRL, PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == -1
+ || ! prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0)) {
+ Printf("FATAL: HWAddressSanitizer failed to enable tagged pointer syscall ABI.\n");
+ Die();
+ }
+#undef PR_SET_TAGGED_ADDR_CTRL
+#undef PR_GET_TAGGED_ADDR_CTRL
+#undef PR_TAGGED_ADDR_ENABLE
+#endif
+}
+
bool InitShadow() {
// Define the entire memory range.
kHighMemEnd = GetHighMemEnd();
Index: compiler-rt/lib/hwasan/hwasan.h
===================================================================
--- compiler-rt/lib/hwasan/hwasan.h
+++ compiler-rt/lib/hwasan/hwasan.h
@@ -74,6 +74,7 @@
bool ProtectRange(uptr beg, uptr end);
bool InitShadow();
+void InitPrctl();
void InitThreads();
void MadviseShadow();
char *GetProcSelfMaps();
Index: compiler-rt/lib/hwasan/hwasan.cpp
===================================================================
--- compiler-rt/lib/hwasan/hwasan.cpp
+++ compiler-rt/lib/hwasan/hwasan.cpp
@@ -354,6 +354,8 @@
hwasan_init_is_running = 1;
SanitizerToolName = "HWAddressSanitizer";
+ InitPrctl();
+
InitTlsSize();
CacheBinaryName();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68794.224353.patch
Type: text/x-patch
Size: 2196 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191010/299811b7/attachment.bin>
More information about the llvm-commits
mailing list