[PATCH] D42430: [scudo] Allow for weak hooks, gated by a define
Kostya Kortchinsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 23 09:27:04 PST 2018
cryptoad created this revision.
cryptoad added a reviewer: alekseyshl.
Herald added a subscriber: Sanitizers.
Hooks in the allocation & deallocation paths can be a security risk (see for an
example https://scarybeastsecurity.blogspot.com/2016/11/0day-exploit-advancing-exploitation.html
which used the glibc's __free_hook to complete exploitation).
But some users have expressed a need for them, even if only for tests and
memory benchmarks. So allow for `__sanitizer_malloc_hook` &
`__sanitizer_free_hook` to be called if defined, and gate them behind a global
define `SCUDO_CAN_USE_HOOKS` defaulting to 0.
Repository:
rCRT Compiler Runtime
https://reviews.llvm.org/D42430
Files:
lib/scudo/scudo_allocator.cpp
lib/scudo/scudo_platform.h
Index: lib/scudo/scudo_platform.h
===================================================================
--- lib/scudo/scudo_platform.h
+++ lib/scudo/scudo_platform.h
@@ -55,6 +55,12 @@
# define SCUDO_CAN_USE_PUBLIC_INTERFACE 1
#endif
+// Hooks in the allocation & deallocation paths can become a security concern if
+// implemented improperly, or if overwritten by an attacker. Use with caution.
+#ifndef SCUDO_CAN_USE_HOOKS
+# define SCUDO_CAN_USE_HOOKS 0
+#endif
+
namespace __scudo {
#if SANITIZER_CAN_USE_ALLOCATOR64
Index: lib/scudo/scudo_allocator.cpp
===================================================================
--- lib/scudo/scudo_allocator.cpp
+++ lib/scudo/scudo_allocator.cpp
@@ -430,7 +430,8 @@
}
void *Ptr = reinterpret_cast<void *>(UserPtr);
Chunk::storeHeader(Ptr, &Header);
- // if (&__sanitizer_malloc_hook) __sanitizer_malloc_hook(Ptr, Size);
+ if (SCUDO_CAN_USE_HOOKS && &__sanitizer_malloc_hook)
+ __sanitizer_malloc_hook(Ptr, Size);
return Ptr;
}
@@ -480,7 +481,8 @@
// the TLS destructors, ending up in initialized thread specific data never
// being destroyed properly. Any other heap operation will do a full init.
initThreadMaybe(/*MinimalInit=*/true);
- // if (&__sanitizer_free_hook) __sanitizer_free_hook(Ptr);
+ if (SCUDO_CAN_USE_HOOKS && &__sanitizer_free_hook)
+ __sanitizer_free_hook(Ptr);
if (UNLIKELY(!Ptr))
return;
if (UNLIKELY(!Chunk::isAligned(Ptr))) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42430.131095.patch
Type: text/x-patch
Size: 1482 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180123/2cd8f9eb/attachment.bin>
More information about the llvm-commits
mailing list