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

Unified Diff: sandbox/linux/services/credentials.h

Issue 960873002: Update from https://crrev.com/318214 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sandbox/linux/services/credentials.h
diff --git a/sandbox/linux/services/credentials.h b/sandbox/linux/services/credentials.h
index 2b761b6034aeb7445a0f114166b41c11f5eebdf7..91435611851f81a0d2136feb3975180d5158874a 100644
--- a/sandbox/linux/services/credentials.h
+++ b/sandbox/linux/services/credentials.h
@@ -29,7 +29,12 @@ class SANDBOX_EXPORT Credentials {
// the current process. For security reasons, since capabilities are
// per-thread, the caller is responsible for ensuring it is single-threaded
// when calling this API.
+ // |proc_fd| must be a file descriptor to /proc/ and remains owned by
+ // the caller.
+ static bool DropAllCapabilities(int proc_fd) WARN_UNUSED_RESULT;
+ // A similar API which assumes that it can open /proc/self/ by itself.
static bool DropAllCapabilities() WARN_UNUSED_RESULT;
+
// Return true iff there is any capability in any of the capabilities sets
// of the current process.
static bool HasAnyCapability();
@@ -51,6 +56,7 @@ class SANDBOX_EXPORT Credentials {
// change.
// If this call succeeds, the current process will be granted a full set of
// capabilities in the new namespace.
+ // This will fail if the process is not mono-threaded.
static bool MoveToNewUserNS() WARN_UNUSED_RESULT;
// Remove the ability of the process to access the file system. File
@@ -58,13 +64,14 @@ class SANDBOX_EXPORT Credentials {
// available.
// The implementation currently uses chroot(2) and requires CAP_SYS_CHROOT.
// CAP_SYS_CHROOT can be acquired by using the MoveToNewUserNS() API.
- // Make sure to call DropAllCapabilities() after this call to prevent
- // escapes.
- // To be secure, the caller must ensure that any directory file descriptors
- // are closed (for example, by checking the result of
- // ProcUtil::HasOpenDirectory with a file descriptor for /proc, then closing
- // that file descriptor). Otherwise it may be possible to escape the chroot.
- static bool DropFileSystemAccess() WARN_UNUSED_RESULT;
+ // |proc_fd| must be a file descriptor to /proc/ and must be the only open
+ // directory file descriptor of the process.
+ //
+ // CRITICAL:
+ // - the caller must close |proc_fd| eventually or access to the file
+ // system can be recovered.
+ // - DropAllCapabilities() must be called to prevent escapes.
+ static bool DropFileSystemAccess(int proc_fd) WARN_UNUSED_RESULT;
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(Credentials);
« 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