diff --git a/browser/app/winlauncher/freestanding/LoaderPrivateAPI.cpp b/browser/app/winlauncher/freestanding/LoaderPrivateAPI.cpp index cc3d96f9ceba..40bc8ac63999 100644 --- a/browser/app/winlauncher/freestanding/LoaderPrivateAPI.cpp +++ b/browser/app/winlauncher/freestanding/LoaderPrivateAPI.cpp @@ -9,6 +9,7 @@ #include "mozilla/Assertions.h" #include "mozilla/Types.h" #include "mozilla/Unused.h" +#include "../DllBlocklistInit.h" using GlobalInitializerFn = void(__cdecl*)(void); @@ -84,7 +85,7 @@ class MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS LoaderPrivateAPIImp final void NotifyEndDllLoad(void* aContext, NTSTATUS aLoadNtStatus, ModuleLoadInfo&& aModuleLoadInfo) final; nt::AllocatedUnicodeString GetSectionName(void* aSectionAddr) final; - nt::MemorySectionNameBuf GetSectionNameBuffer(void* aSectionAddr) final; + nt::LoaderAPI::InitDllBlocklistOOPFnPtr GetDllBlocklistInitFn() final; // LoaderPrivateAPI void NotifyBeginDllLoad(void** aContext, @@ -93,6 +94,7 @@ class MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS LoaderPrivateAPIImp final PCUNICODE_STRING aRequestedDllName) final; void SetObserver(nt::LoaderObserver* aNewObserver) final; bool IsDefaultObserver() const final; + nt::MemorySectionNameBuf GetSectionNameBuffer(void* aSectionAddr) final; }; static void Init() { @@ -208,6 +210,11 @@ nt::AllocatedUnicodeString LoaderPrivateAPIImp::GetSectionName( return nt::AllocatedUnicodeString(&buf.mSectionFileName); } +nt::LoaderAPI::InitDllBlocklistOOPFnPtr +LoaderPrivateAPIImp::GetDllBlocklistInitFn() { + return &InitializeDllBlocklistOOP; +} + nt::MemorySectionNameBuf LoaderPrivateAPIImp::GetSectionNameBuffer( void* aSectionAddr) { const HANDLE kCurrentProcess = reinterpret_cast(-1); diff --git a/mozglue/dllservices/LoaderAPIInterfaces.h b/mozglue/dllservices/LoaderAPIInterfaces.h index 63b56465a3b4..bff2642e83ea 100644 --- a/mozglue/dllservices/LoaderAPIInterfaces.h +++ b/mozglue/dllservices/LoaderAPIInterfaces.h @@ -92,6 +92,15 @@ class NS_NO_VTABLE LoaderAPI { * backing it. */ virtual AllocatedUnicodeString GetSectionName(void* aSectionAddr) = 0; + + using InitDllBlocklistOOPFnPtr = + LauncherVoidResultWithLineInfo (*)(const wchar_t*, HANDLE); + + /** + * Return a pointer to the cross-process DLL Blocklist Init function. + * Used by sandboxBroker::LaunchApp. + */ + virtual InitDllBlocklistOOPFnPtr GetDllBlocklistInitFn() = 0; }; } // namespace nt diff --git a/mozglue/dllservices/ModuleLoadFrame.cpp b/mozglue/dllservices/ModuleLoadFrame.cpp index f0a9225f930b..cb67f726bce4 100644 --- a/mozglue/dllservices/ModuleLoadFrame.cpp +++ b/mozglue/dllservices/ModuleLoadFrame.cpp @@ -28,7 +28,8 @@ nt::LoaderAPI* ModuleLoadFrame::sLoaderAPI; using GetNtLoaderAPIFn = decltype(&mozilla::GetNtLoaderAPI); /* static */ -void ModuleLoadFrame::StaticInit(nt::LoaderObserver* aNewObserver) { +nt::LoaderAPI::InitDllBlocklistOOPFnPtr ModuleLoadFrame::StaticInit( + nt::LoaderObserver* aNewObserver) { const auto pGetNtLoaderAPI = reinterpret_cast( ::GetProcAddress(::GetModuleHandleW(nullptr), "GetNtLoaderAPI")); if (!pGetNtLoaderAPI) { @@ -36,10 +37,12 @@ void ModuleLoadFrame::StaticInit(nt::LoaderObserver* aNewObserver) { // the launcher process blocklist. gFallbackLoaderAPI.SetObserver(aNewObserver); sLoaderAPI = &gFallbackLoaderAPI; - return; + return nullptr; } sLoaderAPI = pGetNtLoaderAPI(aNewObserver); + MOZ_ASSERT(sLoaderAPI); + return sLoaderAPI->GetDllBlocklistInitFn(); } ModuleLoadFrame::ModuleLoadFrame(PCUNICODE_STRING aRequestedDllName) diff --git a/mozglue/dllservices/ModuleLoadFrame.h b/mozglue/dllservices/ModuleLoadFrame.h index de8ef04f09ce..9a31455b8a56 100644 --- a/mozglue/dllservices/ModuleLoadFrame.h +++ b/mozglue/dllservices/ModuleLoadFrame.h @@ -25,7 +25,8 @@ class MOZ_RAII ModuleLoadFrame final { ModuleLoadFrame& operator=(const ModuleLoadFrame&) = delete; ModuleLoadFrame& operator=(ModuleLoadFrame&&) = delete; - static void StaticInit(nt::LoaderObserver* aNewObserver); + static nt::LoaderAPI::InitDllBlocklistOOPFnPtr StaticInit( + nt::LoaderObserver* aNewObserver); private: bool mAlreadyLoaded; diff --git a/mozglue/dllservices/WindowsDllBlocklist.cpp b/mozglue/dllservices/WindowsDllBlocklist.cpp index 6e30c724c91f..566455ebe530 100644 --- a/mozglue/dllservices/WindowsDllBlocklist.cpp +++ b/mozglue/dllservices/WindowsDllBlocklist.cpp @@ -588,6 +588,7 @@ static WindowsDllInterceptor Kernel32Intercept; static void GetNativeNtBlockSetWriter(); static glue::LoaderObserver gMozglueLoaderObserver; +static nt::LoaderAPI::InitDllBlocklistOOPFnPtr gInitDllBlocklistOOPFnPtr; MFBT_API void DllBlocklist_Initialize(uint32_t aInitFlags) { if (sBlocklistInitAttempted) { @@ -597,7 +598,8 @@ MFBT_API void DllBlocklist_Initialize(uint32_t aInitFlags) { sInitFlags = aInitFlags; - glue::ModuleLoadFrame::StaticInit(&gMozglueLoaderObserver); + gInitDllBlocklistOOPFnPtr = + glue::ModuleLoadFrame::StaticInit(&gMozglueLoaderObserver); #ifdef _M_AMD64 if (!IsWin8OrLater()) { @@ -753,6 +755,7 @@ MFBT_API void DllBlocklist_SetFullDllServices( glue::AutoExclusiveLock lock(gDllServicesLock); if (aSvc) { aSvc->SetAuthenticodeImpl(GetAuthenticode()); + aSvc->SetInitDllBlocklistOOPFnPtr(gInitDllBlocklistOOPFnPtr); gMozglueLoaderObserver.Forward(aSvc); } diff --git a/mozglue/dllservices/WindowsDllServices.h b/mozglue/dllservices/WindowsDllServices.h index 69cd12dd1049..cca67593ef47 100644 --- a/mozglue/dllservices/WindowsDllServices.h +++ b/mozglue/dllservices/WindowsDllServices.h @@ -10,10 +10,12 @@ #include "mozilla/Assertions.h" #include "mozilla/Authenticode.h" #include "mozilla/LoaderAPIInterfaces.h" +#include "mozilla/Move.h" #include "mozilla/mozalloc.h" #include "mozilla/UniquePtr.h" #include "mozilla/Vector.h" #include "mozilla/WindowsDllBlocklist.h" +#include "mozilla/WinHeaderOnlyUtils.h" #if defined(MOZILLA_INTERNAL_API) @@ -57,6 +59,17 @@ class DllServicesBase : public Authenticode { mAuthenticode = aAuthenticode; } + void SetInitDllBlocklistOOPFnPtr( + nt::LoaderAPI::InitDllBlocklistOOPFnPtr aPtr) { + mInitDllBlocklistOOPFnPtr = aPtr; + } + + template + LauncherVoidResultWithLineInfo InitDllBlocklistOOP(Args&&... aArgs) { + MOZ_RELEASE_ASSERT(mInitDllBlocklistOOPFnPtr); + return mInitDllBlocklistOOPFnPtr(std::forward(aArgs)...); + } + // In debug builds we override GetBinaryOrgName to add a Gecko-specific // assertion. OTOH, we normally do not want people overriding this function, // so we'll make it final in the release case, thus covering all bases. @@ -85,7 +98,8 @@ class DllServicesBase : public Authenticode { DllServicesBase& operator=(DllServicesBase&&) = delete; protected: - DllServicesBase() : mAuthenticode(nullptr) {} + DllServicesBase() + : mAuthenticode(nullptr), mInitDllBlocklistOOPFnPtr(nullptr) {} virtual ~DllServicesBase() = default; @@ -94,6 +108,7 @@ class DllServicesBase : public Authenticode { private: Authenticode* mAuthenticode; + nt::LoaderAPI::InitDllBlocklistOOPFnPtr mInitDllBlocklistOOPFnPtr; }; } // namespace detail diff --git a/mozglue/dllservices/WindowsFallbackLoaderAPI.cpp b/mozglue/dllservices/WindowsFallbackLoaderAPI.cpp index 09cccee0615e..b57925c926de 100644 --- a/mozglue/dllservices/WindowsFallbackLoaderAPI.cpp +++ b/mozglue/dllservices/WindowsFallbackLoaderAPI.cpp @@ -67,6 +67,12 @@ nt::AllocatedUnicodeString FallbackLoaderAPI::GetSectionName( return nt::AllocatedUnicodeString(&buf.mSectionFileName); } +nt::LoaderAPI::InitDllBlocklistOOPFnPtr +FallbackLoaderAPI::GetDllBlocklistInitFn() { + MOZ_ASSERT_UNREACHABLE("This should not be called so soon!"); + return nullptr; +} + void FallbackLoaderAPI::SetObserver(nt::LoaderObserver* aLoaderObserver) { mLoaderObserver = aLoaderObserver; } diff --git a/mozglue/dllservices/WindowsFallbackLoaderAPI.h b/mozglue/dllservices/WindowsFallbackLoaderAPI.h index 3232df71f376..cca5fadf1eb3 100644 --- a/mozglue/dllservices/WindowsFallbackLoaderAPI.h +++ b/mozglue/dllservices/WindowsFallbackLoaderAPI.h @@ -24,6 +24,7 @@ class MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS FallbackLoaderAPI final void NotifyEndDllLoad(void* aContext, NTSTATUS aLoadNtStatus, ModuleLoadInfo&& aModuleLoadInfo) final; nt::AllocatedUnicodeString GetSectionName(void* aSectionAddr) final; + nt::LoaderAPI::InitDllBlocklistOOPFnPtr GetDllBlocklistInitFn() final; void SetObserver(nt::LoaderObserver* aLoaderObserver);