Workaround dawn_wire_server_and_frontend_fuzzer ASAN false positive

When discovering Vulkan adapters, if none is found, the vulkan loader
DLL is loaded and then unloaded, which results in ASAN false positives
when the loader's previously allocated memory is re-used, which happens
in fuzzer::TracePC::ClearInlineCounters.

Bug: chromium:1427723
Bug: chromium:1038952
Change-Id: Idb205607426a0af22daba363e2679afaa33204b9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/127840
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Antonio Maiorano 2023-04-18 20:10:51 +00:00 committed by Dawn LUCI CQ
parent b8a3bac98b
commit bacf44f964
1 changed files with 13 additions and 0 deletions
src/dawn/fuzzers

View File

@ -19,6 +19,7 @@
#include <vector>
#include "dawn/common/Assert.h"
#include "dawn/common/DynamicLib.h"
#include "dawn/common/Log.h"
#include "dawn/common/SystemUtils.h"
#include "dawn/dawn_proc.h"
@ -49,6 +50,9 @@ class DevNull : public dawn::wire::CommandSerializer {
std::unique_ptr<dawn::native::Instance> sInstance;
static bool (*sAdapterSupported)(const dawn::native::Adapter&) = nullptr;
#if DAWN_PLATFORM_IS(WINDOWS) && defined(ADDRESS_SANITIZER)
static DynamicLib sVulkanLoader;
#endif
} // namespace
@ -57,6 +61,15 @@ int DawnWireServerFuzzer::Initialize(int* argc, char*** argv) {
// Swiftshader crashes libFuzzer. When this is fixed, move this into Run so that error injection
// for adapter discovery can be fuzzed.
sInstance = std::make_unique<dawn::native::Instance>();
// TODO(crbug.com/1038952): Although we keep a static instance, when discovering default Vulkan
// adapters, if no adapter is found, the vulkan loader DLL will be loaded and then unloaded,
// resulting in ASAN false positives. We work around this by explicitly loading the loader
// without unloading it here.
#if DAWN_PLATFORM_IS(WINDOWS) && defined(ADDRESS_SANITIZER)
sVulkanLoader.Open(GetExecutableDirectory().value_or("") + "vulkan-1.dll");
#endif
sInstance->DiscoverDefaultAdapters();
return 0;