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

Side by Side Diff: sandbox/linux/services/credentials.h

Issue 938223004: Linux sandbox: better APIs with /proc/ arguments (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix invalid proc_fd_ usage. Created 5 years, 9 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
OLDNEW
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)
(...skipping 11 matching lines...) Expand all
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 // Drop all capabilities in the effective, inheritable and permitted sets for 28 // Drop all capabilities in the effective, inheritable and permitted sets for
29 // the current process. For security reasons, since capabilities are 29 // the current process. For security reasons, since capabilities are
30 // per-thread, the caller is responsible for ensuring it is single-threaded 30 // per-thread, the caller is responsible for ensuring it is single-threaded
31 // when calling this API. 31 // when calling this API.
32 // |proc_fd| must be a file descriptor to /proc/ and remains owned by
33 // the caller.
34 static bool DropAllCapabilities(int proc_fd) WARN_UNUSED_RESULT;
35 // A similar API which assumes that it can open /proc/self/ by itself.
32 static bool DropAllCapabilities() WARN_UNUSED_RESULT; 36 static bool DropAllCapabilities() WARN_UNUSED_RESULT;
37
33 // Return true iff there is any capability in any of the capabilities sets 38 // Return true iff there is any capability in any of the capabilities sets
34 // of the current process. 39 // of the current process.
35 static bool HasAnyCapability(); 40 static bool HasAnyCapability();
36 // Returns the capabilities of the current process in textual form, as 41 // Returns the capabilities of the current process in textual form, as
37 // documented in libcap2's cap_to_text(3). This is mostly useful for 42 // documented in libcap2's cap_to_text(3). This is mostly useful for
38 // debugging and tests. 43 // debugging and tests.
39 static scoped_ptr<std::string> GetCurrentCapString(); 44 static scoped_ptr<std::string> GetCurrentCapString();
40 45
41 // Returns whether the kernel supports CLONE_NEWUSER and whether it would be 46 // Returns whether the kernel supports CLONE_NEWUSER and whether it would be
42 // possible to immediately move to a new user namespace. There is no point 47 // possible to immediately move to a new user namespace. There is no point
43 // in using this method right before calling MoveToNewUserNS(), simply call 48 // in using this method right before calling MoveToNewUserNS(), simply call
44 // MoveToNewUserNS() immediately. This method is only useful to test the 49 // MoveToNewUserNS() immediately. This method is only useful to test the
45 // ability to move to a user namespace ahead of time. 50 // ability to move to a user namespace ahead of time.
46 static bool CanCreateProcessInNewUserNS(); 51 static bool CanCreateProcessInNewUserNS();
47 52
48 // Move the current process to a new "user namespace" as supported by Linux 53 // Move the current process to a new "user namespace" as supported by Linux
49 // 3.8+ (CLONE_NEWUSER). 54 // 3.8+ (CLONE_NEWUSER).
50 // The uid map will be set-up so that the perceived uid and gid will not 55 // The uid map will be set-up so that the perceived uid and gid will not
51 // change. 56 // change.
52 // If this call succeeds, the current process will be granted a full set of 57 // If this call succeeds, the current process will be granted a full set of
53 // capabilities in the new namespace. 58 // capabilities in the new namespace.
54 static bool MoveToNewUserNS() WARN_UNUSED_RESULT; 59 static bool MoveToNewUserNS() WARN_UNUSED_RESULT;
55 60
56 // Remove the ability of the process to access the file system. File 61 // Remove the ability of the process to access the file system. File
57 // descriptors which are already open prior to calling this API remain 62 // descriptors which are already open prior to calling this API remain
58 // available. 63 // available.
59 // The implementation currently uses chroot(2) and requires CAP_SYS_CHROOT. 64 // The implementation currently uses chroot(2) and requires CAP_SYS_CHROOT.
60 // CAP_SYS_CHROOT can be acquired by using the MoveToNewUserNS() API. 65 // CAP_SYS_CHROOT can be acquired by using the MoveToNewUserNS() API.
61 // Make sure to call DropAllCapabilities() after this call to prevent 66 // |proc_fd| must be a file descriptor to /proc/ and must be the only open
62 // escapes. 67 // directory file descriptor of the process.
63 // To be secure, the caller must ensure that any directory file descriptors 68 //
64 // are closed (for example, by checking the result of 69 // CRITICAL:
65 // ProcUtil::HasOpenDirectory with a file descriptor for /proc, then closing 70 // - the caller must close |proc_fd| eventually or access to the file
66 // that file descriptor). Otherwise it may be possible to escape the chroot. 71 // system can be recovered.
67 static bool DropFileSystemAccess() WARN_UNUSED_RESULT; 72 // - DropAllCapabilities() must be called to prevent escapes.
73 static bool DropFileSystemAccess(int proc_fd) WARN_UNUSED_RESULT;
68 74
69 private: 75 private:
70 DISALLOW_IMPLICIT_CONSTRUCTORS(Credentials); 76 DISALLOW_IMPLICIT_CONSTRUCTORS(Credentials);
71 }; 77 };
72 78
73 } // namespace sandbox. 79 } // namespace sandbox.
74 80
75 #endif // SANDBOX_LINUX_SERVICES_CREDENTIALS_H_ 81 #endif // SANDBOX_LINUX_SERVICES_CREDENTIALS_H_
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf/sandbox_bpf_unittest.cc ('k') | sandbox/linux/services/credentials.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698