| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <tuple> | 9 #include <tuple> |
| 10 | 10 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 HandleReceivedAttachment(attachment); | 167 HandleReceivedAttachment(attachment); |
| 168 } | 168 } |
| 169 | 169 |
| 170 bool AttachmentBrokerPrivilegedMac::RouteWireFormatToAnother( | 170 bool AttachmentBrokerPrivilegedMac::RouteWireFormatToAnother( |
| 171 const MachPortWireFormat& wire_format) { | 171 const MachPortWireFormat& wire_format) { |
| 172 DCHECK_NE(wire_format.destination_process, base::Process::Current().Pid()); | 172 DCHECK_NE(wire_format.destination_process, base::Process::Current().Pid()); |
| 173 | 173 |
| 174 // Another process is the destination. | 174 // Another process is the destination. |
| 175 base::ProcessId dest = wire_format.destination_process; | 175 base::ProcessId dest = wire_format.destination_process; |
| 176 base::AutoLock auto_lock(*get_lock()); | 176 base::AutoLock auto_lock(*get_lock()); |
| 177 Sender* sender = GetSenderWithProcessId(dest); | 177 AttachmentBrokerPrivileged::EndpointRunnerPair pair = |
| 178 if (!sender) { | 178 GetSenderWithProcessId(dest); |
| 179 if (!pair.first) { |
| 179 // Assuming that this message was not sent from a malicious process, the | 180 // Assuming that this message was not sent from a malicious process, the |
| 180 // channel endpoint that would have received this message will block | 181 // channel endpoint that would have received this message will block |
| 181 // forever. | 182 // forever. |
| 182 LOG(ERROR) << "Failed to deliver brokerable attachment to process with id: " | 183 LOG(ERROR) << "Failed to deliver brokerable attachment to process with id: " |
| 183 << dest; | 184 << dest; |
| 184 LogError(DESTINATION_NOT_FOUND); | 185 LogError(DESTINATION_NOT_FOUND); |
| 185 return false; | 186 return false; |
| 186 } | 187 } |
| 187 | 188 |
| 188 LogError(DESTINATION_FOUND); | 189 LogError(DESTINATION_FOUND); |
| 189 sender->Send(new AttachmentBrokerMsg_MachPortHasBeenDuplicated(wire_format)); | 190 SendMessageToEndpoint( |
| 191 pair, new AttachmentBrokerMsg_MachPortHasBeenDuplicated(wire_format)); |
| 190 return true; | 192 return true; |
| 191 } | 193 } |
| 192 | 194 |
| 193 base::mac::ScopedMachSendRight AttachmentBrokerPrivilegedMac::ExtractNamedRight( | 195 base::mac::ScopedMachSendRight AttachmentBrokerPrivilegedMac::ExtractNamedRight( |
| 194 mach_port_t task_port, | 196 mach_port_t task_port, |
| 195 mach_port_name_t named_right) { | 197 mach_port_name_t named_right) { |
| 196 mach_port_t extracted_right = MACH_PORT_NULL; | 198 mach_port_t extracted_right = MACH_PORT_NULL; |
| 197 mach_msg_type_name_t extracted_right_type; | 199 mach_msg_type_name_t extracted_right_type; |
| 198 kern_return_t kr = | 200 kern_return_t kr = |
| 199 mach_port_extract_right(task_port, named_right, MACH_MSG_TYPE_MOVE_SEND, | 201 mach_port_extract_right(task_port, named_right, MACH_MSG_TYPE_MOVE_SEND, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 222 base::AutoLock l(precursors_lock_); | 224 base::AutoLock l(precursors_lock_); |
| 223 auto it = precursors_.find(pid); | 225 auto it = precursors_.find(pid); |
| 224 if (it == precursors_.end()) | 226 if (it == precursors_.end()) |
| 225 return; | 227 return; |
| 226 | 228 |
| 227 // Whether this process is the destination process. | 229 // Whether this process is the destination process. |
| 228 bool to_self = pid == base::GetCurrentProcId(); | 230 bool to_self = pid == base::GetCurrentProcId(); |
| 229 | 231 |
| 230 if (!to_self) { | 232 if (!to_self) { |
| 231 base::AutoLock auto_lock(*get_lock()); | 233 base::AutoLock auto_lock(*get_lock()); |
| 232 if (!GetSenderWithProcessId(pid)) { | 234 AttachmentBrokerPrivileged::EndpointRunnerPair pair = |
| 235 GetSenderWithProcessId(pid); |
| 236 if (!pair.first) { |
| 233 // If there is no sender, then the destination process is no longer | 237 // If there is no sender, then the destination process is no longer |
| 234 // running, or never existed to begin with. | 238 // running, or never existed to begin with. |
| 235 LogError(DESTINATION_NOT_FOUND); | 239 LogError(DESTINATION_NOT_FOUND); |
| 236 delete it->second; | 240 delete it->second; |
| 237 precursors_.erase(it); | 241 precursors_.erase(it); |
| 238 return; | 242 return; |
| 239 } | 243 } |
| 240 } | 244 } |
| 241 | 245 |
| 242 mach_port_t task_port = port_provider_->TaskForPid(pid); | 246 mach_port_t task_port = port_provider_->TaskForPid(pid); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 316 |
| 313 void AttachmentBrokerPrivilegedMac::ProcessExtractorsForProcess( | 317 void AttachmentBrokerPrivilegedMac::ProcessExtractorsForProcess( |
| 314 base::ProcessId pid) { | 318 base::ProcessId pid) { |
| 315 base::AutoLock l(extractors_lock_); | 319 base::AutoLock l(extractors_lock_); |
| 316 auto it = extractors_.find(pid); | 320 auto it = extractors_.find(pid); |
| 317 if (it == extractors_.end()) | 321 if (it == extractors_.end()) |
| 318 return; | 322 return; |
| 319 | 323 |
| 320 { | 324 { |
| 321 base::AutoLock auto_lock(*get_lock()); | 325 base::AutoLock auto_lock(*get_lock()); |
| 322 if (!GetSenderWithProcessId(pid)) { | 326 AttachmentBrokerPrivileged::EndpointRunnerPair pair = |
| 327 GetSenderWithProcessId(pid); |
| 328 if (!pair.first) { |
| 323 // If there is no sender, then the source process is no longer running. | 329 // If there is no sender, then the source process is no longer running. |
| 324 LogError(ERROR_SOURCE_NOT_FOUND); | 330 LogError(ERROR_SOURCE_NOT_FOUND); |
| 325 delete it->second; | 331 delete it->second; |
| 326 extractors_.erase(it); | 332 extractors_.erase(it); |
| 327 return; | 333 return; |
| 328 } | 334 } |
| 329 } | 335 } |
| 330 | 336 |
| 331 mach_port_t task_port = port_provider_->TaskForPid(pid); | 337 mach_port_t task_port = port_provider_->TaskForPid(pid); |
| 332 | 338 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 373 |
| 368 auto it = extractors_.find(source_pid); | 374 auto it = extractors_.find(source_pid); |
| 369 if (it == extractors_.end()) | 375 if (it == extractors_.end()) |
| 370 extractors_[source_pid] = new ScopedVector<AttachmentExtractor>; | 376 extractors_[source_pid] = new ScopedVector<AttachmentExtractor>; |
| 371 | 377 |
| 372 extractors_[source_pid]->push_back( | 378 extractors_[source_pid]->push_back( |
| 373 new AttachmentExtractor(source_pid, dest_pid, port, id)); | 379 new AttachmentExtractor(source_pid, dest_pid, port, id)); |
| 374 } | 380 } |
| 375 | 381 |
| 376 } // namespace IPC | 382 } // namespace IPC |
| OLD | NEW |