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

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

Issue 59763014: DPCHECK known conditions when we guess false in CurrentProcessHasOpenDirectories (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update on newer master again Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "sandbox/linux/services/credentials.h" 5 #include "sandbox/linux/services/credentials.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 Credentials::~Credentials() { 156 Credentials::~Credentials() {
157 } 157 }
158 158
159 bool Credentials::HasOpenDirectory(int proc_fd) { 159 bool Credentials::HasOpenDirectory(int proc_fd) {
160 int proc_self_fd = -1; 160 int proc_self_fd = -1;
161 if (proc_fd >= 0) { 161 if (proc_fd >= 0) {
162 proc_self_fd = openat(proc_fd, "self/fd", O_DIRECTORY | O_RDONLY); 162 proc_self_fd = openat(proc_fd, "self/fd", O_DIRECTORY | O_RDONLY);
163 } else { 163 } else {
164 proc_self_fd = openat(AT_FDCWD, "/proc/self/fd", O_DIRECTORY | O_RDONLY); 164 proc_self_fd = openat(AT_FDCWD, "/proc/self/fd", O_DIRECTORY | O_RDONLY);
165 if (proc_self_fd < 0) { 165 if (proc_self_fd < 0) {
166 // If this process has been chrooted (eg into /proc/self/fdinfo) then
167 // the new root dir will not have directory listing permissions for us
168 // (hence EACCES). And if we do have this permission, then /proc won't
169 // exist anyway (hence ENOENT).
170 DPCHECK(errno == EACCES || errno == ENOENT)
171 << "Unexpected failure when trying to open /proc/self/fd: ("
172 << errno << ") " << strerror(errno);
173
166 // If not available, guess false. 174 // If not available, guess false.
167 // TODO(mostynb@opera.com): add a CHECK_EQ(ENOENT, errno); Figure out what
168 // other situations are here. http://crbug.com/314985
169 return false; 175 return false;
170 } 176 }
171 } 177 }
172 CHECK_GE(proc_self_fd, 0); 178 CHECK_GE(proc_self_fd, 0);
173 179
174 // Ownership of proc_self_fd is transferred here, it must not be closed 180 // Ownership of proc_self_fd is transferred here, it must not be closed
175 // or modified afterwards except via dir. 181 // or modified afterwards except via dir.
176 ScopedDIR dir(fdopendir(proc_self_fd)); 182 ScopedDIR dir(fdopendir(proc_self_fd));
177 CHECK(dir); 183 CHECK(dir);
178 184
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 } 263 }
258 264
259 bool Credentials::DropFileSystemAccess() { 265 bool Credentials::DropFileSystemAccess() {
260 // Chrooting to a safe empty dir will only be safe if no directory file 266 // Chrooting to a safe empty dir will only be safe if no directory file
261 // descriptor is available to the process. 267 // descriptor is available to the process.
262 DCHECK(!HasOpenDirectory(-1)); 268 DCHECK(!HasOpenDirectory(-1));
263 return ChrootToSafeEmptyDir(); 269 return ChrootToSafeEmptyDir();
264 } 270 }
265 271
266 } // namespace sandbox. 272 } // namespace sandbox.
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698