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
diff --git a/libc/bionic/fdsan.cpp b/libc/bionic/fdsan.cpp
index ebc680f..4b89918 100644
--- a/libc/bionic/fdsan.cpp
+++ b/libc/bionic/fdsan.cpp
@@ -246,6 +246,10 @@
}
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 @@
}
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_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 fb3f73d..134d621 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 @@
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));
+}