Skip to content

Commit

Permalink
Linux sandbox: migrate policies to new format.
Browse files Browse the repository at this point in the history
seccomp-bpf policies are now the implementation of the interface that
lives in sandbox/linux/seccomp-bpf/sandbox_bpf_policy.h

Sandbox policies inside content/ will all derive from the SandboxBpfBasePolicy
(sandbox_bpf_base_policy.h) class.

We can now rely on real C++ inheritance to implement our policy hierarchy.

This is a first CL, part of a larger refactor. It should help minmize the risk
of error and facilitate review by keeping the general layout of the code similar.

In upcoming changes, we will:
1. Migrate NaCl and get rid of the compatibility / deprecated interfaces.
2. Extend the interface of SandboxBpfBasePolicy to be compatible with
starting a GPU sandbox and reflect all the steps.
3. Move all the policies to directories such as renderer/ and gpu/ and each
policy class will be able to live in its own file.

BUG=325535
R=creis@chromium.org, jorgelo@chromium.org, mseaborn@chromium.org, rsesek@chromium.org

Review URL: https://codereview.chromium.org/105673005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239550 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jln@chromium.org committed Dec 9, 2013
1 parent b445632 commit add747d
Show file tree
Hide file tree
Showing 10 changed files with 701 additions and 394 deletions.
1 change: 1 addition & 0 deletions components/nacl.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
'nacl/loader/nacl_helper_linux.h',
'../base/posix/unix_domain_socket_linux.cc',
'../content/common/child_process_sandbox_support_impl_shm_linux.cc',
'../content/common/sandbox_bpf_base_policy_linux.cc',
'../content/common/sandbox_init_linux.cc',
'../content/common/sandbox_seccomp_bpf_linux.cc',
'../content/public/common/content_switches.cc',
Expand Down
36 changes: 36 additions & 0 deletions content/common/sandbox_bpf_base_policy_linux.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/common/sandbox_bpf_base_policy_linux.h"

#include <errno.h>

#include "base/logging.h"
#include "sandbox/linux/seccomp-bpf-helpers/baseline_policy.h"

namespace content {

namespace {

// The errno used for denied file system access system calls, such as open(2).
static const int kFSDeniedErrno = EPERM;

} // namespace.

SandboxBpfBasePolicy::SandboxBpfBasePolicy()
: baseline_policy_(new sandbox::BaselinePolicy(kFSDeniedErrno)) {}
SandboxBpfBasePolicy::~SandboxBpfBasePolicy() {}

ErrorCode SandboxBpfBasePolicy::EvaluateSyscall(Sandbox* sandbox_compiler,
int system_call_number) const {
DCHECK(baseline_policy_);
return baseline_policy_->EvaluateSyscall(sandbox_compiler,
system_call_number);
}

int SandboxBpfBasePolicy::GetFSDeniedErrno() {
return kFSDeniedErrno;
}

} // namespace content.
40 changes: 40 additions & 0 deletions content/common/sandbox_bpf_base_policy_linux.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_COMMON_SANDBOX_BPF_BASE_POLICY_LINUX_H_
#define CONTENT_COMMON_SANDBOX_BPF_BASE_POLICY_LINUX_H_

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "sandbox/linux/seccomp-bpf-helpers/baseline_policy.h"
#include "sandbox/linux/seccomp-bpf/sandbox_bpf_policy.h"

using playground2::ErrorCode;
using playground2::Sandbox;

namespace content {

// The "baseline" BPF policy for content/. Any content/ seccomp-bpf policy
// should inherit from it.
// It implements the main SandboxBpfPolicy interface. Due to its nature
// as a "kernel attack surface reduction" layer, it's implementation-defined.
class SandboxBpfBasePolicy : public playground2::SandboxBpfPolicy {
public:
SandboxBpfBasePolicy();
virtual ~SandboxBpfBasePolicy();

virtual ErrorCode EvaluateSyscall(Sandbox* sandbox_compiler,
int system_call_number) const OVERRIDE;
// Get the errno(3) to return for filesystem errors.
static int GetFSDeniedErrno();

private:
// Compose the BaselinePolicy from sandbox/.
scoped_ptr<sandbox::BaselinePolicy> baseline_policy_;
DISALLOW_COPY_AND_ASSIGN(SandboxBpfBasePolicy);
};

} // namespace content

#endif // CONTENT_COMMON_SANDBOX_BPF_BASE_POLICY_LINUX_H_
Loading

0 comments on commit add747d

Please sign in to comment.