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

Side by Side Diff: content/common/sandbox_linux/sandbox_linux.cc

Issue 197873014: Revert of Implement ScopedFD in terms of ScopedGeneric. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « content/child/npapi/np_channel_base.cc ('k') | content/common/sandbox_mac.mm » ('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 (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 <dirent.h> 5 #include <dirent.h>
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <sys/resource.h> 7 #include <sys/resource.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 #include <sys/time.h> 9 #include <sys/time.h>
10 #include <sys/types.h> 10 #include <sys/types.h>
11 #include <unistd.h> 11 #include <unistd.h>
12 12
13 #include <limits> 13 #include <limits>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/callback_helpers.h" 16 #include "base/callback_helpers.h"
17 #include "base/command_line.h" 17 #include "base/command_line.h"
18 #include "base/files/scoped_file.h"
19 #include "base/logging.h" 18 #include "base/logging.h"
20 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
21 #include "base/memory/singleton.h" 20 #include "base/memory/singleton.h"
22 #include "base/posix/eintr_wrapper.h" 21 #include "base/posix/eintr_wrapper.h"
23 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
24 #include "base/time/time.h" 23 #include "base/time/time.h"
25 #include "build/build_config.h" 24 #include "build/build_config.h"
26 #include "content/common/sandbox_linux/sandbox_linux.h" 25 #include "content/common/sandbox_linux/sandbox_linux.h"
27 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h" 26 #include "content/common/sandbox_linux/sandbox_seccomp_bpf_linux.h"
28 #include "content/public/common/content_switches.h" 27 #include "content/public/common/content_switches.h"
29 #include "content/public/common/sandbox_linux.h" 28 #include "content/public/common/sandbox_linux.h"
30 #include "sandbox/linux/services/credentials.h" 29 #include "sandbox/linux/services/credentials.h"
31 #include "sandbox/linux/services/thread_helpers.h" 30 #include "sandbox/linux/services/thread_helpers.h"
32 #include "sandbox/linux/services/yama.h" 31 #include "sandbox/linux/services/yama.h"
33 #include "sandbox/linux/suid/client/setuid_sandbox_client.h" 32 #include "sandbox/linux/suid/client/setuid_sandbox_client.h"
34 33
35 using sandbox::Yama; 34 using sandbox::Yama;
36 35
37 namespace { 36 namespace {
38 37
39 struct FDCloser { 38 struct FDCloser {
40 inline void operator()(int* fd) const { 39 inline void operator()(int* fd) const {
41 DCHECK(fd); 40 DCHECK(fd);
42 PCHECK(0 == IGNORE_EINTR(close(*fd))); 41 PCHECK(0 == IGNORE_EINTR(close(*fd)));
43 *fd = -1; 42 *fd = -1;
44 } 43 }
45 }; 44 };
46 45
46 // Don't use base::ScopedFD since it doesn't CHECK that the file descriptor was
47 // closed.
48 typedef scoped_ptr<int, FDCloser> SafeScopedFD;
49
47 void LogSandboxStarted(const std::string& sandbox_name) { 50 void LogSandboxStarted(const std::string& sandbox_name) {
48 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 51 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
49 const std::string process_type = 52 const std::string process_type =
50 command_line.GetSwitchValueASCII(switches::kProcessType); 53 command_line.GetSwitchValueASCII(switches::kProcessType);
51 const std::string activated_sandbox = 54 const std::string activated_sandbox =
52 "Activated " + sandbox_name + " sandbox for process type: " + 55 "Activated " + sandbox_name + " sandbox for process type: " +
53 process_type + "."; 56 process_type + ".";
54 #if defined(OS_CHROMEOS) 57 #if defined(OS_CHROMEOS)
55 LOG(WARNING) << activated_sandbox; 58 LOG(WARNING) << activated_sandbox;
56 #else 59 #else
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } 196 }
194 197
195 return sandbox_status_flags_; 198 return sandbox_status_flags_;
196 } 199 }
197 200
198 // Threads are counted via /proc/self/task. This is a little hairy because of 201 // Threads are counted via /proc/self/task. This is a little hairy because of
199 // PID namespaces and existing sandboxes, so "self" must really be used instead 202 // PID namespaces and existing sandboxes, so "self" must really be used instead
200 // of using the pid. 203 // of using the pid.
201 bool LinuxSandbox::IsSingleThreaded() const { 204 bool LinuxSandbox::IsSingleThreaded() const {
202 bool is_single_threaded = false; 205 bool is_single_threaded = false;
203 base::ScopedFD proc_self_task(OpenProcTaskFd(proc_fd_)); 206 int proc_self_task = OpenProcTaskFd(proc_fd_);
204 207
205 // In Debug mode, it's mandatory to be able to count threads to catch bugs. 208 // In Debug mode, it's mandatory to be able to count threads to catch bugs.
206 #if !defined(NDEBUG) 209 #if !defined(NDEBUG)
207 // Using CHECK here since we want to check all the cases where 210 // Using CHECK here since we want to check all the cases where
208 // !defined(NDEBUG) 211 // !defined(NDEBUG)
209 // gets built. 212 // gets built.
210 CHECK(proc_self_task.is_valid()) 213 CHECK_LE(0, proc_self_task) << "Could not count threads, the sandbox was not "
211 << "Could not count threads, the sandbox was not " 214 << "pre-initialized properly.";
212 << "pre-initialized properly.";
213 #endif // !defined(NDEBUG) 215 #endif // !defined(NDEBUG)
214 216
215 if (!proc_self_task.is_valid()) { 217 if (proc_self_task < 0) {
216 // Pretend to be monothreaded if it can't be determined (for instance the 218 // Pretend to be monothreaded if it can't be determined (for instance the
217 // setuid sandbox is already engaged but no proc_fd_ is available). 219 // setuid sandbox is already engaged but no proc_fd_ is available).
218 is_single_threaded = true; 220 is_single_threaded = true;
219 } else { 221 } else {
222 SafeScopedFD task_closer(&proc_self_task);
220 is_single_threaded = 223 is_single_threaded =
221 sandbox::ThreadHelpers::IsSingleThreaded(proc_self_task.get()); 224 sandbox::ThreadHelpers::IsSingleThreaded(proc_self_task);
222 } 225 }
223 226
224 return is_single_threaded; 227 return is_single_threaded;
225 } 228 }
226 229
227 bool LinuxSandbox::seccomp_bpf_started() const { 230 bool LinuxSandbox::seccomp_bpf_started() const {
228 return seccomp_bpf_started_; 231 return seccomp_bpf_started_;
229 } 232 }
230 233
231 sandbox::SetuidSandboxClient* 234 sandbox::SetuidSandboxClient*
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 (sandbox_status_flags_ != kSandboxLinuxInvalid) && 384 (sandbox_status_flags_ != kSandboxLinuxInvalid) &&
382 (GetStatus() & kSandboxLinuxSeccompBPF); 385 (GetStatus() & kSandboxLinuxSeccompBPF);
383 } 386 }
384 if (promised_seccomp_bpf_would_start) { 387 if (promised_seccomp_bpf_would_start) {
385 CHECK(seccomp_bpf_started_); 388 CHECK(seccomp_bpf_started_);
386 } 389 }
387 } 390 }
388 391
389 void LinuxSandbox::StopThreadAndEnsureNotCounted(base::Thread* thread) const { 392 void LinuxSandbox::StopThreadAndEnsureNotCounted(base::Thread* thread) const {
390 DCHECK(thread); 393 DCHECK(thread);
391 base::ScopedFD proc_self_task(OpenProcTaskFd(proc_fd_)); 394 int proc_self_task = OpenProcTaskFd(proc_fd_);
392 PCHECK(proc_self_task.is_valid()); 395 PCHECK(proc_self_task >= 0);
393 CHECK(sandbox::ThreadHelpers::StopThreadAndWatchProcFS(proc_self_task.get(), 396 SafeScopedFD task_closer(&proc_self_task);
394 thread)); 397 CHECK(
398 sandbox::ThreadHelpers::StopThreadAndWatchProcFS(proc_self_task, thread));
395 } 399 }
396 400
397 } // namespace content 401 } // namespace content
OLDNEW
« no previous file with comments | « content/child/npapi/np_channel_base.cc ('k') | content/common/sandbox_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698