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

Side by Side Diff: components/nacl/loader/sandbox_linux/nacl_sandbox_linux.cc

Issue 1409633002: Non-SFI mode: Remove old Non-SFI code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/nacl/loader/sandbox_linux/nacl_sandbox_linux.h" 5 #include "components/nacl/loader/sandbox_linux/nacl_sandbox_linux.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <sys/prctl.h> 9 #include <sys/prctl.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
11 #include <sys/types.h> 11 #include <sys/types.h>
12 #include <unistd.h> 12 #include <unistd.h>
13 13
14 #include <limits> 14 #include <limits>
15 15
16 #include "base/basictypes.h" 16 #include "base/basictypes.h"
17 #include "base/callback.h" 17 #include "base/callback.h"
18 #include "base/command_line.h" 18 #include "base/command_line.h"
19 #include "base/compiler_specific.h" 19 #include "base/compiler_specific.h"
20 #include "base/files/scoped_file.h" 20 #include "base/files/scoped_file.h"
21 #include "base/logging.h" 21 #include "base/logging.h"
22 #include "base/memory/scoped_ptr.h" 22 #include "base/memory/scoped_ptr.h"
23 #include "base/posix/eintr_wrapper.h" 23 #include "base/posix/eintr_wrapper.h"
24 #include "build/build_config.h" 24 #include "build/build_config.h"
25 #include "components/nacl/common/nacl_switches.h" 25 #include "components/nacl/common/nacl_switches.h"
26 #include "components/nacl/loader/nonsfi/nonsfi_sandbox.h"
27 #include "components/nacl/loader/sandbox_linux/nacl_bpf_sandbox_linux.h" 26 #include "components/nacl/loader/sandbox_linux/nacl_bpf_sandbox_linux.h"
28 #include "content/public/common/content_switches.h" 27 #include "content/public/common/content_switches.h"
29 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" 28 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
30 #include "sandbox/linux/services/credentials.h" 29 #include "sandbox/linux/services/credentials.h"
31 #include "sandbox/linux/services/namespace_sandbox.h" 30 #include "sandbox/linux/services/namespace_sandbox.h"
32 #include "sandbox/linux/services/proc_util.h" 31 #include "sandbox/linux/services/proc_util.h"
33 #include "sandbox/linux/services/resource_limits.h" 32 #include "sandbox/linux/services/resource_limits.h"
34 #include "sandbox/linux/services/thread_helpers.h" 33 #include "sandbox/linux/services/thread_helpers.h"
35 #include "sandbox/linux/suid/client/setuid_sandbox_client.h" 34 #include "sandbox/linux/suid/client/setuid_sandbox_client.h"
36 35
36 #if defined(OS_NACL_NONSFI)
37 #include "components/nacl/loader/nonsfi/nonsfi_sandbox.h"
Mark Seaborn 2015/10/15 18:10:11 Nit: I don't think you need to conditionalise this
hidehiko 2015/10/19 04:39:18 Done.
38 #endif
39
37 namespace nacl { 40 namespace nacl {
38 41
39 namespace { 42 namespace {
40 43
41 // This is a poor man's check on whether we are sandboxed. 44 // This is a poor man's check on whether we are sandboxed.
42 bool IsSandboxed() { 45 bool IsSandboxed() {
43 int proc_fd = open("/proc/self/exe", O_RDONLY); 46 int proc_fd = open("/proc/self/exe", O_RDONLY);
44 if (proc_fd >= 0) { 47 if (proc_fd >= 0) {
45 PCHECK(0 == IGNORE_EINTR(close(proc_fd))); 48 PCHECK(0 == IGNORE_EINTR(close(proc_fd)));
46 return false; 49 return false;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // have a single thread running here. 181 // have a single thread running here.
179 DCHECK(!layer_one_sealed_); 182 DCHECK(!layer_one_sealed_);
180 CHECK(IsSingleThreaded()); 183 CHECK(IsSingleThreaded());
181 CheckForExpectedNumberOfOpenFds(); 184 CheckForExpectedNumberOfOpenFds();
182 185
183 RestrictAddressSpaceUsage(); 186 RestrictAddressSpaceUsage();
184 187
185 // Pass proc_fd_ ownership to the BPF sandbox, which guarantees it will 188 // Pass proc_fd_ ownership to the BPF sandbox, which guarantees it will
186 // be closed. There is no point in keeping it around since the BPF policy 189 // be closed. There is no point in keeping it around since the BPF policy
187 // will prevent its usage. 190 // will prevent its usage.
188 if (uses_nonsfi_mode) {
189 layer_two_enabled_ = nacl::nonsfi::InitializeBPFSandbox(proc_fd_.Pass());
190 layer_two_is_nonsfi_ = true;
191 } else {
192 #if defined(OS_NACL_NONSFI) 191 #if defined(OS_NACL_NONSFI)
193 LOG(FATAL) << "nacl_helper_nonsfi can run only Non-SFI plugin."; 192 CHECK(uses_nonsfi_mode) << "nacl_helper_nonsfi can run only Non-SFI plugin.";
Mark Seaborn 2015/10/15 18:10:11 Consistency nit: The #else branch doesn't have a m
hidehiko 2015/10/19 04:39:18 Done.
193 layer_two_enabled_ = nacl::nonsfi::InitializeBPFSandbox(proc_fd_.Pass());
194 layer_two_is_nonsfi_ = true;
194 #else 195 #else
195 layer_two_enabled_ = nacl::InitializeBPFSandbox(proc_fd_.Pass()); 196 CHECK(!uses_nonsfi_mode);
197 layer_two_enabled_ = nacl::InitializeBPFSandbox(proc_fd_.Pass());
196 #endif 198 #endif
197 }
198 } 199 }
199 200
200 void NaClSandbox::SealLayerOneSandbox() { 201 void NaClSandbox::SealLayerOneSandbox() {
201 if (proc_fd_.is_valid() && !layer_two_enabled_) { 202 if (proc_fd_.is_valid() && !layer_two_enabled_) {
202 // If nothing prevents us, check that there is no superfluous directory 203 // If nothing prevents us, check that there is no superfluous directory
203 // open. 204 // open.
204 CHECK(!HasOpenDirectory()); 205 CHECK(!HasOpenDirectory());
205 } 206 }
206 proc_fd_.reset(); 207 proc_fd_.reset();
207 layer_one_sealed_ = true; 208 layer_one_sealed_ = true;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 static const char kNoBpfMsg[] = 240 static const char kNoBpfMsg[] =
240 "The seccomp-bpf sandbox is not engaged for NaCl:"; 241 "The seccomp-bpf sandbox is not engaged for NaCl:";
241 if (can_be_no_sandbox) 242 if (can_be_no_sandbox)
242 LOG(ERROR) << kNoBpfMsg << kItIsDangerousMsg; 243 LOG(ERROR) << kNoBpfMsg << kItIsDangerousMsg;
243 else 244 else
244 LOG(FATAL) << kNoBpfMsg << kItIsNotAllowedMsg; 245 LOG(FATAL) << kNoBpfMsg << kItIsNotAllowedMsg;
245 } 246 }
246 } 247 }
247 248
248 } // namespace nacl 249 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698