| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/nacl/browser/nacl_process_host.h" | 5 #include "components/nacl/browser/nacl_process_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "components/nacl/common/nacl_messages.h" | 33 #include "components/nacl/common/nacl_messages.h" |
| 34 #include "components/nacl/common/nacl_process_type.h" | 34 #include "components/nacl/common/nacl_process_type.h" |
| 35 #include "components/nacl/common/nacl_switches.h" | 35 #include "components/nacl/common/nacl_switches.h" |
| 36 #include "content/public/browser/browser_child_process_host.h" | 36 #include "content/public/browser/browser_child_process_host.h" |
| 37 #include "content/public/browser/browser_ppapi_host.h" | 37 #include "content/public/browser/browser_ppapi_host.h" |
| 38 #include "content/public/browser/child_process_data.h" | 38 #include "content/public/browser/child_process_data.h" |
| 39 #include "content/public/browser/plugin_service.h" | 39 #include "content/public/browser/plugin_service.h" |
| 40 #include "content/public/common/child_process_host.h" | 40 #include "content/public/common/child_process_host.h" |
| 41 #include "content/public/common/content_switches.h" | 41 #include "content/public/common/content_switches.h" |
| 42 #include "content/public/common/process_type.h" | 42 #include "content/public/common/process_type.h" |
| 43 #include "content/public/common/sandboxed_process_launcher_delegate.h" |
| 43 #include "ipc/ipc_channel.h" | 44 #include "ipc/ipc_channel.h" |
| 44 #include "ipc/ipc_switches.h" | 45 #include "ipc/ipc_switches.h" |
| 45 #include "native_client/src/shared/imc/nacl_imc_c.h" | 46 #include "native_client/src/shared/imc/nacl_imc_c.h" |
| 46 #include "net/base/net_util.h" | 47 #include "net/base/net_util.h" |
| 47 #include "net/socket/tcp_listen_socket.h" | 48 #include "net/socket/tcp_listen_socket.h" |
| 48 #include "ppapi/host/host_factory.h" | 49 #include "ppapi/host/host_factory.h" |
| 49 #include "ppapi/host/ppapi_host.h" | 50 #include "ppapi/host/ppapi_host.h" |
| 50 #include "ppapi/proxy/ppapi_messages.h" | 51 #include "ppapi/proxy/ppapi_messages.h" |
| 51 #include "ppapi/shared_impl/ppapi_nacl_plugin_args.h" | 52 #include "ppapi/shared_impl/ppapi_nacl_plugin_args.h" |
| 52 #include "ppapi/shared_impl/ppapi_switches.h" | 53 #include "ppapi/shared_impl/ppapi_switches.h" |
| 53 | 54 |
| 54 #if defined(OS_POSIX) | 55 #if defined(OS_POSIX) |
| 55 #include <fcntl.h> | 56 #include <fcntl.h> |
| 56 | 57 |
| 57 #include "ipc/ipc_channel_posix.h" | 58 #include "ipc/ipc_channel_posix.h" |
| 58 #elif defined(OS_WIN) | 59 #elif defined(OS_WIN) |
| 59 #include <windows.h> | 60 #include <windows.h> |
| 60 | 61 |
| 61 #include "base/threading/thread.h" | 62 #include "base/threading/thread.h" |
| 62 #include "base/win/scoped_handle.h" | 63 #include "base/win/scoped_handle.h" |
| 63 #include "components/nacl/browser/nacl_broker_service_win.h" | 64 #include "components/nacl/browser/nacl_broker_service_win.h" |
| 64 #include "components/nacl/common/nacl_debug_exception_handler_win.h" | 65 #include "components/nacl/common/nacl_debug_exception_handler_win.h" |
| 65 #include "content/public/common/sandbox_init.h" | 66 #include "content/public/common/sandbox_init.h" |
| 66 #include "content/public/common/sandboxed_process_launcher_delegate.h" | |
| 67 #endif | 67 #endif |
| 68 | 68 |
| 69 using content::BrowserThread; | 69 using content::BrowserThread; |
| 70 using content::ChildProcessData; | 70 using content::ChildProcessData; |
| 71 using content::ChildProcessHost; | 71 using content::ChildProcessHost; |
| 72 using ppapi::proxy::SerializedHandle; | 72 using ppapi::proxy::SerializedHandle; |
| 73 | 73 |
| 74 #if defined(OS_WIN) | 74 #if defined(OS_WIN) |
| 75 | 75 |
| 76 namespace { | 76 namespace { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 #endif // defined(OS_WIN) | 138 #endif // defined(OS_WIN) |
| 139 | 139 |
| 140 namespace { | 140 namespace { |
| 141 | 141 |
| 142 #if defined(OS_WIN) | 142 #if defined(OS_WIN) |
| 143 bool RunningOnWOW64() { | 143 bool RunningOnWOW64() { |
| 144 return (base::win::OSInfo::GetInstance()->wow64_status() == | 144 return (base::win::OSInfo::GetInstance()->wow64_status() == |
| 145 base::win::OSInfo::WOW64_ENABLED); | 145 base::win::OSInfo::WOW64_ENABLED); |
| 146 } | 146 } |
| 147 #endif |
| 147 | 148 |
| 148 // NOTE: changes to this class need to be reviewed by the security team. | 149 // NOTE: changes to this class need to be reviewed by the security team. |
| 149 class NaClSandboxedProcessLauncherDelegate | 150 class NaClSandboxedProcessLauncherDelegate |
| 150 : public content::SandboxedProcessLauncherDelegate { | 151 : public content::SandboxedProcessLauncherDelegate { |
| 151 public: | 152 public: |
| 152 NaClSandboxedProcessLauncherDelegate() {} | 153 NaClSandboxedProcessLauncherDelegate(ChildProcessHost* host) |
| 154 #if defined(OS_POSIX) |
| 155 : ipc_fd_(host->TakeClientFileDescriptor()) |
| 156 #endif |
| 157 {} |
| 158 |
| 153 virtual ~NaClSandboxedProcessLauncherDelegate() {} | 159 virtual ~NaClSandboxedProcessLauncherDelegate() {} |
| 154 | 160 |
| 161 #if defined(OS_WIN) |
| 155 virtual void PostSpawnTarget(base::ProcessHandle process) { | 162 virtual void PostSpawnTarget(base::ProcessHandle process) { |
| 156 // For Native Client sel_ldr processes on 32-bit Windows, reserve 1 GB of | 163 // For Native Client sel_ldr processes on 32-bit Windows, reserve 1 GB of |
| 157 // address space to prevent later failure due to address space fragmentation | 164 // address space to prevent later failure due to address space fragmentation |
| 158 // from .dll loading. The NaCl process will attempt to locate this space by | 165 // from .dll loading. The NaCl process will attempt to locate this space by |
| 159 // scanning the address space using VirtualQuery. | 166 // scanning the address space using VirtualQuery. |
| 160 // TODO(bbudge) Handle the --no-sandbox case. | 167 // TODO(bbudge) Handle the --no-sandbox case. |
| 161 // http://code.google.com/p/nativeclient/issues/detail?id=2131 | 168 // http://code.google.com/p/nativeclient/issues/detail?id=2131 |
| 162 const SIZE_T kNaClSandboxSize = 1 << 30; | 169 const SIZE_T kNaClSandboxSize = 1 << 30; |
| 163 if (!nacl::AllocateAddressSpaceASLR(process, kNaClSandboxSize)) { | 170 if (!nacl::AllocateAddressSpaceASLR(process, kNaClSandboxSize)) { |
| 164 DLOG(WARNING) << "Failed to reserve address space for Native Client"; | 171 DLOG(WARNING) << "Failed to reserve address space for Native Client"; |
| 165 } | 172 } |
| 166 } | 173 } |
| 174 #elif defined(OS_POSIX) |
| 175 virtual bool ShouldUseZygote() OVERRIDE { |
| 176 return true; |
| 177 } |
| 178 virtual int GetIpcFd() OVERRIDE { |
| 179 return ipc_fd_; |
| 180 } |
| 181 #endif // OS_WIN |
| 182 |
| 183 private: |
| 184 #if defined(OS_POSIX) |
| 185 int ipc_fd_; |
| 186 #endif // OS_POSIX |
| 167 }; | 187 }; |
| 168 | 188 |
| 169 #endif // OS_WIN | |
| 170 | |
| 171 void SetCloseOnExec(NaClHandle fd) { | 189 void SetCloseOnExec(NaClHandle fd) { |
| 172 #if defined(OS_POSIX) | 190 #if defined(OS_POSIX) |
| 173 int flags = fcntl(fd, F_GETFD); | 191 int flags = fcntl(fd, F_GETFD); |
| 174 CHECK_NE(flags, -1); | 192 CHECK_NE(flags, -1); |
| 175 int rc = fcntl(fd, F_SETFD, flags | FD_CLOEXEC); | 193 int rc = fcntl(fd, F_SETFD, flags | FD_CLOEXEC); |
| 176 CHECK_EQ(rc, 0); | 194 CHECK_EQ(rc, 0); |
| 177 #endif | 195 #endif |
| 178 } | 196 } |
| 179 | 197 |
| 180 bool ShareHandleToSelLdr( | 198 bool ShareHandleToSelLdr( |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 cmd_line->AppendSwitch(switches::kNoErrorDialogs); | 588 cmd_line->AppendSwitch(switches::kNoErrorDialogs); |
| 571 | 589 |
| 572 // On Windows we might need to start the broker process to launch a new loader | 590 // On Windows we might need to start the broker process to launch a new loader |
| 573 #if defined(OS_WIN) | 591 #if defined(OS_WIN) |
| 574 if (RunningOnWOW64()) { | 592 if (RunningOnWOW64()) { |
| 575 if (!NaClBrokerService::GetInstance()->LaunchLoader( | 593 if (!NaClBrokerService::GetInstance()->LaunchLoader( |
| 576 weak_factory_.GetWeakPtr(), channel_id)) { | 594 weak_factory_.GetWeakPtr(), channel_id)) { |
| 577 SendErrorToRenderer("broker service did not launch process"); | 595 SendErrorToRenderer("broker service did not launch process"); |
| 578 return false; | 596 return false; |
| 579 } | 597 } |
| 580 } else { | 598 return true; |
| 581 process_->Launch(new NaClSandboxedProcessLauncherDelegate, | |
| 582 false, | |
| 583 cmd_line.release()); | |
| 584 } | 599 } |
| 585 #elif defined(OS_POSIX) | |
| 586 process_->Launch(true, // use_zygote | |
| 587 base::EnvironmentMap(), | |
| 588 cmd_line.release()); | |
| 589 #endif | 600 #endif |
| 590 | 601 process_->Launch( |
| 602 new NaClSandboxedProcessLauncherDelegate(process_->GetHost()), |
| 603 cmd_line.release()); |
| 591 return true; | 604 return true; |
| 592 } | 605 } |
| 593 | 606 |
| 594 bool NaClProcessHost::OnMessageReceived(const IPC::Message& msg) { | 607 bool NaClProcessHost::OnMessageReceived(const IPC::Message& msg) { |
| 595 bool handled = true; | 608 bool handled = true; |
| 596 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg) | 609 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg) |
| 597 IPC_MESSAGE_HANDLER(NaClProcessMsg_QueryKnownToValidate, | 610 IPC_MESSAGE_HANDLER(NaClProcessMsg_QueryKnownToValidate, |
| 598 OnQueryKnownToValidate) | 611 OnQueryKnownToValidate) |
| 599 IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate, | 612 IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate, |
| 600 OnSetKnownToValidate) | 613 OnSetKnownToValidate) |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1057 process_handle.Take(), info, | 1070 process_handle.Take(), info, |
| 1058 base::MessageLoopProxy::current(), | 1071 base::MessageLoopProxy::current(), |
| 1059 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 1072 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
| 1060 weak_factory_.GetWeakPtr())); | 1073 weak_factory_.GetWeakPtr())); |
| 1061 return true; | 1074 return true; |
| 1062 } | 1075 } |
| 1063 } | 1076 } |
| 1064 #endif | 1077 #endif |
| 1065 | 1078 |
| 1066 } // namespace nacl | 1079 } // namespace nacl |
| OLD | NEW |