[PATCH] D57179: Enhance support for NetBSD in SafeStack

Kamil Rytarowski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 24 13:39:28 PST 2019


krytarowski marked 2 inline comments as done.
krytarowski added inline comments.


================
Comment at: lib/safestack/safestack_platform.h:46
+#if SANITIZER_NETBSD
+static void *GetRealLibcAddress(const char *symbol) {
+  void *real = dlsym(RTLD_NEXT, symbol);
----------------
vitalybuka wrote:
> maybe merge this and "#if SANITIZER_NETBSD" above?
I prefer to keep this function namespaced.


================
Comment at: lib/safestack/safestack_platform.h:116
 inline int Mprotect(void *addr, size_t length, int prot) {
 #if SANITIZER_NETBSD
+  DEFINE__REAL(int, mprotect, void *a, size_t b, int c);
----------------
vitalybuka wrote:
> krytarowski wrote:
> > vitalybuka wrote:
> > > We don't want to hit interpector here, because it can be called called from preinit_array.
> > > DEFINE__REAL will avoid interceptors, however dlsym from preinit_array may crash as it can to try to allocate memory.
> > > So we use syscall on linux. 
> > > sanitizer_common/sanitizer_netbsd still had such problem, so I didn't bother to copy DEFINE_REAL.
> > > 
> > NetBSD does not use/support `preinit_array`, except on archs that demand it (amd64/i386 aren't in the set).
> > 
> > How does it crash with allocating the memory? By calling real malloc? Dynamic loader on NetBSD uses its internal copy of xmalloc() for allocations.
> > 
> > According to my quick testing with gdb(1) and an example program, dlsym(3) does not allocate anything through xmalloc() (at least for RTLD_SELF).
> Yes, on linux it crashes with malloc which can be not initialized (if its non standard allocator)
> 
> 
So there is no problem on NetBSD, at least in the current circumstances nothing is known to be faulty.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57179/new/

https://reviews.llvm.org/D57179





More information about the llvm-commits mailing list