diff options
author | Josh Gao <jmgao@google.com> | 2018-06-01 15:47:20 -0700 |
---|---|---|
committer | Josh Gao <jmgao@google.com> | 2018-07-18 18:11:46 -0700 |
commit | c954ec09c527ae1ad758ddd44b178da66c4c35e0 (patch) | |
tree | 842dead3542e166d4039984029d5d30912f9ff28 | |
parent | fcf2c01b5599a96b968afb1528c996d9486937b0 (diff) | |
download | system_core-c954ec09c527ae1ad758ddd44b178da66c4c35e0.tar.gz system_core-c954ec09c527ae1ad758ddd44b178da66c4c35e0.tar.bz2 system_core-c954ec09c527ae1ad758ddd44b178da66c4c35e0.zip |
debuggerd_handler: use syscall(__NR_close) instead of close.
Avoid bionic's file descriptor ownership checks by calling the close
syscall manually.
Test: debuggerd_test
Change-Id: I10af6aca0e66fe030fd7a53506ae61c87695641d
-rw-r--r-- | base/include/android-base/unique_fd.h | 10 | ||||
-rw-r--r-- | debuggerd/handler/debuggerd_handler.cpp | 14 |
2 files changed, 19 insertions, 5 deletions
diff --git a/base/include/android-base/unique_fd.h b/base/include/android-base/unique_fd.h index 057f462e5..019d337c4 100644 --- a/base/include/android-base/unique_fd.h +++ b/base/include/android-base/unique_fd.h @@ -151,7 +151,8 @@ using unique_fd = unique_fd_impl<DefaultCloser>; #if !defined(_WIN32) // Inline functions, so that they can be used header-only. -inline bool Pipe(unique_fd* read, unique_fd* write) { +template <typename Closer> +inline bool Pipe(unique_fd_impl<Closer>* read, unique_fd_impl<Closer>* write) { int pipefd[2]; #if defined(__linux__) @@ -175,7 +176,9 @@ inline bool Pipe(unique_fd* read, unique_fd* write) { return true; } -inline bool Socketpair(int domain, int type, int protocol, unique_fd* left, unique_fd* right) { +template <typename Closer> +inline bool Socketpair(int domain, int type, int protocol, unique_fd_impl<Closer>* left, + unique_fd_impl<Closer>* right) { int sockfd[2]; if (socketpair(domain, type, protocol, sockfd) != 0) { return false; @@ -185,7 +188,8 @@ inline bool Socketpair(int domain, int type, int protocol, unique_fd* left, uniq return true; } -inline bool Socketpair(int type, unique_fd* left, unique_fd* right) { +template <typename Closer> +inline bool Socketpair(int type, unique_fd_impl<Closer>* left, unique_fd_impl<Closer>* right) { return Socketpair(AF_UNIX, type, 0, left, right); } diff --git a/debuggerd/handler/debuggerd_handler.cpp b/debuggerd/handler/debuggerd_handler.cpp index c07a34a70..615fb46ad 100644 --- a/debuggerd/handler/debuggerd_handler.cpp +++ b/debuggerd/handler/debuggerd_handler.cpp @@ -59,7 +59,16 @@ #include "protocol.h" using android::base::Pipe; -using android::base::unique_fd; + +// We muck with our fds in a 'thread' that doesn't share the same fd table. +// Close fds in that thread with a raw close syscall instead of going through libc. +struct FdsanBypassCloser { + static void Close(int fd) { + syscall(__NR_close, fd); + } +}; + +using unique_fd = android::base::unique_fd_impl<FdsanBypassCloser>; // see man(2) prctl, specifically the section about PR_GET_NAME #define MAX_TASK_NAME_LEN (16) @@ -299,7 +308,8 @@ static int debuggerd_dispatch_pseudothread(void* arg) { debugger_thread_info* thread_info = static_cast<debugger_thread_info*>(arg); for (int i = 0; i < 1024; ++i) { - close(i); + // Don't use close to avoid bionic's file descriptor ownership checks. + syscall(__NR_close, i); } int devnull = TEMP_FAILURE_RETRY(open("/dev/null", O_RDWR)); |