diff --git a/ipc/attachment_broker_privileged.cc b/ipc/attachment_broker_privileged.cc index 7631001e5413c..a6de9e6064265 100644 --- a/ipc/attachment_broker_privileged.cc +++ b/ipc/attachment_broker_privileged.cc @@ -103,7 +103,7 @@ void AttachmentBrokerPrivileged::DeregisterCommunicationChannel( } Sender* AttachmentBrokerPrivileged::GetSenderWithProcessId(base::ProcessId id) { - base::AutoLock auto_lock(*get_lock()); + get_lock()->AssertAcquired(); auto it = std::find_if(endpoints_.begin(), endpoints_.end(), [id](Endpoint* c) { return c->GetPeerPID() == id; }); if (it == endpoints_.end()) diff --git a/ipc/attachment_broker_privileged.h b/ipc/attachment_broker_privileged.h index cbaaaf276d267..a82d581aadbe2 100644 --- a/ipc/attachment_broker_privileged.h +++ b/ipc/attachment_broker_privileged.h @@ -47,6 +47,9 @@ class IPC_EXPORT AttachmentBrokerPrivileged : public IPC::AttachmentBroker { protected: // Returns the sender whose peer's process id is |id|. // Returns nullptr if no sender is found. + // The lock returned by get_lock() must already be acquired before calling + // this method. The return value is only guaranteed to be valid while the lock + // is held. Sender* GetSenderWithProcessId(base::ProcessId id); // Errors that can be reported by subclasses. diff --git a/ipc/attachment_broker_privileged_mac.cc b/ipc/attachment_broker_privileged_mac.cc index f4dc043971abe..62e218c4b0580 100644 --- a/ipc/attachment_broker_privileged_mac.cc +++ b/ipc/attachment_broker_privileged_mac.cc @@ -8,6 +8,7 @@ #include "base/memory/shared_memory.h" #include "base/process/port_provider_mac.h" #include "base/process/process.h" +#include "base/synchronization/lock.h" #include "ipc/attachment_broker_messages.h" #include "ipc/brokerable_attachment.h" #include "ipc/ipc_channel.h" @@ -210,6 +211,7 @@ bool AttachmentBrokerPrivilegedMac::RouteWireFormatToAnother( // Another process is the destination. base::ProcessId dest = wire_format.destination_process; + base::AutoLock auto_lock(*get_lock()); Sender* sender = GetSenderWithProcessId(dest); if (!sender) { // Assuming that this message was not sent from a malicious process, the @@ -319,6 +321,7 @@ void AttachmentBrokerPrivilegedMac::SendPrecursorsForProcess( bool to_self = pid == base::GetCurrentProcId(); if (!to_self) { + base::AutoLock auto_lock(*get_lock()); if (!GetSenderWithProcessId(pid)) { // If there is no sender, then the destination process is no longer // running, or never existed to begin with. @@ -387,12 +390,15 @@ void AttachmentBrokerPrivilegedMac::ProcessExtractorsForProcess( if (it == extractors_.end()) return; - if (!GetSenderWithProcessId(pid)) { - // If there is no sender, then the source process is no longer running. - LogError(ERROR_SOURCE_NOT_FOUND); - delete it->second; - extractors_.erase(it); - return; + { + base::AutoLock auto_lock(*get_lock()); + if (!GetSenderWithProcessId(pid)) { + // If there is no sender, then the source process is no longer running. + LogError(ERROR_SOURCE_NOT_FOUND); + delete it->second; + extractors_.erase(it); + return; + } } mach_port_t task_port = port_provider_->TaskForPid(pid);