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 "chrome/browser/nacl_host/nacl_file_host.h" | 5 #include "chrome/browser/nacl_host/nacl_file_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/platform_file.h" | 11 #include "base/platform_file.h" |
12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/extensions/extension_info_map.h" | 14 #include "chrome/browser/extensions/extension_info_map.h" |
| 15 #include "chrome/browser/nacl_host/nacl_browser.h" |
15 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" | 16 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
16 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
17 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
18 #include "chrome/common/extensions/extension_file_util.h" | 19 #include "chrome/common/extensions/extension_file_util.h" |
19 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h" | 20 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h" |
20 #include "chrome/common/render_messages.h" | 21 #include "chrome/common/render_messages.h" |
21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/render_view_host.h" | 23 #include "content/public/browser/render_view_host.h" |
23 #include "content/public/browser/site_instance.h" | 24 #include "content/public/browser/site_instance.h" |
24 #include "ipc/ipc_platform_file.h" | 25 #include "ipc/ipc_platform_file.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 if (target_desc == IPC::InvalidPlatformFileForTransit()) { | 124 if (target_desc == IPC::InvalidPlatformFileForTransit()) { |
124 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 125 NotifyRendererOfError(chrome_render_message_filter, reply_msg); |
125 return; | 126 return; |
126 } | 127 } |
127 | 128 |
128 ChromeViewHostMsg_NaClCreateTemporaryFile::WriteReplyParams( | 129 ChromeViewHostMsg_NaClCreateTemporaryFile::WriteReplyParams( |
129 reply_msg, target_desc); | 130 reply_msg, target_desc); |
130 chrome_render_message_filter->Send(reply_msg); | 131 chrome_render_message_filter->Send(reply_msg); |
131 } | 132 } |
132 | 133 |
| 134 void DoRegisterOpenedNaClExecutableFile( |
| 135 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, |
| 136 base::PlatformFile file, |
| 137 base::FilePath file_path, |
| 138 IPC::Message* reply_msg) { |
| 139 // IO thread owns the NaClBrowser singleton. |
| 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 141 |
| 142 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); |
| 143 uint64_t file_token_lo = 0; |
| 144 uint64_t file_token_hi = 0; |
| 145 nacl_browser->PutFilePath(file_path, &file_token_lo, &file_token_hi); |
| 146 |
| 147 IPC::PlatformFileForTransit file_desc = IPC::GetFileHandleForProcess( |
| 148 file, |
| 149 chrome_render_message_filter->peer_handle(), |
| 150 true /* close_source */); |
| 151 |
| 152 ChromeViewHostMsg_OpenNaClExecutable::WriteReplyParams( |
| 153 reply_msg, file_desc, file_token_lo, file_token_hi); |
| 154 chrome_render_message_filter->Send(reply_msg); |
| 155 } |
| 156 |
133 // Convert the file URL into a file path in the extension directory. | 157 // Convert the file URL into a file path in the extension directory. |
134 // This function is security sensitive. Be sure to check with a security | 158 // This function is security sensitive. Be sure to check with a security |
135 // person before you modify it. | 159 // person before you modify it. |
136 bool GetExtensionFilePath( | 160 bool GetExtensionFilePath( |
137 scoped_refptr<ExtensionInfoMap> extension_info_map, | 161 scoped_refptr<ExtensionInfoMap> extension_info_map, |
138 const GURL& file_url, | 162 const GURL& file_url, |
139 base::FilePath* file_path) { | 163 base::FilePath* file_path) { |
140 // Check that the URL is recognized by the extension system. | 164 // Check that the URL is recognized by the extension system. |
141 const extensions::Extension* extension = | 165 const extensions::Extension* extension = |
142 extension_info_map->extensions().GetExtensionOrAppByURL( | 166 extension_info_map->extensions().GetExtensionOrAppByURL( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 const GURL& file_url, | 213 const GURL& file_url, |
190 IPC::Message* reply_msg) { | 214 IPC::Message* reply_msg) { |
191 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 215 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
192 | 216 |
193 base::FilePath file_path; | 217 base::FilePath file_path; |
194 if (!GetExtensionFilePath(extension_info_map, file_url, &file_path)) { | 218 if (!GetExtensionFilePath(extension_info_map, file_url, &file_path)) { |
195 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 219 NotifyRendererOfError(chrome_render_message_filter, reply_msg); |
196 return; | 220 return; |
197 } | 221 } |
198 | 222 |
199 // Get a file descriptor. On Windows, we need 'GENERIC_EXECUTE' in order to | 223 base::PlatformFile file; |
200 // memory map the executable. | 224 nacl::OpenNaClExecutableImpl(file_path, &file); |
201 // IMPORTANT: This file descriptor must not have write access - that could | 225 if (file != base::kInvalidPlatformFileValue) { |
202 // allow a sandbox escape. | 226 // This function is running on the blocking pool, but the path needs to be |
203 base::PlatformFileError error_code; | 227 // registered in a structure owned by the IO thread. |
204 base::PlatformFile file = base::CreatePlatformFile( | 228 BrowserThread::PostTask( |
205 file_path, | 229 BrowserThread::IO, FROM_HERE, |
206 base::PLATFORM_FILE_OPEN | | 230 base::Bind( |
207 base::PLATFORM_FILE_READ | | 231 &DoRegisterOpenedNaClExecutableFile, |
208 base::PLATFORM_FILE_EXECUTE, // Windows only flag. | 232 chrome_render_message_filter, |
209 NULL, | 233 file, file_path, reply_msg)); |
210 &error_code); | 234 } else { |
211 if (error_code != base::PLATFORM_FILE_OK) { | |
212 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 235 NotifyRendererOfError(chrome_render_message_filter, reply_msg); |
213 return; | 236 return; |
214 } | 237 } |
215 // Check that the file does not reference a directory. Returning a descriptor | |
216 // to an extension directory could allow a sandbox escape. | |
217 base::PlatformFileInfo file_info; | |
218 if (!base::GetPlatformFileInfo(file, &file_info) || file_info.is_directory) | |
219 { | |
220 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | |
221 return; | |
222 } | |
223 | |
224 IPC::PlatformFileForTransit file_desc = IPC::GetFileHandleForProcess( | |
225 file, | |
226 chrome_render_message_filter->peer_handle(), | |
227 true /* close_source */); | |
228 | |
229 ChromeViewHostMsg_OpenNaClExecutable::WriteReplyParams( | |
230 reply_msg, file_path, file_desc); | |
231 chrome_render_message_filter->Send(reply_msg); | |
232 } | 238 } |
233 | 239 |
234 } // namespace | 240 } // namespace |
235 | 241 |
236 namespace nacl_file_host { | 242 namespace nacl_file_host { |
237 | 243 |
238 void GetReadonlyPnaclFd( | 244 void GetReadonlyPnaclFd( |
239 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, | 245 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, |
240 const std::string& filename, | 246 const std::string& filename, |
241 IPC::Message* reply_msg) { | 247 IPC::Message* reply_msg) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 base::Bind( | 342 base::Bind( |
337 &DoOpenNaClExecutableOnThreadPool, | 343 &DoOpenNaClExecutableOnThreadPool, |
338 chrome_render_message_filter, | 344 chrome_render_message_filter, |
339 extension_info_map, | 345 extension_info_map, |
340 file_url, reply_msg))) { | 346 file_url, reply_msg))) { |
341 NotifyRendererOfError(chrome_render_message_filter, reply_msg); | 347 NotifyRendererOfError(chrome_render_message_filter, reply_msg); |
342 } | 348 } |
343 } | 349 } |
344 | 350 |
345 } // namespace nacl_file_host | 351 } // namespace nacl_file_host |
OLD | NEW |