From 9c8f0c8d00f4a3c6c937eb81cede486e593dd35c Mon Sep 17 00:00:00 2001 From: Kershaw Chang Date: Tue, 7 Jul 2020 11:51:17 +0000 Subject: [PATCH] Bug 1647759 - P3: Send init attributes to socket process r=dragana Depends on D82352 Differential Revision: https://phabricator.services.mozilla.com/D82353 --- netwerk/ipc/PSocketProcess.ipdl | 7 +++ netwerk/ipc/SocketProcessChild.cpp | 8 +++ netwerk/ipc/SocketProcessChild.h | 2 + netwerk/ipc/SocketProcessHost.cpp | 80 ++++++++++++++++-------------- 4 files changed, 59 insertions(+), 38 deletions(-) diff --git a/netwerk/ipc/PSocketProcess.ipdl b/netwerk/ipc/PSocketProcess.ipdl index cdc144df5b83..ff0fa491fc7c 100644 --- a/netwerk/ipc/PSocketProcess.ipdl +++ b/netwerk/ipc/PSocketProcess.ipdl @@ -69,6 +69,12 @@ struct SocketDataArgs SocketInfo[] info; }; +struct SocketPorcessInitAttributes { + bool mOffline; + bool mConnectivity; + FileDescriptor? mSandboxBroker; +}; + sync protocol PSocketProcess { manages PDNSRequest; @@ -125,6 +131,7 @@ parent: returns (bool aAccepted); child: + async Init(SocketPorcessInitAttributes aAttributes); async PreferenceUpdate(Pref pref); async RequestMemoryReport(uint32_t generation, bool anonymize, diff --git a/netwerk/ipc/SocketProcessChild.cpp b/netwerk/ipc/SocketProcessChild.cpp index e359b617b6c3..41c9755af6ad 100644 --- a/netwerk/ipc/SocketProcessChild.cpp +++ b/netwerk/ipc/SocketProcessChild.cpp @@ -187,6 +187,14 @@ void SocketProcessChild::CleanUp() { NS_ShutdownXPCOM(nullptr); } +mozilla::ipc::IPCResult SocketProcessChild::RecvInit( + const SocketPorcessInitAttributes& aAttributes) { + Unused << RecvSetOffline(aAttributes.mOffline()); + Unused << RecvSetConnectivity(aAttributes.mConnectivity()); + Unused << RecvInitLinuxSandbox(aAttributes.mSandboxBroker()); + return IPC_OK(); +} + IPCResult SocketProcessChild::RecvPreferenceUpdate(const Pref& aPref) { Preferences::SetPreference(aPref); return IPC_OK(); diff --git a/netwerk/ipc/SocketProcessChild.h b/netwerk/ipc/SocketProcessChild.h index 7f04424368ac..6a5a0ef98a4a 100644 --- a/netwerk/ipc/SocketProcessChild.h +++ b/netwerk/ipc/SocketProcessChild.h @@ -38,6 +38,8 @@ class SocketProcessChild final void ActorDestroy(ActorDestroyReason aWhy) override; + mozilla::ipc::IPCResult RecvInit( + const SocketPorcessInitAttributes& aAttributes); mozilla::ipc::IPCResult RecvPreferenceUpdate(const Pref& aPref); mozilla::ipc::IPCResult RecvRequestMemoryReport( const uint32_t& generation, const bool& anonymize, diff --git a/netwerk/ipc/SocketProcessHost.cpp b/netwerk/ipc/SocketProcessHost.cpp index 4079ed4f89f7..dec2cfc71a84 100644 --- a/netwerk/ipc/SocketProcessHost.cpp +++ b/netwerk/ipc/SocketProcessHost.cpp @@ -134,48 +134,52 @@ void SocketProcessHost::InitAfterConnect(bool aSucceeded) { MOZ_ASSERT(NS_IsMainThread()); mLaunchPhase = LaunchPhase::Complete; - - if (aSucceeded) { - mSocketProcessParent = MakeUnique(this); - DebugOnly rv = mSocketProcessParent->Open( - TakeChannel(), base::GetProcId(GetChildProcessHandle())); - MOZ_ASSERT(rv); - - nsCOMPtr ioService(do_GetIOService()); - MOZ_ASSERT(ioService, "No IO service?"); - bool offline = false; - DebugOnly result = ioService->GetOffline(&offline); - MOZ_ASSERT(NS_SUCCEEDED(result), "Failed getting offline?"); - - Maybe brokerFd; - -#if defined(XP_LINUX) && defined(MOZ_SANDBOX) - if (GetEffectiveSocketProcessSandboxLevel() > 0) { - auto policy = SandboxBrokerPolicyFactory::GetSocketProcessPolicy( - GetActor()->OtherPid()); - if (policy != nullptr) { - brokerFd = Some(FileDescriptor()); - mSandboxBroker = SandboxBroker::Create( - std::move(policy), GetActor()->OtherPid(), brokerFd.ref()); - // This is unlikely to fail and probably indicates OS resource - // exhaustion. - Unused << NS_WARN_IF(mSandboxBroker == nullptr); - MOZ_ASSERT(brokerFd.ref().IsValid()); - } - Unused << GetActor()->SendInitLinuxSandbox(brokerFd); + if (!aSucceeded) { + if (mListener) { + mListener->OnProcessLaunchComplete(this, false); } -#endif // XP_LINUX && MOZ_SANDBOX - -#ifdef MOZ_GECKO_PROFILER - Unused << GetActor()->SendInitProfiler( - ProfilerParent::CreateForProcess(GetActor()->OtherPid())); -#endif - - Unused << GetActor()->SendSetOffline(offline); + return; } + mSocketProcessParent = MakeUnique(this); + DebugOnly rv = mSocketProcessParent->Open( + TakeChannel(), base::GetProcId(GetChildProcessHandle())); + MOZ_ASSERT(rv); + + SocketPorcessInitAttributes attributes; + nsCOMPtr ioService(do_GetIOService()); + MOZ_ASSERT(ioService, "No IO service?"); + DebugOnly result = ioService->GetOffline(&attributes.mOffline()); + MOZ_ASSERT(NS_SUCCEEDED(result), "Failed getting offline?"); + result = ioService->GetConnectivity(&attributes.mConnectivity()); + MOZ_ASSERT(NS_SUCCEEDED(result), "Failed getting connectivity?"); + +#if defined(XP_LINUX) && defined(MOZ_SANDBOX) + if (GetEffectiveSocketProcessSandboxLevel() > 0) { + auto policy = SandboxBrokerPolicyFactory::GetSocketProcessPolicy( + GetActor()->OtherPid()); + if (policy != nullptr) { + attributes.mSandboxBroker() = Some(FileDescriptor()); + mSandboxBroker = + SandboxBroker::Create(std::move(policy), GetActor()->OtherPid(), + attributes.mSandboxBroker().ref()); + // This is unlikely to fail and probably indicates OS resource + // exhaustion. + Unused << NS_WARN_IF(mSandboxBroker == nullptr); + MOZ_ASSERT(attributes.mSandboxBroker().ref().IsValid()); + } + } +#endif // XP_LINUX && MOZ_SANDBOX + + Unused << GetActor()->SendInit(attributes); + +#ifdef MOZ_GECKO_PROFILER + Unused << GetActor()->SendInitProfiler( + ProfilerParent::CreateForProcess(GetActor()->OtherPid())); +#endif + if (mListener) { - mListener->OnProcessLaunchComplete(this, aSucceeded); + mListener->OnProcessLaunchComplete(this, true); } }