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 <sys/capability.h> | |
jln (very slow on Chromium)
2015/02/25 21:32:49
:(
rickyz (no longer on Chrome)
2015/03/21 01:35:32
Superseded by https://codereview.chromium.org/9974
| |
9 | |
8 #include "build/build_config.h" | 10 #include "build/build_config.h" |
9 // Link errors are tedious to track, raise a compile-time error instead. | 11 // Link errors are tedious to track, raise a compile-time error instead. |
10 #if defined(OS_ANDROID) | 12 #if defined(OS_ANDROID) |
11 #error "Android is not supported." | 13 #error "Android is not supported." |
12 #endif // defined(OS_ANDROID). | 14 #endif // defined(OS_ANDROID). |
13 | 15 |
14 #include <string> | 16 #include <string> |
17 #include <vector> | |
15 | 18 |
16 #include "base/basictypes.h" | 19 #include "base/basictypes.h" |
17 #include "base/compiler_specific.h" | 20 #include "base/compiler_specific.h" |
18 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
19 #include "sandbox/sandbox_export.h" | 22 #include "sandbox/sandbox_export.h" |
20 | 23 |
21 namespace sandbox { | 24 namespace sandbox { |
22 | 25 |
23 // This class should be used to manipulate the current process' credentials. | 26 // This class should be used to manipulate the current process' credentials. |
24 // It is currently a stub used to manipulate POSIX.1e capabilities as | 27 // It is currently a stub used to manipulate POSIX.1e capabilities as |
25 // implemented by the Linux kernel. | 28 // implemented by the Linux kernel. |
26 class SANDBOX_EXPORT Credentials { | 29 class SANDBOX_EXPORT Credentials { |
27 public: | 30 public: |
28 // Drop all capabilities in the effective, inheritable and permitted sets for | 31 // Drop all capabilities in the effective, inheritable and permitted sets for |
29 // the current process. For security reasons, since capabilities are | 32 // the current thread. For security reasons, since capabilities are |
30 // per-thread, the caller is responsible for ensuring it is single-threaded | 33 // per-thread, the caller is responsible for ensuring it is single-threaded |
31 // when calling this API. | 34 // when calling this API. |
32 // |proc_fd| must be a file descriptor to /proc/ and remains owned by | 35 // |proc_fd| must be a file descriptor to /proc/ and remains owned by |
33 // the caller. | 36 // the caller. |
34 static bool DropAllCapabilities(int proc_fd) WARN_UNUSED_RESULT; | 37 static bool DropAllCapabilities(int proc_fd) WARN_UNUSED_RESULT; |
35 // A similar API which assumes that it can open /proc/self/ by itself. | 38 // A similar API which assumes that it can open /proc/self/ by itself. |
36 static bool DropAllCapabilities() WARN_UNUSED_RESULT; | 39 static bool DropAllCapabilities() WARN_UNUSED_RESULT; |
40 // Sets the effective and permitted capability sets for the current thread to | |
41 // the list of capabiltiies in |caps|. All other capability flags are cleared. | |
42 static bool SetCapabilities(int proc_fd, | |
jln (very slow on Chromium)
2015/02/25 21:32:49
Not great to expose that. Probably ok for now, but
rickyz (no longer on Chrome)
2015/03/21 01:35:32
Superseded by https://codereview.chromium.org/9974
| |
43 const std::vector<cap_value_t>& caps); | |
37 | 44 |
38 // Return true iff there is any capability in any of the capabilities sets | 45 // Return true iff there is any capability in any of the capabilities sets |
39 // of the current process. | 46 // of the current thread. |
40 static bool HasAnyCapability(); | 47 static bool HasAnyCapability(); |
41 // Returns the capabilities of the current process in textual form, as | 48 // Returns the capabilities of the current thread in textual form, as |
42 // documented in libcap2's cap_to_text(3). This is mostly useful for | 49 // documented in libcap2's cap_to_text(3). This is mostly useful for |
43 // debugging and tests. | 50 // debugging and tests. |
44 static scoped_ptr<std::string> GetCurrentCapString(); | 51 static scoped_ptr<std::string> GetCurrentCapString(); |
45 | 52 |
46 // Returns whether the kernel supports CLONE_NEWUSER and whether it would be | 53 // Returns whether the kernel supports CLONE_NEWUSER and whether it would be |
47 // possible to immediately move to a new user namespace. There is no point | 54 // possible to immediately move to a new user namespace. There is no point |
48 // in using this method right before calling MoveToNewUserNS(), simply call | 55 // in using this method right before calling MoveToNewUserNS(), simply call |
49 // MoveToNewUserNS() immediately. This method is only useful to test the | 56 // MoveToNewUserNS() immediately. This method is only useful to test the |
50 // ability to move to a user namespace ahead of time. | 57 // ability to move to a user namespace ahead of time. |
51 static bool CanCreateProcessInNewUserNS(); | 58 static bool CanCreateProcessInNewUserNS(); |
(...skipping 20 matching lines...) Expand all Loading... | |
72 // - DropAllCapabilities() must be called to prevent escapes. | 79 // - DropAllCapabilities() must be called to prevent escapes. |
73 static bool DropFileSystemAccess(int proc_fd) WARN_UNUSED_RESULT; | 80 static bool DropFileSystemAccess(int proc_fd) WARN_UNUSED_RESULT; |
74 | 81 |
75 private: | 82 private: |
76 DISALLOW_IMPLICIT_CONSTRUCTORS(Credentials); | 83 DISALLOW_IMPLICIT_CONSTRUCTORS(Credentials); |
77 }; | 84 }; |
78 | 85 |
79 } // namespace sandbox. | 86 } // namespace sandbox. |
80 | 87 |
81 #endif // SANDBOX_LINUX_SERVICES_CREDENTIALS_H_ | 88 #endif // SANDBOX_LINUX_SERVICES_CREDENTIALS_H_ |
OLD | NEW |