support_mixed_sandbox_with_zygote.patch 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Jeremy Apthorp <[email protected]>
  3. Date: Wed, 28 Nov 2018 13:20:27 -0800
  4. Subject: support_mixed_sandbox_with_zygote.patch
  5. On Linux, Chromium launches all new renderer processes via a "zygote"
  6. process which has the sandbox pre-initialized (see
  7. //docs/linux_zygote.md). In order to support mixed-sandbox mode, in
  8. which some renderers are launched with the sandbox engaged and others
  9. without it, we need the option to launch non-sandboxed renderers without
  10. going through the zygote.
  11. Chromium already supports a `--no-zygote` flag, but it turns off the
  12. zygote completely, and thus also disables sandboxing. This patch allows
  13. the `--no-zygote` flag to affect renderer processes on a case-by-case
  14. basis, checking immediately prior to launch whether to go through the
  15. zygote or not based on the command-line of the to-be-launched renderer.
  16. This patch could conceivably be upstreamed, as it does not affect
  17. production Chromium (which does not use the `--no-zygote` flag).
  18. However, the patch would need to be reviewed by the security team, as it
  19. does touch a security-sensitive class.
  20. diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
  21. index 064b5642425290f1d9ab82f75b22fd43973ebf5b..30a0c9216a206042a9769bdeda015eaf00e3cc49 100644
  22. --- a/content/browser/renderer_host/render_process_host_impl.cc
  23. +++ b/content/browser/renderer_host/render_process_host_impl.cc
  24. @@ -1835,9 +1835,15 @@ bool RenderProcessHostImpl::Init() {
  25. std::unique_ptr<SandboxedProcessLauncherDelegate> sandbox_delegate =
  26. std::make_unique<RendererSandboxedProcessLauncherDelegateWin>(
  27. cmd_line.get(), IsJitDisabled());
  28. +#else
  29. +#if BUILDFLAG(USE_ZYGOTE_HANDLE)
  30. + bool use_zygote = !cmd_line->HasSwitch(switches::kNoZygote);
  31. + std::unique_ptr<SandboxedProcessLauncherDelegate> sandbox_delegate =
  32. + std::make_unique<RendererSandboxedProcessLauncherDelegate>(use_zygote);
  33. #else
  34. std::unique_ptr<SandboxedProcessLauncherDelegate> sandbox_delegate =
  35. std::make_unique<RendererSandboxedProcessLauncherDelegate>();
  36. +#endif
  37. #endif
  38. // Spawn the child process asynchronously to avoid blocking the UI thread.
  39. // As long as there's no renderer prefix, we can use the zygote process
  40. diff --git a/content/browser/renderer_host/renderer_sandboxed_process_launcher_delegate.cc b/content/browser/renderer_host/renderer_sandboxed_process_launcher_delegate.cc
  41. index e8d6ef94664bb37996871c0cc0db7c815783b786..0d56fa0aebee80883019a100900119972bf02edd 100644
  42. --- a/content/browser/renderer_host/renderer_sandboxed_process_launcher_delegate.cc
  43. +++ b/content/browser/renderer_host/renderer_sandboxed_process_launcher_delegate.cc
  44. @@ -25,6 +25,9 @@ namespace content {
  45. #if BUILDFLAG(USE_ZYGOTE_HANDLE)
  46. ZygoteHandle RendererSandboxedProcessLauncherDelegate::GetZygote() {
  47. + if (!use_zygote_) {
  48. + return nullptr;
  49. + }
  50. const base::CommandLine& browser_command_line =
  51. *base::CommandLine::ForCurrentProcess();
  52. base::CommandLine::StringType renderer_prefix =
  53. @@ -52,6 +55,9 @@ RendererSandboxedProcessLauncherDelegateWin::
  54. bool is_jit_disabled)
  55. : renderer_code_integrity_enabled_(
  56. GetContentClient()->browser()->IsRendererCodeIntegrityEnabled()) {
  57. +#if BUILDFLAG(USE_ZYGOTE_HANDLE)
  58. + use_zygote_ = !cmd_line->HasSwitch(switches::kNoZygote);
  59. +#endif
  60. if (is_jit_disabled) {
  61. dynamic_code_can_be_disabled_ = true;
  62. return;
  63. diff --git a/content/browser/renderer_host/renderer_sandboxed_process_launcher_delegate.h b/content/browser/renderer_host/renderer_sandboxed_process_launcher_delegate.h
  64. index 463df70c55df932427c761a67dbc89d7657f9703..d6d8094e31129eb7ca1f0bf36523d48204281795 100644
  65. --- a/content/browser/renderer_host/renderer_sandboxed_process_launcher_delegate.h
  66. +++ b/content/browser/renderer_host/renderer_sandboxed_process_launcher_delegate.h
  67. @@ -18,6 +18,11 @@ class CONTENT_EXPORT RendererSandboxedProcessLauncherDelegate
  68. public:
  69. RendererSandboxedProcessLauncherDelegate() = default;
  70. +#if BUILDFLAG(USE_ZYGOTE_HANDLE)
  71. + RendererSandboxedProcessLauncherDelegate(bool use_zygote):
  72. + use_zygote_(use_zygote) {}
  73. +#endif
  74. +
  75. ~RendererSandboxedProcessLauncherDelegate() override = default;
  76. #if BUILDFLAG(USE_ZYGOTE_HANDLE)
  77. @@ -29,6 +34,11 @@ class CONTENT_EXPORT RendererSandboxedProcessLauncherDelegate
  78. #endif // BUILDFLAG(IS_MAC)
  79. sandbox::mojom::Sandbox GetSandboxType() override;
  80. +
  81. + private:
  82. +#if BUILDFLAG(USE_ZYGOTE_HANDLE)
  83. + bool use_zygote_ = true;
  84. +#endif
  85. };
  86. #if BUILDFLAG(IS_WIN)