| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ipc/attachment_broker_privileged_mac.h" | 5 #include "ipc/attachment_broker_privileged_mac.h" |
| 6 | 6 |
| 7 #include "base/mac/scoped_mach_port.h" | 7 #include "base/mac/scoped_mach_port.h" |
| 8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
| 9 #include "base/process/port_provider_mac.h" | 9 #include "base/process/port_provider_mac.h" |
| 10 #include "base/process/process.h" | 10 #include "base/process/process.h" |
| 11 #include "base/synchronization/lock.h" |
| 11 #include "ipc/attachment_broker_messages.h" | 12 #include "ipc/attachment_broker_messages.h" |
| 12 #include "ipc/brokerable_attachment.h" | 13 #include "ipc/brokerable_attachment.h" |
| 13 #include "ipc/ipc_channel.h" | 14 #include "ipc/ipc_channel.h" |
| 14 #include "ipc/mach_port_attachment_mac.h" | 15 #include "ipc/mach_port_attachment_mac.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 // Struct for sending a complex Mach message. | 19 // Struct for sending a complex Mach message. |
| 19 struct MachSendComplexMessage { | 20 struct MachSendComplexMessage { |
| 20 mach_msg_header_t header; | 21 mach_msg_header_t header; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 new internal::MachPortAttachmentMac(wire_format)); | 204 new internal::MachPortAttachmentMac(wire_format)); |
| 204 HandleReceivedAttachment(attachment); | 205 HandleReceivedAttachment(attachment); |
| 205 } | 206 } |
| 206 | 207 |
| 207 bool AttachmentBrokerPrivilegedMac::RouteWireFormatToAnother( | 208 bool AttachmentBrokerPrivilegedMac::RouteWireFormatToAnother( |
| 208 const MachPortWireFormat& wire_format) { | 209 const MachPortWireFormat& wire_format) { |
| 209 DCHECK_NE(wire_format.destination_process, base::Process::Current().Pid()); | 210 DCHECK_NE(wire_format.destination_process, base::Process::Current().Pid()); |
| 210 | 211 |
| 211 // Another process is the destination. | 212 // Another process is the destination. |
| 212 base::ProcessId dest = wire_format.destination_process; | 213 base::ProcessId dest = wire_format.destination_process; |
| 214 base::AutoLock auto_lock(*get_lock()); |
| 213 Sender* sender = GetSenderWithProcessId(dest); | 215 Sender* sender = GetSenderWithProcessId(dest); |
| 214 if (!sender) { | 216 if (!sender) { |
| 215 // Assuming that this message was not sent from a malicious process, the | 217 // Assuming that this message was not sent from a malicious process, the |
| 216 // channel endpoint that would have received this message will block | 218 // channel endpoint that would have received this message will block |
| 217 // forever. | 219 // forever. |
| 218 LOG(ERROR) << "Failed to deliver brokerable attachment to process with id: " | 220 LOG(ERROR) << "Failed to deliver brokerable attachment to process with id: " |
| 219 << dest; | 221 << dest; |
| 220 LogError(DESTINATION_NOT_FOUND); | 222 LogError(DESTINATION_NOT_FOUND); |
| 221 return false; | 223 return false; |
| 222 } | 224 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 base::ProcessId pid) { | 314 base::ProcessId pid) { |
| 313 base::AutoLock l(precursors_lock_); | 315 base::AutoLock l(precursors_lock_); |
| 314 auto it = precursors_.find(pid); | 316 auto it = precursors_.find(pid); |
| 315 if (it == precursors_.end()) | 317 if (it == precursors_.end()) |
| 316 return; | 318 return; |
| 317 | 319 |
| 318 // Whether this process is the destination process. | 320 // Whether this process is the destination process. |
| 319 bool to_self = pid == base::GetCurrentProcId(); | 321 bool to_self = pid == base::GetCurrentProcId(); |
| 320 | 322 |
| 321 if (!to_self) { | 323 if (!to_self) { |
| 324 base::AutoLock auto_lock(*get_lock()); |
| 322 if (!GetSenderWithProcessId(pid)) { | 325 if (!GetSenderWithProcessId(pid)) { |
| 323 // If there is no sender, then the destination process is no longer | 326 // If there is no sender, then the destination process is no longer |
| 324 // running, or never existed to begin with. | 327 // running, or never existed to begin with. |
| 325 LogError(DESTINATION_NOT_FOUND); | 328 LogError(DESTINATION_NOT_FOUND); |
| 326 delete it->second; | 329 delete it->second; |
| 327 precursors_.erase(it); | 330 precursors_.erase(it); |
| 328 return; | 331 return; |
| 329 } | 332 } |
| 330 } | 333 } |
| 331 | 334 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 pid, base::mac::ScopedMachSendRight(port.release()), id)); | 383 pid, base::mac::ScopedMachSendRight(port.release()), id)); |
| 381 } | 384 } |
| 382 | 385 |
| 383 void AttachmentBrokerPrivilegedMac::ProcessExtractorsForProcess( | 386 void AttachmentBrokerPrivilegedMac::ProcessExtractorsForProcess( |
| 384 base::ProcessId pid) { | 387 base::ProcessId pid) { |
| 385 base::AutoLock l(extractors_lock_); | 388 base::AutoLock l(extractors_lock_); |
| 386 auto it = extractors_.find(pid); | 389 auto it = extractors_.find(pid); |
| 387 if (it == extractors_.end()) | 390 if (it == extractors_.end()) |
| 388 return; | 391 return; |
| 389 | 392 |
| 390 if (!GetSenderWithProcessId(pid)) { | 393 { |
| 391 // If there is no sender, then the source process is no longer running. | 394 base::AutoLock auto_lock(*get_lock()); |
| 392 LogError(ERROR_SOURCE_NOT_FOUND); | 395 if (!GetSenderWithProcessId(pid)) { |
| 393 delete it->second; | 396 // If there is no sender, then the source process is no longer running. |
| 394 extractors_.erase(it); | 397 LogError(ERROR_SOURCE_NOT_FOUND); |
| 395 return; | 398 delete it->second; |
| 399 extractors_.erase(it); |
| 400 return; |
| 401 } |
| 396 } | 402 } |
| 397 | 403 |
| 398 mach_port_t task_port = port_provider_->TaskForPid(pid); | 404 mach_port_t task_port = port_provider_->TaskForPid(pid); |
| 399 | 405 |
| 400 // It's possible that the source process has not yet provided the privileged | 406 // It's possible that the source process has not yet provided the privileged |
| 401 // process with its task port. | 407 // process with its task port. |
| 402 if (task_port == MACH_PORT_NULL) | 408 if (task_port == MACH_PORT_NULL) |
| 403 return; | 409 return; |
| 404 | 410 |
| 405 while (!it->second->empty()) { | 411 while (!it->second->empty()) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 434 | 440 |
| 435 auto it = extractors_.find(source_pid); | 441 auto it = extractors_.find(source_pid); |
| 436 if (it == extractors_.end()) | 442 if (it == extractors_.end()) |
| 437 extractors_[source_pid] = new ScopedVector<AttachmentExtractor>; | 443 extractors_[source_pid] = new ScopedVector<AttachmentExtractor>; |
| 438 | 444 |
| 439 extractors_[source_pid]->push_back( | 445 extractors_[source_pid]->push_back( |
| 440 new AttachmentExtractor(source_pid, dest_pid, port, id)); | 446 new AttachmentExtractor(source_pid, dest_pid, port, id)); |
| 441 } | 447 } |
| 442 | 448 |
| 443 } // namespace IPC | 449 } // namespace IPC |
| OLD | NEW |