summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitry Ivanov <dimitry@google.com>2015-10-15 01:17:55 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-10-15 01:17:55 +0000
commit95ac6dbbb23da4967221c3077a10635b1626b031 (patch)
treea6a66f39392900cce31ac3ac1460267d33b81ede
parent3c30a156523f40250361e6ed8791919d1c71a4bb (diff)
parentcf92738fa5dee24050028a1235f815f2a0fd33b5 (diff)
downloadbionic-95ac6dbbb23da4967221c3077a10635b1626b031.zip
bionic-95ac6dbbb23da4967221c3077a10635b1626b031.tar.gz
bionic-95ac6dbbb23da4967221c3077a10635b1626b031.tar.bz2
Merge "Ensure that readlink has access to /proc/self/fd" into mnc-dr-dev
-rw-r--r--linker/linker.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/linker/linker.cpp b/linker/linker.cpp
index c99042f..d3ac1d0 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -37,6 +37,7 @@
#include <string.h>
#include <sys/mman.h>
#include <sys/param.h>
+#include <sys/prctl.h>
#include <unistd.h>
#include <new>
@@ -317,6 +318,13 @@ static void parse_LD_PRELOAD(const char* path) {
static bool realpath_fd(int fd, std::string* realpath) {
std::vector<char> buf(PATH_MAX), proc_self_fd(PATH_MAX);
snprintf(&proc_self_fd[0], proc_self_fd.size(), "/proc/self/fd/%d", fd);
+ // set DUMPABLE to 1 to access /proc/self/fd
+ int dumpable = prctl(PR_GET_DUMPABLE, 0, 0, 0, 0);
+ prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
+ auto guard = make_scope_guard([&]() {
+ // restore dumpable
+ prctl(PR_SET_DUMPABLE, dumpable, 0, 0, 0);
+ });
if (readlink(&proc_self_fd[0], &buf[0], buf.size()) == -1) {
PRINT("readlink('%s') failed: %s [fd=%d]", &proc_self_fd[0], strerror(errno), fd);
return false;