[PATCH] D55986: hwasan: Use system allocator to realloc and free untagged pointers in interceptor mode.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 21 00:02:05 PST 2018


pcc created this revision.
pcc added a reviewer: eugenis.
Herald added subscribers: kubamracek, srhines.

The Android dynamic loader has a non-standard feature that allows
libraries such as the hwasan runtime to interpose symbols even after
the symbol already has a value. The new value of the symbol is used to
relocate libraries loaded after the interposing library, but existing
libraries keep the old value.

What this means in practice is that if we have .so files that depend
on interceptor-mode hwasan without the main executable depending on
it, some of the libraries in the process will be using the hwasan
allocator and some will be using the system allocator, and these
allocators need to interact somehow. For example, if an instrumented
library calls a function such as strdup that allocates memory on
behalf of the caller, the instrumented library can reasonably expect
to be able to call free to deallocate the memory.

We can handle that relatively easily with hwasan by using tag 0 to
represent allocations from the system allocator. If hwasan's realloc
or free functions are passed a pointer with tag 0, the system allocator
is called.

One limitation is that this scheme doesn't work in reverse: if an
instrumented library allocates memory, it must free the memory itself
and cannot pass ownership to a system library. In a future change,
we may want to expose an API for calling the system allocator so
that instrumented libraries can safely transfer ownership of memory
to system libraries.


Repository:
  rL LLVM

https://reviews.llvm.org/D55986

Files:
  compiler-rt/lib/hwasan/hwasan.h
  compiler-rt/lib/hwasan/hwasan_allocator.cc
  compiler-rt/lib/hwasan/hwasan_allocator.h
  compiler-rt/lib/hwasan/hwasan_interceptors.cc
  compiler-rt/lib/hwasan/hwasan_linux.cc
  compiler-rt/lib/hwasan/hwasan_new_delete.cc
  compiler-rt/test/hwasan/TestCases/Posix/system-allocator-fallback.cc
  compiler-rt/test/hwasan/lit.cfg

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55986.179245.patch
Type: text/x-patch
Size: 9760 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181221/f500fd18/attachment.bin>


More information about the llvm-commits mailing list