OLD | NEW |
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 Loading... |
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 Loading... |
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. |
OLD | NEW |