| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_SERVICES_CREDENTIALS_H_ | 5 #ifndef SANDBOX_LINUX_SERVICES_CREDENTIALS_H_ |
| 6 #define SANDBOX_LINUX_SERVICES_CREDENTIALS_H_ | 6 #define SANDBOX_LINUX_SERVICES_CREDENTIALS_H_ |
| 7 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 // Link errors are tedious to track, raise a compile-time error instead. | 9 // Link errors are tedious to track, raise a compile-time error instead. |
| 10 #if defined(OS_ANDROID) | 10 #if defined(OS_ANDROID) |
| 11 #error "Android is not supported." | 11 #error "Android is not supported." |
| 12 #endif // defined(OS_ANDROID). | 12 #endif // defined(OS_ANDROID). |
| 13 | 13 |
| 14 #include <string> | 14 #include <string> |
| 15 | 15 |
| 16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "sandbox/sandbox_export.h" | 19 #include "sandbox/sandbox_export.h" |
| 20 | 20 |
| 21 namespace sandbox { | 21 namespace sandbox { |
| 22 | 22 |
| 23 // This class should be used to manipulate the current process' credentials. | 23 // This class should be used to manipulate the current process' credentials. |
| 24 // It is currently a stub used to manipulate POSIX.1e capabilities as | 24 // It is currently a stub used to manipulate POSIX.1e capabilities as |
| 25 // implemented by the Linux kernel. | 25 // implemented by the Linux kernel. |
| 26 class SANDBOX_EXPORT Credentials { | 26 class SANDBOX_EXPORT Credentials { |
| 27 public: | 27 public: |
| 28 Credentials(); | |
| 29 ~Credentials(); | |
| 30 | |
| 31 // Drop all capabilities in the effective, inheritable and permitted sets for | 28 // Drop all capabilities in the effective, inheritable and permitted sets for |
| 32 // the current process. | 29 // the current process. |
| 33 bool DropAllCapabilities() WARN_UNUSED_RESULT; | 30 static bool DropAllCapabilities() WARN_UNUSED_RESULT; |
| 34 // Return true iff there is any capability in any of the capabilities sets | 31 // Return true iff there is any capability in any of the capabilities sets |
| 35 // of the current process. | 32 // of the current process. |
| 36 bool HasAnyCapability() const; | 33 static bool HasAnyCapability(); |
| 37 // Returns the capabilities of the current process in textual form, as | 34 // Returns the capabilities of the current process in textual form, as |
| 38 // documented in libcap2's cap_to_text(3). This is mostly useful for | 35 // documented in libcap2's cap_to_text(3). This is mostly useful for |
| 39 // debugging and tests. | 36 // debugging and tests. |
| 40 scoped_ptr<std::string> GetCurrentCapString() const; | 37 static scoped_ptr<std::string> GetCurrentCapString(); |
| 41 | 38 |
| 42 // Returns whether the kernel supports CLONE_NEWUSER and whether it would be | 39 // Returns whether the kernel supports CLONE_NEWUSER and whether it would be |
| 43 // possible to immediately move to a new user namespace. There is no point | 40 // possible to immediately move to a new user namespace. There is no point |
| 44 // in using this method right before calling MoveToNewUserNS(), simply call | 41 // in using this method right before calling MoveToNewUserNS(), simply call |
| 45 // MoveToNewUserNS() immediately. This method is only useful to test kernel | 42 // MoveToNewUserNS() immediately. This method is only useful to test kernel |
| 46 // support ahead of time. | 43 // support ahead of time. |
| 47 static bool SupportsNewUserNS(); | 44 static bool SupportsNewUserNS(); |
| 48 | 45 |
| 49 // Move the current process to a new "user namespace" as supported by Linux | 46 // Move the current process to a new "user namespace" as supported by Linux |
| 50 // 3.8+ (CLONE_NEWUSER). | 47 // 3.8+ (CLONE_NEWUSER). |
| 51 // The uid map will be set-up so that the perceived uid and gid will not | 48 // The uid map will be set-up so that the perceived uid and gid will not |
| 52 // change. | 49 // change. |
| 53 // If this call succeeds, the current process will be granted a full set of | 50 // If this call succeeds, the current process will be granted a full set of |
| 54 // capabilities in the new namespace. | 51 // capabilities in the new namespace. |
| 55 bool MoveToNewUserNS() WARN_UNUSED_RESULT; | 52 static bool MoveToNewUserNS() WARN_UNUSED_RESULT; |
| 56 | 53 |
| 57 // Remove the ability of the process to access the file system. File | 54 // Remove the ability of the process to access the file system. File |
| 58 // descriptors which are already open prior to calling this API remain | 55 // descriptors which are already open prior to calling this API remain |
| 59 // available. | 56 // available. |
| 60 // The implementation currently uses chroot(2) and requires CAP_SYS_CHROOT. | 57 // The implementation currently uses chroot(2) and requires CAP_SYS_CHROOT. |
| 61 // CAP_SYS_CHROOT can be acquired by using the MoveToNewUserNS() API. | 58 // CAP_SYS_CHROOT can be acquired by using the MoveToNewUserNS() API. |
| 62 // Make sure to call DropAllCapabilities() after this call to prevent | 59 // Make sure to call DropAllCapabilities() after this call to prevent |
| 63 // escapes. | 60 // escapes. |
| 64 // To be secure, the caller must ensure that any directory file descriptors | 61 // To be secure, the caller must ensure that any directory file descriptors |
| 65 // are closed (for example, by checking the result of | 62 // are closed (for example, by checking the result of |
| 66 // ProcUtil::HasOpenDirectory with a file descriptor for /proc, then closing | 63 // ProcUtil::HasOpenDirectory with a file descriptor for /proc, then closing |
| 67 // that file descriptor). Otherwise it may be possible to escape the chroot. | 64 // that file descriptor). Otherwise it may be possible to escape the chroot. |
| 68 bool DropFileSystemAccess() WARN_UNUSED_RESULT; | 65 static bool DropFileSystemAccess() WARN_UNUSED_RESULT; |
| 69 | 66 |
| 70 private: | 67 private: |
| 71 DISALLOW_COPY_AND_ASSIGN(Credentials); | 68 DISALLOW_IMPLICIT_CONSTRUCTORS(Credentials); |
| 72 }; | 69 }; |
| 73 | 70 |
| 74 } // namespace sandbox. | 71 } // namespace sandbox. |
| 75 | 72 |
| 76 #endif // SANDBOX_LINUX_SERVICES_CREDENTIALS_H_ | 73 #endif // SANDBOX_LINUX_SERVICES_CREDENTIALS_H_ |
| OLD | NEW |