diff options
author | Josh Gao <jmgao@google.com> | 2020-05-07 19:40:14 -0700 |
---|---|---|
committer | Josh Gao <jmgao@google.com> | 2020-05-12 01:42:18 -0700 |
commit | 1bf410b5f9e47ead5b78d5d030bbc830ffb2719d (patch) | |
tree | 1734d1b48d5d469e36b33cc92a014579e02d4bfc | |
parent | 53783514325872d274523642af4b80135a1a86ec (diff) | |
download | bionic-1bf410b5f9e47ead5b78d5d030bbc830ffb2719d.tar.gz |
fdsan: don't do anything when vforked.
Bug: http://b/153926671
Test: 32/64-bit bionic-unit-tests on blueline, x86_64 emulator
Change-Id: Id351a993e396774b68239edfef83d9e81205290b
(cherry picked from commit 65fb2a7f0304fda4463771ae40f8b83728e74a62)
-rw-r--r-- | libc/bionic/fdsan.cpp | 12 | ||||
-rw-r--r-- | tests/fdsan_test.cpp | 19 |
2 files changed, 31 insertions, 0 deletions
diff --git a/libc/bionic/fdsan.cpp b/libc/bionic/fdsan.cpp index ebc680f3e..4b8991872 100644 --- a/libc/bionic/fdsan.cpp +++ b/libc/bionic/fdsan.cpp @@ -246,6 +246,10 @@ uint64_t android_fdsan_get_tag_value(uint64_t tag) { } int android_fdsan_close_with_tag(int fd, uint64_t expected_tag) { + if (__get_thread()->is_vforked()) { + return __close(fd); + } + FDTRACK_CLOSE(fd); FdEntry* fde = GetFdEntry(fd); if (!fde) { @@ -296,6 +300,10 @@ uint64_t android_fdsan_get_owner_tag(int fd) { } void android_fdsan_exchange_owner_tag(int fd, uint64_t expected_tag, uint64_t new_tag) { + if (__get_thread()->is_vforked()) { + return; + } + FdEntry* fde = GetFdEntry(fd); if (!fde) { return; @@ -332,6 +340,10 @@ android_fdsan_error_level android_fdsan_get_error_level() { } android_fdsan_error_level android_fdsan_set_error_level(android_fdsan_error_level new_level) { + if (__get_thread()->is_vforked()) { + return android_fdsan_get_error_level(); + } + return atomic_exchange(&GetFdTable().error_level, new_level); } diff --git a/tests/fdsan_test.cpp b/tests/fdsan_test.cpp index fb3f73dc3..134d62117 100644 --- a/tests/fdsan_test.cpp +++ b/tests/fdsan_test.cpp @@ -23,6 +23,7 @@ #include <fcntl.h> #include <stdlib.h> #include <sys/types.h> +#include <unistd.h> #if defined(__BIONIC__) #include <android/fdsan.h> @@ -192,3 +193,21 @@ TEST_F(FdsanTest, unique_fd_unowned_close_after_move) { EXPECT_FDSAN_DEATH(close(fd_moved.get()), "expected to be unowned, actually owned by unique_fd"); #endif } + +TEST_F(FdsanTest, vfork) { + android::base::unique_fd fd(open("/dev/null", O_RDONLY)); + + pid_t rc = vfork(); + ASSERT_NE(-1, rc); + + if (rc == 0) { + close(fd.get()); + _exit(0); + } + + int status; + pid_t wait_result = waitpid(rc, &status, 0); + ASSERT_EQ(wait_result, rc); + ASSERT_TRUE(WIFEXITED(status)); + ASSERT_EQ(0, WEXITSTATUS(status)); +} |