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

Side by Side Diff: content/common/sandbox_mac.mm

Issue 469383002: Fix Mac sandbox meta data access (reland) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Typo fix Created 6 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 | « content/common/sandbox_mac.h ('k') | content/common/sandbox_mac_diraccess_unittest.mm » ('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 (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 "content/common/sandbox_mac.h" 5 #include "content/common/sandbox_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include <CoreFoundation/CFTimeZone.h> 9 #include <CoreFoundation/CFTimeZone.h>
10 extern "C" { 10 extern "C" {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 DLOG(FATAL) << "String quoting failed " << bad_string; 107 DLOG(FATAL) << "String quoting failed " << bad_string;
108 } 108 }
109 109
110 } // namespace 110 } // namespace
111 111
112 // static 112 // static
113 NSString* Sandbox::AllowMetadataForPath(const base::FilePath& allowed_path) { 113 NSString* Sandbox::AllowMetadataForPath(const base::FilePath& allowed_path) {
114 // Collect a list of all parent directories. 114 // Collect a list of all parent directories.
115 base::FilePath last_path = allowed_path; 115 base::FilePath last_path = allowed_path;
116 std::vector<base::FilePath> subpaths; 116 std::vector<base::FilePath> subpaths;
117 for (base::FilePath path = allowed_path; 117
118 path.value() != last_path.value(); 118 base::FilePath path = allowed_path;
119 path = path.DirName()) { 119 do {
120 subpaths.push_back(path); 120 subpaths.push_back(path);
121
121 last_path = path; 122 last_path = path;
122 } 123 path = path.DirName();
124 } while (path.value() != last_path.value());
123 125
124 // Iterate through all parents and allow stat() on them explicitly. 126 // Iterate through all parents and allow stat() on them explicitly.
125 NSString* sandbox_command = @"(allow file-read-metadata "; 127 NSString* sandbox_command = @"(allow file-read-metadata ";
126 for (std::vector<base::FilePath>::reverse_iterator i = subpaths.rbegin(); 128 for (std::vector<base::FilePath>::reverse_iterator i = subpaths.rbegin();
127 i != subpaths.rend(); 129 i != subpaths.rend();
128 ++i) { 130 ++i) {
129 std::string subdir_escaped; 131 std::string subdir_escaped;
130 if (!QuotePlainString(i->value(), &subdir_escaped)) { 132 if (!QuotePlainString(i->value(), &subdir_escaped)) {
131 FatalStringQuoteException(i->value()); 133 FatalStringQuoteException(i->value());
132 return nil; 134 return nil;
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 substitutions["COMPONENT_BUILD_WORKAROUND"] = SandboxSubstring(""); 565 substitutions["COMPONENT_BUILD_WORKAROUND"] = SandboxSubstring("");
564 #if defined(COMPONENT_BUILD) 566 #if defined(COMPONENT_BUILD)
565 // dlopen() fails without file-read-metadata access if the executable image 567 // dlopen() fails without file-read-metadata access if the executable image
566 // contains LC_RPATH load commands. The components build uses those. 568 // contains LC_RPATH load commands. The components build uses those.
567 // See http://crbug.com/127465 569 // See http://crbug.com/127465
568 if (base::mac::IsOSSnowLeopard()) { 570 if (base::mac::IsOSSnowLeopard()) {
569 base::FilePath bundle_executable = base::mac::NSStringToFilePath( 571 base::FilePath bundle_executable = base::mac::NSStringToFilePath(
570 [base::mac::MainBundle() executablePath]); 572 [base::mac::MainBundle() executablePath]);
571 NSString* sandbox_command = AllowMetadataForPath( 573 NSString* sandbox_command = AllowMetadataForPath(
572 GetCanonicalSandboxPath(bundle_executable)); 574 GetCanonicalSandboxPath(bundle_executable));
575
576 // In addition to the workaround above, for OS X <= 10.6 we also need to
577 // allow reading file metadata for all the dylibs under the same directory
578 // containing the Chrome bundle. It requires to go 5 levels up from main
579 // bundle path because the main bundle here is the Helper.app bundle.
580 base::FilePath product_path = base::mac::MainBundlePath()
581 .DirName()
582 .DirName()
583 .DirName()
584 .DirName()
585 .DirName();
586 sandbox_command = [sandbox_command
587 stringByAppendingFormat:
588 @"(allow file-read-metadata (regex #\"^%@/.*\\.dylib$\"))",
589 base::mac::FilePathToNSString(product_path)];
590
573 substitutions["COMPONENT_BUILD_WORKAROUND"] = 591 substitutions["COMPONENT_BUILD_WORKAROUND"] =
574 SandboxSubstring(base::SysNSStringToUTF8(sandbox_command)); 592 SandboxSubstring(base::SysNSStringToUTF8(sandbox_command));
575 } 593 }
576 #endif 594 #endif
577 595
578 // All information needed to assemble the final profile has been collected. 596 // All information needed to assemble the final profile has been collected.
579 // Merge it all together. 597 // Merge it all together.
580 std::string final_sandbox_profile_str; 598 std::string final_sandbox_profile_str;
581 if (!PostProcessSandboxProfile(sandbox_data, tokens_to_remove, substitutions, 599 if (!PostProcessSandboxProfile(sandbox_data, tokens_to_remove, substitutions,
582 &final_sandbox_profile_str)) { 600 &final_sandbox_profile_str)) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 if (HANDLE_EINTR(fcntl(fd.get(), F_GETPATH, canonical_path)) != 0) { 632 if (HANDLE_EINTR(fcntl(fd.get(), F_GETPATH, canonical_path)) != 0) {
615 DPLOG(FATAL) << "GetCanonicalSandboxPath() failed for: " 633 DPLOG(FATAL) << "GetCanonicalSandboxPath() failed for: "
616 << path.value(); 634 << path.value();
617 return path; 635 return path;
618 } 636 }
619 637
620 return base::FilePath(canonical_path); 638 return base::FilePath(canonical_path);
621 } 639 }
622 640
623 } // namespace content 641 } // namespace content
OLDNEW
« no previous file with comments | « content/common/sandbox_mac.h ('k') | content/common/sandbox_mac_diraccess_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698