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
3 // found in the LICENSE file.
5 #include "content/renderer/renderer_main_platform_delegate.h"
10 #include "base/command_line.h"
11 #include "base/file_util.h"
12 #include "base/logging.h"
13 #include "content/common/sandbox_linux.h"
14 #include "content/public/common/content_switches.h"
15 #include "content/public/common/sandbox_init.h"
19 RendererMainPlatformDelegate::RendererMainPlatformDelegate(
20 const MainFunctionParams
& parameters
)
21 : parameters_(parameters
) {
24 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() {
27 void RendererMainPlatformDelegate::PlatformInitialize() {
30 void RendererMainPlatformDelegate::PlatformUninitialize() {
33 bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox
) {
34 // The sandbox is started in the zygote process: zygote_main_linux.cc
35 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandbox
39 bool RendererMainPlatformDelegate::EnableSandbox() {
40 // The setuid sandbox is started in the zygote process: zygote_main_linux.cc
41 // http://code.google.com/p/chromium/wiki/LinuxSUIDSandbox
43 // Anything else is started in InitializeSandbox().
44 LinuxSandbox::InitializeSandbox();
48 void RendererMainPlatformDelegate::RunSandboxTests(bool no_sandbox
) {
49 // The LinuxSandbox class requires going through initialization before
50 // GetStatus() and others can be used. When we are not launched through the
51 // Zygote, this initialization will only happen in the renderer process if
52 // EnableSandbox() above is called, which it won't necesserily be.
53 // This only happens with flags such as --renderer-cmd-prefix which are
58 // about:sandbox uses a value returned from LinuxSandbox::GetStatus() before
59 // any renderer has been started.
60 // Here, we test that the status of SeccompBpf in the renderer is consistent
61 // with what LinuxSandbox::GetStatus() said we would do.
62 class LinuxSandbox
* linux_sandbox
= LinuxSandbox::GetInstance();
63 if (linux_sandbox
->GetStatus() & kSandboxLinuxSeccompBpf
) {
64 CHECK(linux_sandbox
->seccomp_bpf_started());
67 // Under the setuid sandbox, we should not be able to open any file via the
69 if (linux_sandbox
->GetStatus() & kSandboxLinuxSUID
) {
70 CHECK(!file_util::PathExists(base::FilePath("/proc/cpuinfo")));
73 #if defined(__x86_64__)
74 // Limit this test to architectures where seccomp BPF is active in renderers.
75 if (linux_sandbox
->seccomp_bpf_started()) {
77 // This should normally return EBADF since the first argument is bogus,
78 // but we know that under the seccomp-bpf sandbox, this should return EPERM.
79 CHECK_EQ(fchmod(-1, 07777), -1);
80 CHECK_EQ(errno
, EPERM
);
85 } // namespace content