Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: ipc/attachment_broker_win.cc

Issue 1262543003: ipc: Create an unforgeable mechanism to get the process id of the sender. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove dchecks. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ipc/attachment_broker_privileged_win.cc ('k') | ipc/ipc_channel_nacl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_win.h" 5 #include "ipc/attachment_broker_win.h"
6 6
7 #include "base/process/process.h" 7 #include "base/process/process.h"
8 #include "ipc/attachment_broker_messages.h" 8 #include "ipc/attachment_broker_messages.h"
9 #include "ipc/brokerable_attachment.h" 9 #include "ipc/brokerable_attachment.h"
10 #include "ipc/handle_attachment_win.h" 10 #include "ipc/handle_attachment_win.h"
11 #include "ipc/ipc_sender.h" 11 #include "ipc/ipc_sender.h"
12 12
13 namespace IPC { 13 namespace IPC {
14 14
15 AttachmentBrokerWin::AttachmentBrokerWin() { 15 AttachmentBrokerWin::AttachmentBrokerWin() {
16 } 16 }
17 17
18 AttachmentBrokerWin::~AttachmentBrokerWin() { 18 AttachmentBrokerWin::~AttachmentBrokerWin() {
19 } 19 }
20 20
21 bool AttachmentBrokerWin::SendAttachmentToProcess( 21 bool AttachmentBrokerWin::SendAttachmentToProcess(
22 const BrokerableAttachment* attachment, 22 const BrokerableAttachment* attachment,
23 base::ProcessId destination_process) { 23 base::ProcessId destination_process) {
24 switch (attachment->GetBrokerableType()) { 24 switch (attachment->GetBrokerableType()) {
25 case BrokerableAttachment::WIN_HANDLE: 25 case BrokerableAttachment::WIN_HANDLE:
26 const internal::HandleAttachmentWin* handle_attachment = 26 const internal::HandleAttachmentWin* handle_attachment =
27 static_cast<const internal::HandleAttachmentWin*>(attachment); 27 static_cast<const internal::HandleAttachmentWin*>(attachment);
28 internal::HandleAttachmentWin::WireFormat format = 28 internal::HandleAttachmentWin::WireFormat format =
29 handle_attachment->GetWireFormat(destination_process); 29 handle_attachment->GetWireFormat(destination_process);
30 // TODO(erikchen): Replace the call to base::Process::Current().Pid() with 30 return sender_->Send(new AttachmentBrokerMsg_DuplicateWinHandle(format));
31 // a non-forgeable mechanism. http://crbug.com/513431.
32 return sender_->Send(new AttachmentBrokerMsg_DuplicateWinHandle(
33 format, base::Process::Current().Pid()));
34 } 31 }
35 return false; 32 return false;
36 } 33 }
37 34
38 bool AttachmentBrokerWin::OnMessageReceived(const Message& msg) { 35 bool AttachmentBrokerWin::OnMessageReceived(const Message& msg) {
39 bool handled = true; 36 bool handled = true;
40 IPC_BEGIN_MESSAGE_MAP(AttachmentBrokerWin, msg) 37 IPC_BEGIN_MESSAGE_MAP(AttachmentBrokerWin, msg)
41 IPC_MESSAGE_HANDLER(AttachmentBrokerMsg_WinHandleHasBeenDuplicated, 38 IPC_MESSAGE_HANDLER(AttachmentBrokerMsg_WinHandleHasBeenDuplicated,
42 OnWinHandleHasBeenDuplicated) 39 OnWinHandleHasBeenDuplicated)
43 IPC_MESSAGE_UNHANDLED(handled = false) 40 IPC_MESSAGE_UNHANDLED(handled = false)
44 IPC_END_MESSAGE_MAP() 41 IPC_END_MESSAGE_MAP()
45 return handled; 42 return handled;
46 } 43 }
47 44
48 void AttachmentBrokerWin::OnWinHandleHasBeenDuplicated( 45 void AttachmentBrokerWin::OnWinHandleHasBeenDuplicated(
49 const IPC::internal::HandleAttachmentWin::WireFormat& wire_format) { 46 const IPC::internal::HandleAttachmentWin::WireFormat& wire_format) {
50 // The IPC message was intended for a different process. Ignore it. 47 // The IPC message was intended for a different process. Ignore it.
51 if (wire_format.destination_process != base::Process::Current().Pid()) 48 if (wire_format.destination_process != base::Process::Current().Pid())
52 return; 49 return;
53 50
54 scoped_refptr<BrokerableAttachment> attachment( 51 scoped_refptr<BrokerableAttachment> attachment(
55 new IPC::internal::HandleAttachmentWin(wire_format)); 52 new IPC::internal::HandleAttachmentWin(wire_format));
56 HandleReceivedAttachment(attachment); 53 HandleReceivedAttachment(attachment);
57 } 54 }
58 55
59 } // namespace IPC 56 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/attachment_broker_privileged_win.cc ('k') | ipc/ipc_channel_nacl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698