Commit ef0ebd22 authored by Tom Sepez's avatar Tom Sepez Committed by Commit Bot

Move Sandbox::Status flags to SandboxLinux::Status

This is a small bit of overdue tidying, in that the flags should be
in the header with the method that returns them.

Change-Id: I8f9e8290a3ec36b53fa64ca69fcc3a11ac3b0e7c
Reviewed-on: https://chromium-review.googlesource.com/773508Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517465}
parent 4c47c5d4
...@@ -28,23 +28,23 @@ static void SetSandboxStatusData(content::WebUIDataSource* source) { ...@@ -28,23 +28,23 @@ static void SetSandboxStatusData(content::WebUIDataSource* source) {
const int status = const int status =
content::ZygoteHost::GetInstance()->GetRendererSandboxStatus(); content::ZygoteHost::GetInstance()->GetRendererSandboxStatus();
source->AddBoolean("suid", status & service_manager::Sandbox::kSUID); source->AddBoolean("suid", status & service_manager::SandboxLinux::kSUID);
source->AddBoolean("userNs", status & service_manager::Sandbox::kUserNS); source->AddBoolean("userNs", status & service_manager::SandboxLinux::kUserNS);
source->AddBoolean("pidNs", status & service_manager::Sandbox::kPIDNS); source->AddBoolean("pidNs", status & service_manager::SandboxLinux::kPIDNS);
source->AddBoolean("netNs", status & service_manager::Sandbox::kNetNS); source->AddBoolean("netNs", status & service_manager::SandboxLinux::kNetNS);
source->AddBoolean("seccompBpf", source->AddBoolean("seccompBpf",
status & service_manager::Sandbox::kSeccompBPF); status & service_manager::SandboxLinux::kSeccompBPF);
source->AddBoolean("seccompTsync", source->AddBoolean("seccompTsync",
status & service_manager::Sandbox::kSeccompTSYNC); status & service_manager::SandboxLinux::kSeccompTSYNC);
source->AddBoolean("yama", status & service_manager::Sandbox::kYama); source->AddBoolean("yama", status & service_manager::SandboxLinux::kYama);
// Require either the setuid or namespace sandbox for our first-layer sandbox. // Require either the setuid or namespace sandbox for our first-layer sandbox.
bool good_layer1 = (status & service_manager::Sandbox::kSUID || bool good_layer1 = (status & service_manager::SandboxLinux::kSUID ||
status & service_manager::Sandbox::kUserNS) && status & service_manager::SandboxLinux::kUserNS) &&
status & service_manager::Sandbox::kPIDNS && status & service_manager::SandboxLinux::kPIDNS &&
status & service_manager::Sandbox::kNetNS; status & service_manager::SandboxLinux::kNetNS;
// A second-layer sandbox is also required to be adequately sandboxed. // A second-layer sandbox is also required to be adequately sandboxed.
bool good_layer2 = status & service_manager::Sandbox::kSeccompBPF; bool good_layer2 = status & service_manager::SandboxLinux::kSeccompBPF;
source->AddBoolean("sandboxGood", good_layer1 && good_layer2); source->AddBoolean("sandboxGood", good_layer1 && good_layer2);
} }
#endif #endif
......
...@@ -47,13 +47,13 @@ bool RendererMainPlatformDelegate::EnableSandbox() { ...@@ -47,13 +47,13 @@ bool RendererMainPlatformDelegate::EnableSandbox() {
// Here, we test that the status of SeccompBpf in the renderer is consistent // Here, we test that the status of SeccompBpf in the renderer is consistent
// with what SandboxLinux::GetStatus() said we would do. // with what SandboxLinux::GetStatus() said we would do.
auto* linux_sandbox = service_manager::SandboxLinux::GetInstance(); auto* linux_sandbox = service_manager::SandboxLinux::GetInstance();
if (linux_sandbox->GetStatus() & service_manager::Sandbox::kSeccompBPF) { if (linux_sandbox->GetStatus() & service_manager::SandboxLinux::kSeccompBPF) {
CHECK(linux_sandbox->seccomp_bpf_started()); CHECK(linux_sandbox->seccomp_bpf_started());
} }
// Under the setuid sandbox, we should not be able to open any file via the // Under the setuid sandbox, we should not be able to open any file via the
// filesystem. // filesystem.
if (linux_sandbox->GetStatus() & service_manager::Sandbox::kSUID) { if (linux_sandbox->GetStatus() & service_manager::SandboxLinux::kSUID) {
CHECK(!base::PathExists(base::FilePath("/proc/cpuinfo"))); CHECK(!base::PathExists(base::FilePath("/proc/cpuinfo")));
} }
......
...@@ -225,11 +225,11 @@ bool Zygote::GetProcessInfo(base::ProcessHandle pid, ...@@ -225,11 +225,11 @@ bool Zygote::GetProcessInfo(base::ProcessHandle pid,
} }
bool Zygote::UsingSUIDSandbox() const { bool Zygote::UsingSUIDSandbox() const {
return sandbox_flags_ & service_manager::Sandbox::kSUID; return sandbox_flags_ & service_manager::SandboxLinux::kSUID;
} }
bool Zygote::UsingNSSandbox() const { bool Zygote::UsingNSSandbox() const {
return sandbox_flags_ & service_manager::Sandbox::kUserNS; return sandbox_flags_ & service_manager::SandboxLinux::kUserNS;
} }
bool Zygote::HandleRequestFromBrowser(int fd) { bool Zygote::HandleRequestFromBrowser(int fd) {
...@@ -445,8 +445,8 @@ int Zygote::ForkWithRealPid(const std::string& process_type, ...@@ -445,8 +445,8 @@ int Zygote::ForkWithRealPid(const std::string& process_type,
CHECK_NE(pid, 0); CHECK_NE(pid, 0);
} else { } else {
CreatePipe(&read_pipe, &write_pipe); CreatePipe(&read_pipe, &write_pipe);
if (sandbox_flags_ & service_manager::Sandbox::kPIDNS && if (sandbox_flags_ & service_manager::SandboxLinux::kPIDNS &&
sandbox_flags_ & service_manager::Sandbox::kUserNS) { sandbox_flags_ & service_manager::SandboxLinux::kUserNS) {
pid = sandbox::NamespaceSandbox::ForkInNewPidNamespace( pid = sandbox::NamespaceSandbox::ForkInNewPidNamespace(
/*drop_capabilities_in_child=*/true); /*drop_capabilities_in_child=*/true);
} else { } else {
......
...@@ -615,11 +615,11 @@ bool ZygoteMain( ...@@ -615,11 +615,11 @@ bool ZygoteMain(
const int sandbox_flags = linux_sandbox->GetStatus(); const int sandbox_flags = linux_sandbox->GetStatus();
const bool setuid_sandbox_engaged = const bool setuid_sandbox_engaged =
sandbox_flags & service_manager::Sandbox::kSUID; sandbox_flags & service_manager::SandboxLinux::kSUID;
CHECK_EQ(using_setuid_sandbox, setuid_sandbox_engaged); CHECK_EQ(using_setuid_sandbox, setuid_sandbox_engaged);
const bool namespace_sandbox_engaged = const bool namespace_sandbox_engaged =
sandbox_flags & service_manager::Sandbox::kUserNS; sandbox_flags & service_manager::SandboxLinux::kUserNS;
CHECK_EQ(using_namespace_sandbox, namespace_sandbox_engaged); CHECK_EQ(using_namespace_sandbox, namespace_sandbox_engaged);
Zygote zygote(sandbox_flags, std::move(fork_delegates), extra_children, Zygote zygote(sandbox_flags, std::move(fork_delegates), extra_children,
......
...@@ -132,7 +132,7 @@ bool UpdateProcessTypeAndEnableSandbox( ...@@ -132,7 +132,7 @@ bool UpdateProcessTypeAndEnableSandbox(
SandboxLinux::SandboxLinux() SandboxLinux::SandboxLinux()
: proc_fd_(-1), : proc_fd_(-1),
seccomp_bpf_started_(false), seccomp_bpf_started_(false),
sandbox_status_flags_(Sandbox::kInvalid), sandbox_status_flags_(kInvalid),
pre_initialized_(false), pre_initialized_(false),
seccomp_bpf_supported_(false), seccomp_bpf_supported_(false),
seccomp_bpf_with_tsync_supported_(false), seccomp_bpf_with_tsync_supported_(false),
...@@ -230,35 +230,35 @@ int SandboxLinux::GetStatus() { ...@@ -230,35 +230,35 @@ int SandboxLinux::GetStatus() {
if (!pre_initialized_) { if (!pre_initialized_) {
return 0; return 0;
} }
if (sandbox_status_flags_ == Sandbox::kInvalid) { if (sandbox_status_flags_ == kInvalid) {
// Initialize sandbox_status_flags_. // Initialize sandbox_status_flags_.
sandbox_status_flags_ = 0; sandbox_status_flags_ = 0;
if (setuid_sandbox_client_->IsSandboxed()) { if (setuid_sandbox_client_->IsSandboxed()) {
sandbox_status_flags_ |= Sandbox::kSUID; sandbox_status_flags_ |= kSUID;
if (setuid_sandbox_client_->IsInNewPIDNamespace()) if (setuid_sandbox_client_->IsInNewPIDNamespace())
sandbox_status_flags_ |= Sandbox::kPIDNS; sandbox_status_flags_ |= kPIDNS;
if (setuid_sandbox_client_->IsInNewNETNamespace()) if (setuid_sandbox_client_->IsInNewNETNamespace())
sandbox_status_flags_ |= Sandbox::kNetNS; sandbox_status_flags_ |= kNetNS;
} else if (sandbox::NamespaceSandbox::InNewUserNamespace()) { } else if (sandbox::NamespaceSandbox::InNewUserNamespace()) {
sandbox_status_flags_ |= Sandbox::kUserNS; sandbox_status_flags_ |= kUserNS;
if (sandbox::NamespaceSandbox::InNewPidNamespace()) if (sandbox::NamespaceSandbox::InNewPidNamespace())
sandbox_status_flags_ |= Sandbox::kPIDNS; sandbox_status_flags_ |= kPIDNS;
if (sandbox::NamespaceSandbox::InNewNetNamespace()) if (sandbox::NamespaceSandbox::InNewNetNamespace())
sandbox_status_flags_ |= Sandbox::kNetNS; sandbox_status_flags_ |= kNetNS;
} }
// We report whether the sandbox will be activated when renderers, workers // We report whether the sandbox will be activated when renderers, workers
// and PPAPI plugins go through sandbox initialization. // and PPAPI plugins go through sandbox initialization.
if (seccomp_bpf_supported()) { if (seccomp_bpf_supported()) {
sandbox_status_flags_ |= Sandbox::kSeccompBPF; sandbox_status_flags_ |= kSeccompBPF;
} }
if (seccomp_bpf_with_tsync_supported()) { if (seccomp_bpf_with_tsync_supported()) {
sandbox_status_flags_ |= Sandbox::kSeccompTSYNC; sandbox_status_flags_ |= kSeccompTSYNC;
} }
if (yama_is_enforcing_) { if (yama_is_enforcing_) {
sandbox_status_flags_ |= Sandbox::kYama; sandbox_status_flags_ |= kYama;
} }
} }
...@@ -519,8 +519,7 @@ void SandboxLinux::CheckForBrokenPromises(SandboxType sandbox_type) { ...@@ -519,8 +519,7 @@ void SandboxLinux::CheckForBrokenPromises(SandboxType sandbox_type) {
} }
// Make sure that any promise made with GetStatus() wasn't broken. // Make sure that any promise made with GetStatus() wasn't broken.
bool promised_seccomp_bpf_would_start = bool promised_seccomp_bpf_would_start =
(sandbox_status_flags_ != Sandbox::kInvalid) && (sandbox_status_flags_ != kInvalid) && (GetStatus() & kSeccompBPF);
(GetStatus() & Sandbox::kSeccompBPF);
CHECK(!promised_seccomp_bpf_would_start || seccomp_bpf_started_); CHECK(!promised_seccomp_bpf_would_start || seccomp_bpf_started_);
} }
......
...@@ -65,6 +65,35 @@ class SERVICE_MANAGER_SANDBOX_EXPORT SandboxLinux { ...@@ -65,6 +65,35 @@ class SERVICE_MANAGER_SANDBOX_EXPORT SandboxLinux {
METHOD_MATCH_WITH_FALLBACK = 37, METHOD_MATCH_WITH_FALLBACK = 37,
}; };
// These form a bitmask which describes the conditions of the Linux sandbox.
// Note: this doesn't strictly give you the current status, it states
// what will be enabled when the relevant processes are initialized.
enum Status {
// SUID sandbox active.
kSUID = 1 << 0,
// Sandbox is using a new PID namespace.
kPIDNS = 1 << 1,
// Sandbox is using a new network namespace.
kNetNS = 1 << 2,
// seccomp-bpf sandbox active.
kSeccompBPF = 1 << 3,
// The Yama LSM module is present and enforcing.
kYama = 1 << 4,
// seccomp-bpf sandbox is active and the kernel supports TSYNC.
kSeccompTSYNC = 1 << 5,
// User namespace sandbox active.
kUserNS = 1 << 6,
// A flag that denotes an invalid sandbox status.
kInvalid = 1 << 31,
};
// SandboxLinux Options are a superset of SandboxSecompBPF Options. // SandboxLinux Options are a superset of SandboxSecompBPF Options.
struct Options : public SandboxSeccompBPF::Options { struct Options : public SandboxSeccompBPF::Options {
// When running with a zygote, the namespace sandbox will have already // When running with a zygote, the namespace sandbox will have already
...@@ -121,15 +150,17 @@ class SERVICE_MANAGER_SANDBOX_EXPORT SandboxLinux { ...@@ -121,15 +150,17 @@ class SERVICE_MANAGER_SANDBOX_EXPORT SandboxLinux {
// Returns the status of the renderer, worker and ppapi sandbox. Can only // Returns the status of the renderer, worker and ppapi sandbox. Can only
// be queried after going through PreinitializeSandbox(). This is a bitmask // be queried after going through PreinitializeSandbox(). This is a bitmask
// and uses the constants defined in "enum LinuxSandboxStatus". Since the // and uses the constants defined in "enum Status" above. Since the
// status needs to be provided before the sandboxes are actually started, // status needs to be provided before the sandboxes are actually started,
// this returns what will actually happen once InitializeSandbox() // this returns what will actually happen once InitializeSandbox()
// is called from inside these processes. // is called from inside these processes.
int GetStatus(); int GetStatus();
// Returns true if the current process is single-threaded or if the number // Returns true if the current process is single-threaded or if the number
// of threads cannot be determined. // of threads cannot be determined.
bool IsSingleThreaded() const; bool IsSingleThreaded() const;
// Did we start Seccomp BPF?
// Returns true if we started Seccomp BPF.
bool seccomp_bpf_started() const; bool seccomp_bpf_started() const;
// Simple accessor for our instance of the setuid sandbox. Will never return // Simple accessor for our instance of the setuid sandbox. Will never return
......
...@@ -36,35 +36,6 @@ namespace service_manager { ...@@ -36,35 +36,6 @@ namespace service_manager {
class SERVICE_MANAGER_SANDBOX_EXPORT Sandbox { class SERVICE_MANAGER_SANDBOX_EXPORT Sandbox {
public: public:
#if defined(OS_LINUX) #if defined(OS_LINUX)
// These form a bitmask which describes the conditions of the Linux sandbox.
// Note: this doesn't strictly give you the current status, it states
// what will be enabled when the relevant processes are initialized.
enum Status {
// SUID sandbox active.
kSUID = 1 << 0,
// Sandbox is using a new PID namespace.
kPIDNS = 1 << 1,
// Sandbox is using a new network namespace.
kNetNS = 1 << 2,
// seccomp-bpf sandbox active.
kSeccompBPF = 1 << 3,
// The Yama LSM module is present and enforcing.
kYama = 1 << 4,
// seccomp-bpf sandbox is active and the kernel supports TSYNC.
kSeccompTSYNC = 1 << 5,
// User namespace sandbox active.
kUserNS = 1 << 6,
// A flag that denotes an invalid sandbox status.
kInvalid = 1 << 31,
};
static bool Initialize(SandboxType sandbox_type, static bool Initialize(SandboxType sandbox_type,
SandboxLinux::PreSandboxHook hook, SandboxLinux::PreSandboxHook hook,
const SandboxLinux::Options& options); const SandboxLinux::Options& options);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment