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

Side by Side Diff: chrome/browser/nacl_host/nacl_file_host.cc

Issue 14750007: NaCl: enable meta-based validation for shared libraries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More edits Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
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
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 DoOpenNaClExecutableRegister(
Mark Seaborn 2013/05/16 23:01:47 Not sure I understand the name, since it suggests
Nick Bray (chromium) 2013/05/21 20:09:06 Done.
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 nonce = nacl_browser->PutFilePath(file_path);
144
145 IPC::PlatformFileForTransit file_desc = IPC::GetFileHandleForProcess(
146 file,
147 chrome_render_message_filter->peer_handle(),
148 true /* close_source */);
149
150 ChromeViewHostMsg_OpenNaClExecutable::WriteReplyParams(
151 reply_msg, file_desc, nonce);
152 chrome_render_message_filter->Send(reply_msg);
153 }
154
133 // Convert the file URL into a file path in the extension directory. 155 // 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 156 // This function is security sensitive. Be sure to check with a security
135 // person before you modify it. 157 // person before you modify it.
136 bool GetExtensionFilePath( 158 bool GetExtensionFilePath(
137 scoped_refptr<ExtensionInfoMap> extension_info_map, 159 scoped_refptr<ExtensionInfoMap> extension_info_map,
138 const GURL& file_url, 160 const GURL& file_url,
139 base::FilePath* file_path) { 161 base::FilePath* file_path) {
140 // Check that the URL is recognized by the extension system. 162 // Check that the URL is recognized by the extension system.
141 const extensions::Extension* extension = 163 const extensions::Extension* extension =
142 extension_info_map->extensions().GetExtensionOrAppByURL( 164 extension_info_map->extensions().GetExtensionOrAppByURL(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 const GURL& file_url, 211 const GURL& file_url,
190 IPC::Message* reply_msg) { 212 IPC::Message* reply_msg) {
191 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 213 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
192 214
193 base::FilePath file_path; 215 base::FilePath file_path;
194 if (!GetExtensionFilePath(extension_info_map, file_url, &file_path)) { 216 if (!GetExtensionFilePath(extension_info_map, file_url, &file_path)) {
195 NotifyRendererOfError(chrome_render_message_filter, reply_msg); 217 NotifyRendererOfError(chrome_render_message_filter, reply_msg);
196 return; 218 return;
197 } 219 }
198 220
199 // Get a file descriptor. On Windows, we need 'GENERIC_EXECUTE' in order to 221 base::PlatformFile file;
200 // memory map the executable. 222 nacl::OpenNaClExecutableImpl(file_path, &file);
201 // IMPORTANT: This file descriptor must not have write access - that could 223 if (file != base::kInvalidPlatformFileValue) {
202 // allow a sandbox escape. 224 BrowserThread::PostTask(
203 base::PlatformFileError error_code; 225 BrowserThread::IO, FROM_HERE,
204 base::PlatformFile file = base::CreatePlatformFile( 226 base::Bind(
Mark Seaborn 2013/05/16 23:01:47 Why does this need a PostTask() now? Is the Creat
Nick Bray (chromium) 2013/05/21 20:09:06 Done.
205 file_path, 227 &DoOpenNaClExecutableRegister,
206 base::PLATFORM_FILE_OPEN | 228 chrome_render_message_filter,
207 base::PLATFORM_FILE_READ | 229 file, file_path, reply_msg));
208 base::PLATFORM_FILE_EXECUTE, // Windows only flag. 230 } else {
209 NULL,
210 &error_code);
211 if (error_code != base::PLATFORM_FILE_OK) {
212 NotifyRendererOfError(chrome_render_message_filter, reply_msg); 231 NotifyRendererOfError(chrome_render_message_filter, reply_msg);
213 return; 232 return;
214 } 233 }
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 } 234 }
233 235
234 } // namespace 236 } // namespace
235 237
236 namespace nacl_file_host { 238 namespace nacl_file_host {
237 239
238 void GetReadonlyPnaclFd( 240 void GetReadonlyPnaclFd(
239 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter, 241 scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter,
240 const std::string& filename, 242 const std::string& filename,
241 IPC::Message* reply_msg) { 243 IPC::Message* reply_msg) {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 base::Bind( 338 base::Bind(
337 &DoOpenNaClExecutableOnThreadPool, 339 &DoOpenNaClExecutableOnThreadPool,
338 chrome_render_message_filter, 340 chrome_render_message_filter,
339 extension_info_map, 341 extension_info_map,
340 file_url, reply_msg))) { 342 file_url, reply_msg))) {
341 NotifyRendererOfError(chrome_render_message_filter, reply_msg); 343 NotifyRendererOfError(chrome_render_message_filter, reply_msg);
342 } 344 }
343 } 345 }
344 346
345 } // namespace nacl_file_host 347 } // namespace nacl_file_host
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698