Commit 3788a74e authored by jln@chromium.org's avatar jln@chromium.org

Linux GPU sandbox: only allocate broker policy in the broker.

The GPU broker policy was allocated in the main GPU process and then used in
the broker process. We switch the logic so that the broker policy is only ever
allocated in the broker process itself.

Besides fixing a small memory leak (in the GPU process), this makes sure that a
policy is only ever used in the process that allocated it. This will allow to
bind policies with properties such as "which processes does this policy allow
to send signal to".

BUG=367986
R=jorgelo@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266726 0039d316-1c4b-4281-b951-d872f2087c98
parent 52c43cbf
...@@ -94,13 +94,16 @@ void AddArmGpuWhitelist(std::vector<std::string>* read_whitelist, ...@@ -94,13 +94,16 @@ void AddArmGpuWhitelist(std::vector<std::string>* read_whitelist,
class CrosArmGpuBrokerProcessPolicy : public CrosArmGpuProcessPolicy { class CrosArmGpuBrokerProcessPolicy : public CrosArmGpuProcessPolicy {
public: public:
CrosArmGpuBrokerProcessPolicy() : CrosArmGpuProcessPolicy(false) {} static sandbox::SandboxBPFPolicy* Create() {
return new CrosArmGpuBrokerProcessPolicy();
}
virtual ~CrosArmGpuBrokerProcessPolicy() {} virtual ~CrosArmGpuBrokerProcessPolicy() {}
virtual ErrorCode EvaluateSyscall(SandboxBPF* sandbox_compiler, virtual ErrorCode EvaluateSyscall(SandboxBPF* sandbox_compiler,
int system_call_number) const OVERRIDE; int system_call_number) const OVERRIDE;
private: private:
CrosArmGpuBrokerProcessPolicy() : CrosArmGpuProcessPolicy(false) {}
DISALLOW_COPY_AND_ASSIGN(CrosArmGpuBrokerProcessPolicy); DISALLOW_COPY_AND_ASSIGN(CrosArmGpuBrokerProcessPolicy);
}; };
...@@ -169,12 +172,9 @@ bool CrosArmGpuProcessPolicy::PreSandboxHook() { ...@@ -169,12 +172,9 @@ bool CrosArmGpuProcessPolicy::PreSandboxHook() {
// Add ARM-specific files to whitelist in the broker. // Add ARM-specific files to whitelist in the broker.
AddArmGpuWhitelist(&read_whitelist_extra, &write_whitelist_extra); AddArmGpuWhitelist(&read_whitelist_extra, &write_whitelist_extra);
InitGpuBrokerProcess( InitGpuBrokerProcess(CrosArmGpuBrokerProcessPolicy::Create,
base::Bind(&SandboxSeccompBPF::StartSandboxWithExternalPolicy, read_whitelist_extra,
base::Passed(scoped_ptr<sandbox::SandboxBPFPolicy>( write_whitelist_extra);
new CrosArmGpuBrokerProcessPolicy))),
read_whitelist_extra,
write_whitelist_extra);
const int dlopen_flag = RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE; const int dlopen_flag = RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE;
......
...@@ -106,13 +106,16 @@ intptr_t GpuSIGSYS_Handler(const struct arch_seccomp_data& args, ...@@ -106,13 +106,16 @@ intptr_t GpuSIGSYS_Handler(const struct arch_seccomp_data& args,
class GpuBrokerProcessPolicy : public GpuProcessPolicy { class GpuBrokerProcessPolicy : public GpuProcessPolicy {
public: public:
GpuBrokerProcessPolicy() {} static sandbox::SandboxBPFPolicy* Create() {
return new GpuBrokerProcessPolicy();
}
virtual ~GpuBrokerProcessPolicy() {} virtual ~GpuBrokerProcessPolicy() {}
virtual ErrorCode EvaluateSyscall(SandboxBPF* sandbox_compiler, virtual ErrorCode EvaluateSyscall(SandboxBPF* sandbox_compiler,
int system_call_number) const OVERRIDE; int system_call_number) const OVERRIDE;
private: private:
GpuBrokerProcessPolicy() {}
DISALLOW_COPY_AND_ASSIGN(GpuBrokerProcessPolicy); DISALLOW_COPY_AND_ASSIGN(GpuBrokerProcessPolicy);
}; };
...@@ -146,9 +149,11 @@ void UpdateProcessTypeToGpuBroker() { ...@@ -146,9 +149,11 @@ void UpdateProcessTypeToGpuBroker() {
} }
bool UpdateProcessTypeAndEnableSandbox( bool UpdateProcessTypeAndEnableSandbox(
const base::Callback<bool(void)>& broker_sandboxer_callback) { sandbox::SandboxBPFPolicy* (*broker_sandboxer_allocator)(void)) {
DCHECK(broker_sandboxer_allocator);
UpdateProcessTypeToGpuBroker(); UpdateProcessTypeToGpuBroker();
return broker_sandboxer_callback.Run(); return SandboxSeccompBPF::StartSandboxWithExternalPolicy(
make_scoped_ptr(broker_sandboxer_allocator()));
} }
} // namespace } // namespace
...@@ -198,9 +203,7 @@ bool GpuProcessPolicy::PreSandboxHook() { ...@@ -198,9 +203,7 @@ bool GpuProcessPolicy::PreSandboxHook() {
DCHECK(!broker_process()); DCHECK(!broker_process());
// Create a new broker process. // Create a new broker process.
InitGpuBrokerProcess( InitGpuBrokerProcess(
base::Bind(&SandboxSeccompBPF::StartSandboxWithExternalPolicy, GpuBrokerProcessPolicy::Create,
base::Passed(scoped_ptr<sandbox::SandboxBPFPolicy>(
new GpuBrokerProcessPolicy))),
std::vector<std::string>(), // No extra files in whitelist. std::vector<std::string>(), // No extra files in whitelist.
std::vector<std::string>()); std::vector<std::string>());
...@@ -226,7 +229,7 @@ bool GpuProcessPolicy::PreSandboxHook() { ...@@ -226,7 +229,7 @@ bool GpuProcessPolicy::PreSandboxHook() {
} }
void GpuProcessPolicy::InitGpuBrokerProcess( void GpuProcessPolicy::InitGpuBrokerProcess(
const base::Callback<bool(void)>& broker_sandboxer_callback, sandbox::SandboxBPFPolicy* (*broker_sandboxer_allocator)(void),
const std::vector<std::string>& read_whitelist_extra, const std::vector<std::string>& read_whitelist_extra,
const std::vector<std::string>& write_whitelist_extra) { const std::vector<std::string>& write_whitelist_extra) {
static const char kDriRcPath[] = "/etc/drirc"; static const char kDriRcPath[] = "/etc/drirc";
...@@ -256,7 +259,7 @@ void GpuProcessPolicy::InitGpuBrokerProcess( ...@@ -256,7 +259,7 @@ void GpuProcessPolicy::InitGpuBrokerProcess(
// The initialization callback will perform generic initialization and then // The initialization callback will perform generic initialization and then
// call broker_sandboxer_callback. // call broker_sandboxer_callback.
CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox, CHECK(broker_process_->Init(base::Bind(&UpdateProcessTypeAndEnableSandbox,
broker_sandboxer_callback))); broker_sandboxer_allocator)));
} }
} // namespace content } // namespace content
...@@ -29,13 +29,13 @@ class GpuProcessPolicy : public SandboxBPFBasePolicy { ...@@ -29,13 +29,13 @@ class GpuProcessPolicy : public SandboxBPFBasePolicy {
protected: protected:
// Start a broker process to handle open() inside the sandbox. // Start a broker process to handle open() inside the sandbox.
// |broker_sandboxer_callback| is a callback that will enable a suitable // |broker_sandboxer_allocator| is a function pointer which can allocate a
// sandbox for the broker process itself. // suitable sandbox policy for the broker process itself.
// |read_whitelist_extra| and |write_whitelist_extra| are lists of file // |read_whitelist_extra| and |write_whitelist_extra| are lists of file
// names that should be whitelisted by the broker process, in addition to // names that should be whitelisted by the broker process, in addition to
// the basic ones. // the basic ones.
void InitGpuBrokerProcess( void InitGpuBrokerProcess(
const base::Callback<bool(void)>& broker_sandboxer_callback, sandbox::SandboxBPFPolicy* (*broker_sandboxer_allocator)(void),
const std::vector<std::string>& read_whitelist_extra, const std::vector<std::string>& read_whitelist_extra,
const std::vector<std::string>& write_whitelist_extra); const std::vector<std::string>& write_whitelist_extra);
......
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