diff options
author | Dimitry Ivanov <dimitry@google.com> | 2016-08-25 14:53:35 -0700 |
---|---|---|
committer | Dimitry Ivanov <dimitry@google.com> | 2016-08-25 14:58:22 -0700 |
commit | 7da4bbbe87a7eca742c6c45a76aaf191aa70d948 (patch) | |
tree | 12caad3e273e245325378cc7a1b7b4b97a398685 | |
parent | 56762e036ba4dafee2c25dabddd4dc6f7b65f2a6 (diff) | |
download | bionic-7da4bbbe87a7eca742c6c45a76aaf191aa70d948.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
-rw-r--r-- | linker/linker.cpp | 9 |
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?"); |