[PATCH] D54113: [sanitizer] Use AT_EXECFN in ReExec() if available

Benjamin Kramer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 5 09:42:44 PST 2018


bkramer created this revision.
bkramer added reviewers: pcc, dvyukov, kcc.
Herald added subscribers: Sanitizers, delcypher, jlebar, kubamracek.

execve("/proc/self/exe") will not work if the binary relies on
$EXEC_ORIGIN in an rpath. Query AT_EXECFN instead, which will give the
same string that the current binary was exec'd with.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D54113

Files:
  lib/sanitizer_common/sanitizer_linux.cc


Index: lib/sanitizer_common/sanitizer_linux.cc
===================================================================
--- lib/sanitizer_common/sanitizer_linux.cc
+++ lib/sanitizer_common/sanitizer_linux.cc
@@ -640,6 +640,10 @@
 #elif SANITIZER_SOLARIS
   pathname = getexecname();
   CHECK_NE(pathname, NULL);
+#elif SANITIZER_USE_GETAUXVAL
+  // Calling execve with /proc/self/exe sets that as $EXEC_ORIGIN. Binaries that
+  // rely on that will fail to load shared libraries. Query AT_EXECFN instead.
+  pathname = reinterpret_cast<const char *>(getauxval(AT_EXECFN));
 #endif
 
   GetArgsAndEnv(&argv, &envp);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54113.172610.patch
Type: text/x-patch
Size: 610 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181105/4f514353/attachment.bin>


More information about the llvm-commits mailing list