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

Side by Side Diff: sandbox/linux/services/namespace_utils_unittest.cc

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@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 unified diff | Download patch
« no previous file with comments | « sandbox/linux/services/namespace_utils.cc ('k') | sandbox/linux/services/proc_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "sandbox/linux/services/namespace_utils.h" 5 #include "sandbox/linux/services/namespace_utils.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <sched.h> 8 #include <sched.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <sys/wait.h> 10 #include <sys/wait.h>
(...skipping 22 matching lines...) Expand all
33 } 33 }
34 34
35 SANDBOX_TEST(NamespaceUtils, WriteToIdMapFile) { 35 SANDBOX_TEST(NamespaceUtils, WriteToIdMapFile) {
36 if (!Credentials::CanCreateProcessInNewUserNS()) { 36 if (!Credentials::CanCreateProcessInNewUserNS()) {
37 return; 37 return;
38 } 38 }
39 39
40 const uid_t uid = getuid(); 40 const uid_t uid = getuid();
41 const gid_t gid = getgid(); 41 const gid_t gid = getgid();
42 42
43 const bool supports_deny_setgroups =
44 NamespaceUtils::KernelSupportsDenySetgroups();
45
43 const pid_t pid = 46 const pid_t pid =
44 base::ForkWithFlags(CLONE_NEWUSER | SIGCHLD, nullptr, nullptr); 47 base::ForkWithFlags(CLONE_NEWUSER | SIGCHLD, nullptr, nullptr);
45 ASSERT_NE(-1, pid); 48 ASSERT_NE(-1, pid);
46 if (pid == 0) { 49 if (pid == 0) {
50 if (supports_deny_setgroups) {
51 RAW_CHECK(NamespaceUtils::DenySetgroups());
52 }
53
47 RAW_CHECK(getuid() != uid); 54 RAW_CHECK(getuid() != uid);
48 RAW_CHECK(NamespaceUtils::WriteToIdMapFile("/proc/self/uid_map", uid)); 55 RAW_CHECK(NamespaceUtils::WriteToIdMapFile("/proc/self/uid_map", uid));
49 RAW_CHECK(getuid() == uid); 56 RAW_CHECK(getuid() == uid);
50 57
51 RAW_CHECK(getgid() != gid); 58 RAW_CHECK(getgid() != gid);
52 RAW_CHECK(NamespaceUtils::WriteToIdMapFile("/proc/self/gid_map", gid)); 59 RAW_CHECK(NamespaceUtils::WriteToIdMapFile("/proc/self/gid_map", gid));
53 RAW_CHECK(getgid() == gid); 60 RAW_CHECK(getgid() == gid);
54 61
55 _exit(0); 62 _exit(0);
56 } 63 }
57 64
58 int status = 42; 65 int status = 42;
59 SANDBOX_ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0))); 66 SANDBOX_ASSERT_EQ(pid, HANDLE_EINTR(waitpid(pid, &status, 0)));
60 SANDBOX_ASSERT_EQ(0, status); 67 SANDBOX_ASSERT_EQ(0, status);
61 } 68 }
62 69
63 } // namespace. 70 } // namespace.
64 71
65 } // namespace sandbox. 72 } // namespace sandbox.
OLDNEW
« no previous file with comments | « sandbox/linux/services/namespace_utils.cc ('k') | sandbox/linux/services/proc_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698