OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/common/sandbox_mac.h" | 5 #include "chrome/common/sandbox_mac.h" |
6 | 6 |
7 #include "base/debug_util.h" | 7 #include "base/debug_util.h" |
8 | 8 |
9 #import <Cocoa/Cocoa.h> | 9 #import <Cocoa/Cocoa.h> |
10 extern "C" { | 10 extern "C" { |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 // passed in. | 248 // passed in. |
249 if (sandbox_type != SANDBOX_TYPE_UTILITY) { | 249 if (sandbox_type != SANDBOX_TYPE_UTILITY) { |
250 DCHECK(allowed_dir.empty()) | 250 DCHECK(allowed_dir.empty()) |
251 << "Only SANDBOX_TYPE_UTILITY allows a custom directory parameter."; | 251 << "Only SANDBOX_TYPE_UTILITY allows a custom directory parameter."; |
252 } | 252 } |
253 // We use a custom sandbox definition file to lock things down as | 253 // We use a custom sandbox definition file to lock things down as |
254 // tightly as possible. | 254 // tightly as possible. |
255 // TODO(jeremy): Look at using include syntax to unify common parts of sandbox | 255 // TODO(jeremy): Look at using include syntax to unify common parts of sandbox |
256 // definition files. | 256 // definition files. |
257 NSString* sandbox_config_filename = nil; | 257 NSString* sandbox_config_filename = nil; |
258 bool allow_nacl_lines = false; | |
259 switch (sandbox_type) { | 258 switch (sandbox_type) { |
260 case SANDBOX_TYPE_RENDERER: | 259 case SANDBOX_TYPE_RENDERER: |
261 sandbox_config_filename = @"renderer"; | 260 sandbox_config_filename = @"renderer"; |
262 break; | 261 break; |
263 case SANDBOX_TYPE_WORKER: | 262 case SANDBOX_TYPE_WORKER: |
264 sandbox_config_filename = @"worker"; | 263 sandbox_config_filename = @"worker"; |
265 break; | 264 break; |
266 case SANDBOX_TYPE_UTILITY: | 265 case SANDBOX_TYPE_UTILITY: |
267 sandbox_config_filename = @"utility"; | 266 sandbox_config_filename = @"utility"; |
268 break; | 267 break; |
269 case SANDBOX_TYPE_NACL_PLUGIN: | |
270 // The Native Client plugin is a standard renderer sandbox with some | |
271 // additional lines to support use of Unix sockets. | |
272 // TODO(msneck): Remove the use of Unix sockets from Native Client and | |
273 // then remove the associated rules from chrome/renderer/renderer.sb. | |
274 // See http://code.google.com/p/nativeclient/issues/detail?id=344 | |
275 sandbox_config_filename = @"renderer"; | |
276 allow_nacl_lines = true; | |
277 break; | |
278 case SANDBOX_TYPE_NACL_LOADER: | 268 case SANDBOX_TYPE_NACL_LOADER: |
279 // The Native Client loader is used for safeguarding the user's | 269 // The Native Client loader is used for safeguarding the user's |
280 // untrusted code within Native Client. | 270 // untrusted code within Native Client. |
281 // TODO(msneck): Remove the use of Unix sockets from Native Client and | |
282 // then decide on an appropriate sandbox type for the untrusted code. | |
283 // This might simply mean removing the Unix socket rules from | |
284 // chrome/browser/nacl_loader.sb or it might mean sharing the | |
285 // sandbox configuration with SANDBOX_TYPE_WORKER. | |
286 // See http://code.google.com/p/nativeclient/issues/detail?id=344 | |
287 sandbox_config_filename = @"nacl_loader"; | 271 sandbox_config_filename = @"nacl_loader"; |
288 break; | 272 break; |
289 default: | 273 default: |
290 NOTREACHED(); | 274 NOTREACHED(); |
291 return false; | 275 return false; |
292 } | 276 } |
293 | 277 |
294 // Read in the sandbox profile and the common prefix file. | 278 // Read in the sandbox profile and the common prefix file. |
295 NSString* common_sandbox_prefix_path = | 279 NSString* common_sandbox_prefix_path = |
296 [mac_util::MainAppBundle() pathForResource:@"common" | 280 [mac_util::MainAppBundle() pathForResource:@"common" |
(...skipping 29 matching lines...) Expand all Loading... |
326 | 310 |
327 // Enable verbose logging if enabled on the command line. | 311 // Enable verbose logging if enabled on the command line. |
328 // (see renderer.sb for details). | 312 // (see renderer.sb for details). |
329 const CommandLine *command_line = CommandLine::ForCurrentProcess(); | 313 const CommandLine *command_line = CommandLine::ForCurrentProcess(); |
330 if (command_line->HasSwitch(switches::kEnableSandboxLogging)) { | 314 if (command_line->HasSwitch(switches::kEnableSandboxLogging)) { |
331 sandbox_data = [sandbox_data | 315 sandbox_data = [sandbox_data |
332 stringByReplacingOccurrencesOfString:@";ENABLE_LOGGING" | 316 stringByReplacingOccurrencesOfString:@";ENABLE_LOGGING" |
333 withString:@""]; | 317 withString:@""]; |
334 } | 318 } |
335 | 319 |
336 // Enable Native Client lines if they are allowed. | |
337 if (allow_nacl_lines) { | |
338 sandbox_data = [sandbox_data | |
339 stringByReplacingOccurrencesOfString:@";NACL" | |
340 withString:@""]; | |
341 } | |
342 | |
343 if (!allowed_dir.empty()) { | 320 if (!allowed_dir.empty()) { |
344 // The sandbox only understands "real" paths. This resolving step is | 321 // The sandbox only understands "real" paths. This resolving step is |
345 // needed so the caller doesn't need to worry about things like /var | 322 // needed so the caller doesn't need to worry about things like /var |
346 // being a link to /private/var (like in the paths CreateNewTempDirectory() | 323 // being a link to /private/var (like in the paths CreateNewTempDirectory() |
347 // returns). | 324 // returns). |
348 FilePath allowed_dir_canonical(allowed_dir); | 325 FilePath allowed_dir_canonical(allowed_dir); |
349 GetCanonicalSandboxPath(&allowed_dir_canonical); | 326 GetCanonicalSandboxPath(&allowed_dir_canonical); |
350 | 327 |
351 std::string allowed_dir_escaped; | 328 std::string allowed_dir_escaped; |
352 if (!QuoteStringForRegex(allowed_dir_canonical.value(), | 329 if (!QuoteStringForRegex(allowed_dir_canonical.value(), |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 if (HANDLE_EINTR(fcntl(fd, F_GETPATH, canonical_path)) != 0) { | 402 if (HANDLE_EINTR(fcntl(fd, F_GETPATH, canonical_path)) != 0) { |
426 PLOG(FATAL) << "GetCanonicalSandboxPath() failed for: " | 403 PLOG(FATAL) << "GetCanonicalSandboxPath() failed for: " |
427 << path->value(); | 404 << path->value(); |
428 return; | 405 return; |
429 } | 406 } |
430 | 407 |
431 *path = FilePath(canonical_path); | 408 *path = FilePath(canonical_path); |
432 } | 409 } |
433 | 410 |
434 } // namespace sandbox | 411 } // namespace sandbox |
OLD | NEW |