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 "content/browser/child_process_security_policy_impl.h" | 5 #include "content/browser/child_process_security_policy_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 // Used internally only. These bit positions have no relationship to any | 34 // Used internally only. These bit positions have no relationship to any |
35 // underlying OS and can be changed to accommodate finer-grained permissions. | 35 // underlying OS and can be changed to accommodate finer-grained permissions. |
36 enum ChildProcessSecurityPermissions { | 36 enum ChildProcessSecurityPermissions { |
37 READ_FILE_PERMISSION = 1 << 0, | 37 READ_FILE_PERMISSION = 1 << 0, |
38 WRITE_FILE_PERMISSION = 1 << 1, | 38 WRITE_FILE_PERMISSION = 1 << 1, |
39 CREATE_NEW_FILE_PERMISSION = 1 << 2, | 39 CREATE_NEW_FILE_PERMISSION = 1 << 2, |
40 CREATE_OVERWRITE_FILE_PERMISSION = 1 << 3, | 40 CREATE_OVERWRITE_FILE_PERMISSION = 1 << 3, |
| 41 DELETE_FILE_PERMISSION = 1 << 4, |
41 | 42 |
42 // Used by Media Galleries API | 43 // Used by Media Galleries API |
43 COPY_INTO_FILE_PERMISSION = 1 << 4, | 44 COPY_INTO_FILE_PERMISSION = 1 << 5, |
44 }; | 45 }; |
45 | 46 |
46 // Used internally only. Bitmasks that are actually used by the Grant* and Can* | 47 // Used internally only. Bitmasks that are actually used by the Grant* and Can* |
47 // methods. These contain one or more ChildProcessSecurityPermissions. | 48 // methods. These contain one or more ChildProcessSecurityPermissions. |
48 enum ChildProcessSecurityGrants { | 49 enum ChildProcessSecurityGrants { |
49 READ_FILE_GRANT = READ_FILE_PERMISSION, | 50 READ_FILE_GRANT = READ_FILE_PERMISSION, |
50 WRITE_FILE_GRANT = WRITE_FILE_PERMISSION, | 51 WRITE_FILE_GRANT = WRITE_FILE_PERMISSION, |
51 | 52 |
52 CREATE_NEW_FILE_GRANT = CREATE_NEW_FILE_PERMISSION | | 53 CREATE_NEW_FILE_GRANT = CREATE_NEW_FILE_PERMISSION | |
53 COPY_INTO_FILE_PERMISSION, | 54 COPY_INTO_FILE_PERMISSION, |
54 | 55 |
55 CREATE_READ_WRITE_FILE_GRANT = CREATE_NEW_FILE_PERMISSION | | 56 CREATE_READ_WRITE_FILE_GRANT = CREATE_NEW_FILE_PERMISSION | |
56 CREATE_OVERWRITE_FILE_PERMISSION | | 57 CREATE_OVERWRITE_FILE_PERMISSION | |
57 READ_FILE_PERMISSION | | 58 READ_FILE_PERMISSION | |
58 WRITE_FILE_PERMISSION | | 59 WRITE_FILE_PERMISSION | |
59 COPY_INTO_FILE_PERMISSION, | 60 COPY_INTO_FILE_PERMISSION | |
| 61 DELETE_FILE_PERMISSION, |
60 | 62 |
61 COPY_INTO_FILE_GRANT = COPY_INTO_FILE_PERMISSION, | 63 COPY_INTO_FILE_GRANT = COPY_INTO_FILE_PERMISSION, |
| 64 DELETE_FILE_GRANT = DELETE_FILE_PERMISSION, |
62 }; | 65 }; |
63 | 66 |
64 } // namespace | 67 } // namespace |
65 | 68 |
66 // The SecurityState class is used to maintain per-child process security state | 69 // The SecurityState class is used to maintain per-child process security state |
67 // information. | 70 // information. |
68 class ChildProcessSecurityPolicyImpl::SecurityState { | 71 class ChildProcessSecurityPolicyImpl::SecurityState { |
69 public: | 72 public: |
70 SecurityState() | 73 SecurityState() |
71 : enabled_bindings_(0), | 74 : enabled_bindings_(0), |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 void ChildProcessSecurityPolicyImpl::GrantCreateFileForFileSystem( | 474 void ChildProcessSecurityPolicyImpl::GrantCreateFileForFileSystem( |
472 int child_id, const std::string& filesystem_id) { | 475 int child_id, const std::string& filesystem_id) { |
473 GrantPermissionsForFileSystem(child_id, filesystem_id, CREATE_NEW_FILE_GRANT); | 476 GrantPermissionsForFileSystem(child_id, filesystem_id, CREATE_NEW_FILE_GRANT); |
474 } | 477 } |
475 | 478 |
476 void ChildProcessSecurityPolicyImpl::GrantCopyIntoFileSystem( | 479 void ChildProcessSecurityPolicyImpl::GrantCopyIntoFileSystem( |
477 int child_id, const std::string& filesystem_id) { | 480 int child_id, const std::string& filesystem_id) { |
478 GrantPermissionsForFileSystem(child_id, filesystem_id, COPY_INTO_FILE_GRANT); | 481 GrantPermissionsForFileSystem(child_id, filesystem_id, COPY_INTO_FILE_GRANT); |
479 } | 482 } |
480 | 483 |
| 484 void ChildProcessSecurityPolicyImpl::GrantDeleteFromFileSystem( |
| 485 int child_id, const std::string& filesystem_id) { |
| 486 GrantPermissionsForFileSystem(child_id, filesystem_id, DELETE_FILE_GRANT); |
| 487 } |
| 488 |
481 void ChildProcessSecurityPolicyImpl::GrantSendMIDISysExMessage(int child_id) { | 489 void ChildProcessSecurityPolicyImpl::GrantSendMIDISysExMessage(int child_id) { |
482 base::AutoLock lock(lock_); | 490 base::AutoLock lock(lock_); |
483 | 491 |
484 SecurityStateMap::iterator state = security_state_.find(child_id); | 492 SecurityStateMap::iterator state = security_state_.find(child_id); |
485 if (state == security_state_.end()) | 493 if (state == security_state_.end()) |
486 return; | 494 return; |
487 | 495 |
488 state->second->GrantPermissionForMIDISysEx(); | 496 state->second->GrantPermissionForMIDISysEx(); |
489 } | 497 } |
490 | 498 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 return HasPermissionsForFileSystem(child_id, filesystem_id, | 628 return HasPermissionsForFileSystem(child_id, filesystem_id, |
621 READ_FILE_GRANT | WRITE_FILE_GRANT); | 629 READ_FILE_GRANT | WRITE_FILE_GRANT); |
622 } | 630 } |
623 | 631 |
624 bool ChildProcessSecurityPolicyImpl::CanCopyIntoFileSystem( | 632 bool ChildProcessSecurityPolicyImpl::CanCopyIntoFileSystem( |
625 int child_id, const std::string& filesystem_id) { | 633 int child_id, const std::string& filesystem_id) { |
626 return HasPermissionsForFileSystem(child_id, filesystem_id, | 634 return HasPermissionsForFileSystem(child_id, filesystem_id, |
627 COPY_INTO_FILE_GRANT); | 635 COPY_INTO_FILE_GRANT); |
628 } | 636 } |
629 | 637 |
| 638 bool ChildProcessSecurityPolicyImpl::CanDeleteFromFileSystem( |
| 639 int child_id, const std::string& filesystem_id) { |
| 640 return HasPermissionsForFileSystem(child_id, filesystem_id, |
| 641 DELETE_FILE_GRANT); |
| 642 } |
| 643 |
630 bool ChildProcessSecurityPolicyImpl::HasPermissionsForFile( | 644 bool ChildProcessSecurityPolicyImpl::HasPermissionsForFile( |
631 int child_id, const base::FilePath& file, int permissions) { | 645 int child_id, const base::FilePath& file, int permissions) { |
632 base::AutoLock lock(lock_); | 646 base::AutoLock lock(lock_); |
633 bool result = ChildProcessHasPermissionsForFile(child_id, file, permissions); | 647 bool result = ChildProcessHasPermissionsForFile(child_id, file, permissions); |
634 if (!result) { | 648 if (!result) { |
635 // If this is a worker thread that has no access to a given file, | 649 // If this is a worker thread that has no access to a given file, |
636 // let's check that its renderer process has access to that file instead. | 650 // let's check that its renderer process has access to that file instead. |
637 WorkerToMainProcessMap::iterator iter = worker_map_.find(child_id); | 651 WorkerToMainProcessMap::iterator iter = worker_map_.find(child_id); |
638 if (iter != worker_map_.end() && iter->second != 0) { | 652 if (iter != worker_map_.end() && iter->second != 0) { |
639 result = ChildProcessHasPermissionsForFile(iter->second, | 653 result = ChildProcessHasPermissionsForFile(iter->second, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 return HasPermissionsForFileSystemFile(child_id, url, | 723 return HasPermissionsForFileSystemFile(child_id, url, |
710 CREATE_READ_WRITE_FILE_GRANT); | 724 CREATE_READ_WRITE_FILE_GRANT); |
711 } | 725 } |
712 | 726 |
713 bool ChildProcessSecurityPolicyImpl::CanCopyIntoFileSystemFile( | 727 bool ChildProcessSecurityPolicyImpl::CanCopyIntoFileSystemFile( |
714 int child_id, | 728 int child_id, |
715 const fileapi::FileSystemURL& url) { | 729 const fileapi::FileSystemURL& url) { |
716 return HasPermissionsForFileSystemFile(child_id, url, COPY_INTO_FILE_GRANT); | 730 return HasPermissionsForFileSystemFile(child_id, url, COPY_INTO_FILE_GRANT); |
717 } | 731 } |
718 | 732 |
| 733 bool ChildProcessSecurityPolicyImpl::CanDeleteFileSystemFile( |
| 734 int child_id, |
| 735 const fileapi::FileSystemURL& url) { |
| 736 return HasPermissionsForFileSystemFile(child_id, url, DELETE_FILE_GRANT); |
| 737 } |
| 738 |
719 bool ChildProcessSecurityPolicyImpl::HasWebUIBindings(int child_id) { | 739 bool ChildProcessSecurityPolicyImpl::HasWebUIBindings(int child_id) { |
720 base::AutoLock lock(lock_); | 740 base::AutoLock lock(lock_); |
721 | 741 |
722 SecurityStateMap::iterator state = security_state_.find(child_id); | 742 SecurityStateMap::iterator state = security_state_.find(child_id); |
723 if (state == security_state_.end()) | 743 if (state == security_state_.end()) |
724 return false; | 744 return false; |
725 | 745 |
726 return state->second->has_web_ui_bindings(); | 746 return state->second->has_web_ui_bindings(); |
727 } | 747 } |
728 | 748 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 base::AutoLock lock(lock_); | 847 base::AutoLock lock(lock_); |
828 | 848 |
829 SecurityStateMap::iterator state = security_state_.find(child_id); | 849 SecurityStateMap::iterator state = security_state_.find(child_id); |
830 if (state == security_state_.end()) | 850 if (state == security_state_.end()) |
831 return false; | 851 return false; |
832 | 852 |
833 return state->second->can_send_midi_sysex(); | 853 return state->second->can_send_midi_sysex(); |
834 } | 854 } |
835 | 855 |
836 } // namespace content | 856 } // namespace content |
OLD | NEW |