From d37113311c9541876bf3e268f2cace272515a694 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Thu, 20 Aug 2020 16:27:01 -0700 Subject: [PATCH] async_safe: don't call libc's socket. Like with close, socket is no longer a simple syscall, so we can get recursive calls that deadlock. Bug: http://b/165206592 Test: bionic-unit-tests on cuttlefish Test: treehugger Change-Id: I2ba77d733d1ebf08a91afd6ca179e7ae6ae3866e --- libc/async_safe/async_safe_log.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/libc/async_safe/async_safe_log.cpp b/libc/async_safe/async_safe_log.cpp index 207035a15..8b2a32b14 100644 --- a/libc/async_safe/async_safe_log.cpp +++ b/libc/async_safe/async_safe_log.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -51,12 +52,22 @@ #include "private/ErrnoRestorer.h" #include "private/ScopedPthreadMutexLocker.h" -// Don't call libc's close, since it might call back into us as a result of fdsan. +// Don't call libc's close or socket, since it might call back into us as a result of fdsan/fdtrack. #pragma GCC poison close static int __close(int fd) { return syscall(__NR_close, fd); } +static int __socket(int domain, int type, int protocol) { +#if defined(__i386__) + unsigned long args[3] = {static_cast(domain), static_cast(type), + static_cast(protocol)}; + return syscall(__NR_socketcall, SYS_SOCKET, &args); +#else + return syscall(__NR_socket, domain, type, protocol); +#endif +} + // Must be kept in sync with frameworks/base/core/java/android/util/EventLog.java. enum AndroidEventLogType { EVENT_TYPE_INT = 0, @@ -460,7 +471,7 @@ static int open_log_socket() { // found that all logd crashes thus far have had no problem stuffing // the UNIX domain socket and moving on so not critical *today*. - int log_fd = TEMP_FAILURE_RETRY(socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)); + int log_fd = TEMP_FAILURE_RETRY(__socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)); if (log_fd == -1) { return -1; }