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 /debuggerd/handler/debuggerd_handler.cpp | |
parent | fcf2c01b5599a96b968afb1528c996d9486937b0 (diff) |
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
Diffstat (limited to 'debuggerd/handler/debuggerd_handler.cpp')
-rw-r--r-- | debuggerd/handler/debuggerd_handler.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
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)); |