OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "content/renderer/renderer_main_platform_delegate.h" | 5 #include "content/renderer/renderer_main_platform_delegate.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/android/build_info.h" |
| 8 #include "base/feature_list.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "content/public/common/content_switches.h" | |
10 | 10 |
11 #ifdef USE_SECCOMP_BPF | 11 #ifdef USE_SECCOMP_BPF |
12 #include "content/common/sandbox_linux/android/sandbox_bpf_base_policy_android.h
" | 12 #include "content/common/sandbox_linux/android/sandbox_bpf_base_policy_android.h
" |
| 13 #include "content/public/common/content_features.h" |
13 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 14 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
14 #endif | 15 #endif |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 | 18 |
| 19 namespace { |
| 20 |
| 21 #ifdef USE_SECCOMP_BPF |
| 22 // Determines if the running device should support Seccomp, based on the Android |
| 23 // SDK version. |
| 24 bool IsSeccompBPFSupportedBySDK() { |
| 25 const auto info = base::android::BuildInfo::GetInstance(); |
| 26 if (info->sdk_int() < 22) { |
| 27 // Seccomp was never available pre-Lollipop. |
| 28 return false; |
| 29 } else if (info->sdk_int() == 22) { |
| 30 // On Lollipop-MR1, only select Nexus devices have Seccomp available. |
| 31 const char* const kDevices[] = { |
| 32 "deb", "flo", "hammerhead", "mako", |
| 33 "manta", "shamu", "sprout", "volantis", |
| 34 }; |
| 35 |
| 36 for (const auto& device : kDevices) { |
| 37 if (strcmp(device, info->device()) == 0) { |
| 38 return true; |
| 39 } |
| 40 } |
| 41 } else { |
| 42 // On Marshmallow and higher, Seccomp is required by CTS. |
| 43 return true; |
| 44 } |
| 45 return false; |
| 46 } |
| 47 #endif // USE_SECCOMP_BPF |
| 48 |
| 49 } // namespace |
| 50 |
18 RendererMainPlatformDelegate::RendererMainPlatformDelegate( | 51 RendererMainPlatformDelegate::RendererMainPlatformDelegate( |
19 const MainFunctionParams& parameters) | 52 const MainFunctionParams& parameters) |
20 : parameters_(parameters) { | 53 : parameters_(parameters) { |
21 } | 54 } |
22 | 55 |
23 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { | 56 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { |
24 } | 57 } |
25 | 58 |
26 void RendererMainPlatformDelegate::PlatformInitialize() { | 59 void RendererMainPlatformDelegate::PlatformInitialize() { |
27 } | 60 } |
28 | 61 |
29 void RendererMainPlatformDelegate::PlatformUninitialize() { | 62 void RendererMainPlatformDelegate::PlatformUninitialize() { |
30 } | 63 } |
31 | 64 |
32 bool RendererMainPlatformDelegate::EnableSandbox() { | 65 bool RendererMainPlatformDelegate::EnableSandbox() { |
33 #ifdef USE_SECCOMP_BPF | 66 #ifdef USE_SECCOMP_BPF |
34 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 67 // Determine if Seccomp is available via the Android SDK version. |
35 switches::kEnableSeccompFilterSandbox)) { | 68 if (!IsSeccompBPFSupportedBySDK()) |
36 return true; | 69 return true; |
37 } | 70 |
| 71 // Do run-time detection to ensure that support is present. |
38 if (!sandbox::SandboxBPF::SupportsSeccompSandbox( | 72 if (!sandbox::SandboxBPF::SupportsSeccompSandbox( |
39 sandbox::SandboxBPF::SeccompLevel::MULTI_THREADED)) { | 73 sandbox::SandboxBPF::SeccompLevel::MULTI_THREADED)) { |
40 LOG(WARNING) << "Seccomp-BPF sandbox enabled without kernel support. " | 74 LOG(WARNING) << "Seccomp support should be present, but detection " |
41 << "Ignoring flag and proceeding without seccomp sandbox."; | 75 << "failed. Continuing without Seccomp-BPF."; |
42 return true; | 76 return true; |
43 } | 77 } |
44 | 78 |
45 sandbox::SandboxBPF sandbox(new SandboxBPFBasePolicyAndroid()); | 79 // Seccomp has been detected, check if the field trial experiment should run. |
46 CHECK( | 80 if (base::FeatureList::IsEnabled(kSeccompSandboxAndroidFeature)) { |
47 sandbox.StartSandbox(sandbox::SandboxBPF::SeccompLevel::MULTI_THREADED)); | 81 sandbox::SandboxBPF sandbox(new SandboxBPFBasePolicyAndroid()); |
| 82 CHECK(sandbox.StartSandbox( |
| 83 sandbox::SandboxBPF::SeccompLevel::MULTI_THREADED)); |
| 84 } |
48 #endif | 85 #endif |
49 return true; | 86 return true; |
50 } | 87 } |
51 | 88 |
52 } // namespace content | 89 } // namespace content |
OLD | NEW |