Fix SKIP_FD_SANITIZATION false positive

Fix #6523
This commit is contained in:
LoveSy 2023-02-11 18:08:26 +08:00 committed by John Wu
parent 9e8c68af12
commit 577b5912af

View File

@ -520,7 +520,7 @@ void HookContext::sanitize_fds() {
if (flags[SKIP_FD_SANITIZATION]) if (flags[SKIP_FD_SANITIZATION])
return; return;
if (flags[APP_FORK_AND_SPECIALIZE]) { if (flags[APP_FORK_AND_SPECIALIZE] && args.app->fds_to_ignore) {
auto update_fd_array = [&](int off) -> jintArray { auto update_fd_array = [&](int off) -> jintArray {
if (exempted_fds.empty()) if (exempted_fds.empty())
return nullptr; return nullptr;
@ -566,7 +566,7 @@ void HookContext::sanitize_fds() {
int dfd = dirfd(dir.get()); int dfd = dirfd(dir.get());
for (dirent *entry; (entry = xreaddir(dir.get()));) { for (dirent *entry; (entry = xreaddir(dir.get()));) {
int fd = parse_int(entry->d_name); int fd = parse_int(entry->d_name);
if ((fd < 0 || fd >= MAX_FD_SIZE || !allowed_fds[fd]) && fd != dfd) { if ((fd < 0 || fd >= MAX_FD_SIZE || !allowed_fds[fd]) && fd != dfd && fd != logd_fd) {
close(fd); close(fd);
} }
} }
@ -746,8 +746,9 @@ void HookContext::nativeForkAndSpecialize_pre() {
flags[APP_FORK_AND_SPECIALIZE] = true; flags[APP_FORK_AND_SPECIALIZE] = true;
if (args.app->fds_to_ignore == nullptr) { if (args.app->fds_to_ignore == nullptr) {
// The field fds_to_ignore don't exist before Android 8.0, which FDs are not checked // if fds_to_ignore does not exist and there's no FileDescriptorTable::Create,
flags[SKIP_FD_SANITIZATION] = true; // we can skip fd sanitization
flags[SKIP_FD_SANITIZATION] = !dlsym(RTLD_DEFAULT, "_ZN19FileDescriptorTable6CreateEv");
} else if (logd_fd >= 0) { } else if (logd_fd >= 0) {
exempted_fds.push_back(logd_fd); exempted_fds.push_back(logd_fd);
} }