| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef SANDBOX_LINUX_SYSCALL_BROKER_BROKER_CLIENT_H_ | 5 #ifndef SANDBOX_LINUX_SYSCALL_BROKER_BROKER_CLIENT_H_ |
| 6 #define SANDBOX_LINUX_SYSCALL_BROKER_BROKER_CLIENT_H_ | 6 #define SANDBOX_LINUX_SYSCALL_BROKER_BROKER_CLIENT_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "sandbox/linux/syscall_broker/broker_channel.h" |
| 9 #include "sandbox/linux/syscall_broker/broker_common.h" | 10 #include "sandbox/linux/syscall_broker/broker_common.h" |
| 10 | 11 |
| 11 namespace sandbox { | 12 namespace sandbox { |
| 12 | 13 |
| 13 namespace syscall_broker { | 14 namespace syscall_broker { |
| 14 | 15 |
| 15 class BrokerPolicy; | 16 class BrokerPolicy; |
| 16 | 17 |
| 17 // This class can be embedded in a sandboxed process and can be | 18 // This class can be embedded in a sandboxed process and can be |
| 18 // used to perform certain system calls in another, presumably | 19 // used to perform certain system calls in another, presumably |
| 19 // non-sandboxed process (which embeds BrokerHost). | 20 // non-sandboxed process (which embeds BrokerHost). |
| 20 // A key feature of this class is the ability to use some of its methods in a | 21 // A key feature of this class is the ability to use some of its methods in a |
| 21 // thread-safe and async-signal safe way. The goal is to be able to use it to | 22 // thread-safe and async-signal safe way. The goal is to be able to use it to |
| 22 // replace the open() or access() system calls happening anywhere in a process | 23 // replace the open() or access() system calls happening anywhere in a process |
| 23 // (as allowed for instance by seccomp-bpf's SIGSYS mechanism). | 24 // (as allowed for instance by seccomp-bpf's SIGSYS mechanism). |
| 24 class BrokerClient { | 25 class BrokerClient { |
| 25 public: | 26 public: |
| 26 // |policy| needs to match the policy used by BrokerHost. This | 27 // |policy| needs to match the policy used by BrokerHost. This |
| 27 // allows to predict some of the requests which will be denied | 28 // allows to predict some of the requests which will be denied |
| 28 // and save an IPC round trip. | 29 // and save an IPC round trip. |
| 29 // |ipc_channel| needs to be a suitable SOCK_SEQPACKET unix socket. | 30 // |ipc_channel| needs to be a suitable SOCK_SEQPACKET unix socket. |
| 30 // |fast_check_in_client| should be set to true and | 31 // |fast_check_in_client| should be set to true and |
| 31 // |quiet_failures_for_tests| to false unless you are writing tests. | 32 // |quiet_failures_for_tests| to false unless you are writing tests. |
| 32 BrokerClient(const BrokerPolicy& policy, | 33 BrokerClient(const BrokerPolicy& policy, |
| 33 int ipc_channel, | 34 BrokerChannel::EndPoint ipc_channel, |
| 34 bool fast_check_in_client, | 35 bool fast_check_in_client, |
| 35 bool quiet_failures_for_tests); | 36 bool quiet_failures_for_tests); |
| 36 ~BrokerClient(); | 37 ~BrokerClient(); |
| 37 | 38 |
| 38 // Can be used in place of access(). | 39 // Can be used in place of access(). |
| 39 // X_OK will always return an error in practice since the broker process | 40 // X_OK will always return an error in practice since the broker process |
| 40 // doesn't support execute permissions. | 41 // doesn't support execute permissions. |
| 41 // It's similar to the access() system call and will return -errno on errors. | 42 // It's similar to the access() system call and will return -errno on errors. |
| 42 // This is async signal safe. | 43 // This is async signal safe. |
| 43 int Access(const char* pathname, int mode) const; | 44 int Access(const char* pathname, int mode) const; |
| 44 // Can be used in place of open(). | 45 // Can be used in place of open(). |
| 45 // The implementation only supports certain white listed flags and will | 46 // The implementation only supports certain white listed flags and will |
| 46 // return -EPERM on other flags. | 47 // return -EPERM on other flags. |
| 47 // It's similar to the open() system call and will return -errno on errors. | 48 // It's similar to the open() system call and will return -errno on errors. |
| 48 // This is async signal safe. | 49 // This is async signal safe. |
| 49 int Open(const char* pathname, int flags) const; | 50 int Open(const char* pathname, int flags) const; |
| 50 | 51 |
| 52 // Get the file descriptor used for IPC. This is used for tests. |
| 53 int GetIPCDescriptor() const { return ipc_channel_.get(); } |
| 54 |
| 51 private: | 55 private: |
| 52 const BrokerPolicy& broker_policy_; | 56 const BrokerPolicy& broker_policy_; |
| 53 const int ipc_channel_; | 57 const BrokerChannel::EndPoint ipc_channel_; |
| 54 const bool fast_check_in_client_; // Whether to forward a request that we | 58 const bool fast_check_in_client_; // Whether to forward a request that we |
| 55 // know will be denied to the broker. (Used | 59 // know will be denied to the broker. (Used |
| 56 // for tests). | 60 // for tests). |
| 57 const bool quiet_failures_for_tests_; // Disable certain error message when | 61 const bool quiet_failures_for_tests_; // Disable certain error message when |
| 58 // testing for failures. | 62 // testing for failures. |
| 59 | 63 |
| 60 int PathAndFlagsSyscall(IPCCommand syscall_type, | 64 int PathAndFlagsSyscall(IPCCommand syscall_type, |
| 61 const char* pathname, | 65 const char* pathname, |
| 62 int flags) const; | 66 int flags) const; |
| 63 | 67 |
| 64 DISALLOW_COPY_AND_ASSIGN(BrokerClient); | 68 DISALLOW_COPY_AND_ASSIGN(BrokerClient); |
| 65 }; | 69 }; |
| 66 | 70 |
| 67 } // namespace syscall_broker | 71 } // namespace syscall_broker |
| 68 | 72 |
| 69 } // namespace sandbox | 73 } // namespace sandbox |
| 70 | 74 |
| 71 #endif // SANDBOX_LINUX_SYSCALL_BROKER_BROKER_CLIENT_H_ | 75 #endif // SANDBOX_LINUX_SYSCALL_BROKER_BROKER_CLIENT_H_ |
| OLD | NEW |