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

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

Issue 2357393003: Add check for file system access to the sandbox. (Closed)
Patch Set: Fix IsSandboxed() check when loading flash player. Created 4 years, 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/credentials.h" 5 #include "sandbox/linux/services/credentials.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <limits.h> 9 #include <limits.h>
10 #include <pthread.h> 10 #include <pthread.h>
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 PCHECK(0 == chdir("/")); 142 PCHECK(0 == chdir("/"));
143 CHECK(WorkingDirectoryIsRoot()); 143 CHECK(WorkingDirectoryIsRoot());
144 } 144 }
145 145
146 // Disabled on ASAN because of crbug.com/451603. 146 // Disabled on ASAN because of crbug.com/451603.
147 SANDBOX_TEST(Credentials, DISABLE_ON_ASAN(DropFileSystemAccessIsSafe)) { 147 SANDBOX_TEST(Credentials, DISABLE_ON_ASAN(DropFileSystemAccessIsSafe)) {
148 CHECK(Credentials::DropAllCapabilities()); 148 CHECK(Credentials::DropAllCapabilities());
149 // Probably missing kernel support. 149 // Probably missing kernel support.
150 if (!Credentials::MoveToNewUserNS()) return; 150 if (!Credentials::MoveToNewUserNS()) return;
151 CHECK(Credentials::DropFileSystemAccess(ProcUtil::OpenProc().get())); 151 CHECK(Credentials::DropFileSystemAccess(ProcUtil::OpenProc().get()));
152 CHECK(!base::DirectoryExists(base::FilePath("/proc"))); 152 CHECK(!base::DirectoryExists(base::FilePath("/proc")));
rickyz (no longer on Chrome) 2016/09/23 23:40:20 Would be fine with replacing this line rather than
Greg K 2016/09/26 20:22:12 Done.
153 CHECK(WorkingDirectoryIsRoot()); 153 CHECK(WorkingDirectoryIsRoot());
154 CHECK(base::IsDirectoryEmpty(base::FilePath("/"))); 154 CHECK(base::IsDirectoryEmpty(base::FilePath("/")));
155 // We want the chroot to never have a subdirectory. A subdirectory 155 // We want the chroot to never have a subdirectory. A subdirectory
156 // could allow a chroot escape. 156 // could allow a chroot escape.
157 CHECK_NE(0, mkdir("/test", 0700)); 157 CHECK_NE(0, mkdir("/test", 0700));
158 } 158 }
159 159
160 // Check that callers can reliably test if file system access exists.
161 SANDBOX_TEST(Credentials, DISABLE_ON_ASAN(HasFileSystemAccess)) {
162 CHECK(Credentials::HasFileSystemAccess());
163 CHECK(Credentials::DropAllCapabilities());
164 // Probably missing kernel support.
165 if (!Credentials::MoveToNewUserNS()) return;
166 CHECK(Credentials::DropFileSystemAccess(ProcUtil::OpenProc().get()));
167 CHECK(!Credentials::HasFileSystemAccess());
168 }
169
160 // Check that after dropping filesystem access and dropping privileges 170 // Check that after dropping filesystem access and dropping privileges
161 // it is not possible to regain capabilities. 171 // it is not possible to regain capabilities.
162 SANDBOX_TEST(Credentials, DISABLE_ON_ASAN(CannotRegainPrivileges)) { 172 SANDBOX_TEST(Credentials, DISABLE_ON_ASAN(CannotRegainPrivileges)) {
163 base::ScopedFD proc_fd(ProcUtil::OpenProc()); 173 base::ScopedFD proc_fd(ProcUtil::OpenProc());
164 CHECK(Credentials::DropAllCapabilities(proc_fd.get())); 174 CHECK(Credentials::DropAllCapabilities(proc_fd.get()));
165 // Probably missing kernel support. 175 // Probably missing kernel support.
166 if (!Credentials::MoveToNewUserNS()) return; 176 if (!Credentials::MoveToNewUserNS()) return;
167 CHECK(Credentials::DropFileSystemAccess(proc_fd.get())); 177 CHECK(Credentials::DropFileSystemAccess(proc_fd.get()));
168 CHECK(Credentials::DropAllCapabilities(proc_fd.get())); 178 CHECK(Credentials::DropAllCapabilities(proc_fd.get()));
169 179
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 action.sa_handler = &SignalHandler; 271 action.sa_handler = &SignalHandler;
262 PCHECK(sigaction(SIGUSR1, &action, nullptr) == 0); 272 PCHECK(sigaction(SIGUSR1, &action, nullptr) == 0);
263 273
264 PCHECK(raise(SIGUSR1) == 0); 274 PCHECK(raise(SIGUSR1) == 0);
265 CHECK_EQ(1, signal_handler_called); 275 CHECK_EQ(1, signal_handler_called);
266 } 276 }
267 277
268 } // namespace. 278 } // namespace.
269 279
270 } // namespace sandbox. 280 } // namespace sandbox.
OLDNEW
« sandbox/linux/services/credentials.cc ('K') | « sandbox/linux/services/credentials.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698