[PATCH] D68794: libhwasan initialisation include kernel syscall ABI relaxation
Matthew Malcomson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 15 04:46:31 PDT 2019
mmalcomson updated this revision to Diff 225002.
mmalcomson added a comment.
In D68794#1706679 <https://reviews.llvm.org/D68794#1706679>, @eugenis wrote:
> In D68794#1705862 <https://reviews.llvm.org/D68794#1705862>, @mmalcomson wrote:
>
> > Run `prctl` syscall for Android, but ignore EINVAL failures.
> >
> > NOTE: I don't believe this distinguishes between running on a kernel with with the tagged address ABI unconditional or running on a newer kernel or on a kernel with `sysctl abi.tagged_addr_disabled=1`
> > (https://android.googlesource.com/kernel/common/+/690c4ca8a5715644370384672f24d95b042db74a/Documentation/arm64/tagged-address-abi.rst)
>
>
> This is a good point. It appears that PR_GET_TAGGED_ADDR_CTRL works even when abi.tagged_addr_disabled=1, we can use it to tell these two cases apart
Ah! So it does!
I'd apparently not updated my kernel since this was added -- thanks for the catch!
I've used that to add a slightly nicer error message and implemented the suggested changes.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D68794/new/
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,8 @@
#include <sys/time.h>
#include <unistd.h>
#include <unwind.h>
+#include <sys/prctl.h>
+#include <errno.h>
#include "sanitizer_common/sanitizer_common.h"
#include "sanitizer_common/sanitizer_procmaps.h"
@@ -144,6 +146,42 @@
FindDynamicShadowStart(shadow_size_bytes);
}
+void InitPrctl() {
+#define PR_SET_TAGGED_ADDR_CTRL 55
+#define PR_GET_TAGGED_ADDR_CTRL 56
+#define PR_TAGGED_ADDR_ENABLE (1UL << 0)
+
+ // Check we're running on a kernel that can use the tagged address ABI.
+ if (internal_prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0) == -1
+ && errno == EINVAL) {
+#if SANITIZER_ANDROID
+ // Some older Android kernels have the tagged pointer ABI on
+ // unconditionally, and hence don't have the tagged-addr prctl while still
+ // allow the ABI.
+ // If targeting Android and the prctl is not around we assume this is the
+ // case.
+ return;
+#else
+ Printf("FATAL: "
+ "HWAddressSanitizer requires a kernel with tagged address ABI.\n");
+ Die();
+#endif
+ }
+
+ // Turn on the tagged address ABI.
+ if (internal_prctl(PR_SET_TAGGED_ADDR_CTRL,
+ PR_TAGGED_ADDR_ENABLE, 0, 0, 0) == -1
+ || ! internal_prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0)) {
+ Printf("FATAL: HWAddressSanitizer failed to enable tagged address "
+ "syscall ABI.\n"
+ "Suggest check `sysctl abi.tagged_addr_disabled` configuration.\n");
+ Die();
+ }
+#undef PR_SET_TAGGED_ADDR_CTRL
+#undef PR_GET_TAGGED_ADDR_CTRL
+#undef PR_TAGGED_ADDR_ENABLE
+}
+
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
@@ -312,6 +312,8 @@
static void InitInstrumentation() {
if (hwasan_instrumentation_inited) return;
+ InitPrctl();
+
if (!InitShadow()) {
Printf("FATAL: HWAddressSanitizer cannot mmap the shadow memory.\n");
DumpProcessMap();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68794.225002.patch
Type: text/x-patch
Size: 2642 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191015/034ed79b/attachment.bin>
More information about the llvm-commits
mailing list