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 <errno.h> | 7 #include <errno.h> |
8 #include <signal.h> | 8 #include <signal.h> |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 #include <sys/capability.h> | 10 #include <sys/capability.h> |
11 #include <sys/syscall.h> | 11 #include <sys/syscall.h> |
12 #include <sys/types.h> | 12 #include <sys/types.h> |
13 #include <sys/wait.h> | 13 #include <sys/wait.h> |
14 #include <unistd.h> | 14 #include <unistd.h> |
15 | 15 |
16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
17 #include "base/bind.h" | 17 #include "base/bind.h" |
18 #include "base/logging.h" | 18 #include "base/logging.h" |
19 #include "base/posix/eintr_wrapper.h" | 19 #include "base/posix/eintr_wrapper.h" |
20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
21 #include "base/template_util.h" | 21 #include "base/template_util.h" |
22 #include "base/third_party/valgrind/valgrind.h" | 22 #include "base/third_party/valgrind/valgrind.h" |
23 #include "base/threading/thread.h" | 23 #include "base/threading/thread.h" |
24 #include "sandbox/linux/services/proc_util.h" | |
25 #include "sandbox/linux/services/syscall_wrappers.h" | 24 #include "sandbox/linux/services/syscall_wrappers.h" |
26 | 25 |
27 namespace { | 26 namespace { |
28 | 27 |
29 bool IsRunningOnValgrind() { return RUNNING_ON_VALGRIND; } | 28 bool IsRunningOnValgrind() { return RUNNING_ON_VALGRIND; } |
30 | 29 |
31 struct CapFreeDeleter { | 30 struct CapFreeDeleter { |
32 inline void operator()(cap_t cap) const { | 31 inline void operator()(cap_t cap) const { |
33 int ret = cap_free(cap); | 32 int ret = cap_free(cap); |
34 CHECK_EQ(0, ret); | 33 CHECK_EQ(0, ret); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 DCHECK(GetRESIds(NULL, NULL)); | 240 DCHECK(GetRESIds(NULL, NULL)); |
242 const char kGidMapFile[] = "/proc/self/gid_map"; | 241 const char kGidMapFile[] = "/proc/self/gid_map"; |
243 const char kUidMapFile[] = "/proc/self/uid_map"; | 242 const char kUidMapFile[] = "/proc/self/uid_map"; |
244 CHECK(WriteToIdMapFile(kGidMapFile, gid)); | 243 CHECK(WriteToIdMapFile(kGidMapFile, gid)); |
245 CHECK(WriteToIdMapFile(kUidMapFile, uid)); | 244 CHECK(WriteToIdMapFile(kUidMapFile, uid)); |
246 DCHECK(GetRESIds(NULL, NULL)); | 245 DCHECK(GetRESIds(NULL, NULL)); |
247 return true; | 246 return true; |
248 } | 247 } |
249 | 248 |
250 bool Credentials::DropFileSystemAccess() { | 249 bool Credentials::DropFileSystemAccess() { |
251 // Chrooting to a safe empty dir will only be safe if no directory file | |
252 // descriptor is available to the process. | |
253 DCHECK(!ProcUtil::HasOpenDirectory(-1)); | |
254 return ChrootToSafeEmptyDir(); | 250 return ChrootToSafeEmptyDir(); |
255 } | 251 } |
256 | 252 |
257 } // namespace sandbox. | 253 } // namespace sandbox. |
OLD | NEW |