aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitry Ivanov <dimitry@google.com>2016-08-25 14:53:35 -0700
committerDimitry Ivanov <dimitry@google.com>2016-08-26 02:33:14 +0000
commitf98712990344c78f6d844b3b81bb284c5b550d94 (patch)
tree7ead2ae862fc60cf7bb30e3b847a8cc94f8bf64e
parent5aa67675f853af9588ac9274ecf86d7858695ce2 (diff)
downloadbionic-f98712990344c78f6d844b3b81bb284c5b550d94.tar.gz
linker: stat /proc/self/exe instead of executable_path
The absolute path to an executable may no longer be valid for example when the file is unlinked immediately after exec. Using /proc/self/exe instead of absolute path solves this problem. Bug: http://b/31084669 Test: Run the app from http://b/31084669 make sure executable starts Test: by checking ps and /proc/<pid>/exe Change-Id: I5c819f39ef0fc4fc71b05de71e8af9ede611f04c (cherry picked from commit 7da4bbbe87a7eca742c6c45a76aaf191aa70d948)
-rw-r--r--linker/linker.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 05b177b89..8b28d7537 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -4223,12 +4223,15 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args, ElfW(
}
}
- const char* executable_path = get_executable_path();
struct stat file_stat;
- if (TEMP_FAILURE_RETRY(stat(executable_path, &file_stat)) != 0) {
- __libc_fatal("unable to stat file for the executable \"%s\": %s", executable_path, strerror(errno));
+ // Stat "/proc/self/exe" instead of executable_path because
+ // the executable could be unlinked by this point and it should
+ // not cause a crash (see http://b/31084669)
+ if (TEMP_FAILURE_RETRY(stat("/proc/self/exe", &file_stat)) != 0) {
+ __libc_fatal("unable to stat \"/proc/self/exe\": %s", strerror(errno));
}
+ const char* executable_path = get_executable_path();
soinfo* si = soinfo_alloc(&g_default_namespace, executable_path, &file_stat, 0, RTLD_GLOBAL);
if (si == nullptr) {
__libc_fatal("Couldn't allocate soinfo: out of memory?");