support_mixed_sandbox_with_zygote.patch 4.4 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 23c2f323ce9172d6e8a42d0cc031da5a0540ce35..73cad457ad37cfdb5459c11e7828a543dc0cf31d 100644
  22. --- a/content/browser/renderer_host/render_process_host_impl.cc
  23. +++ b/content/browser/renderer_host/render_process_host_impl.cc
  24. @@ -1723,9 +1723,15 @@ bool RenderProcessHostImpl::Init() {
  25. std::unique_ptr<SandboxedProcessLauncherDelegate> sandbox_delegate =
  26. std::make_unique<RendererSandboxedProcessLauncherDelegateWin>(
  27. *cmd_line, IsPdf(), IsJitDisabled());
  28. +#else
  29. +#if BUILDFLAG(USE_ZYGOTE)
  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. auto file_data = std::make_unique<ChildProcessLauncherFileData>();
  39. diff --git a/content/browser/renderer_host/renderer_sandboxed_process_launcher_delegate.cc b/content/browser/renderer_host/renderer_sandboxed_process_launcher_delegate.cc
  40. index e5a087e3e26253901a84d509d8a4f1268a2569fe..7dab0443f8897553830f1f4cc98457839b354264 100644
  41. --- a/content/browser/renderer_host/renderer_sandboxed_process_launcher_delegate.cc
  42. +++ b/content/browser/renderer_host/renderer_sandboxed_process_launcher_delegate.cc
  43. @@ -33,6 +33,9 @@ namespace content {
  44. #if BUILDFLAG(USE_ZYGOTE)
  45. ZygoteCommunication* RendererSandboxedProcessLauncherDelegate::GetZygote() {
  46. + if (!use_zygote_) {
  47. + return nullptr;
  48. + }
  49. const base::CommandLine& browser_command_line =
  50. *base::CommandLine::ForCurrentProcess();
  51. base::CommandLine::StringType renderer_prefix =
  52. @@ -67,6 +70,9 @@ RendererSandboxedProcessLauncherDelegateWin::
  53. is_pdf_renderer_(is_pdf_renderer) {
  54. // PDF renderers must be jitless.
  55. CHECK(!is_pdf_renderer || is_jit_disabled);
  56. +#if BUILDFLAG(USE_ZYGOTE)
  57. + use_zygote_ = !cmd_line->HasSwitch(switches::kNoZygote);
  58. +#endif
  59. if (is_jit_disabled) {
  60. dynamic_code_can_be_disabled_ = true;
  61. return;
  62. diff --git a/content/browser/renderer_host/renderer_sandboxed_process_launcher_delegate.h b/content/browser/renderer_host/renderer_sandboxed_process_launcher_delegate.h
  63. index 00038da2c15696b361aea1469ccf73307e44963e..7ccfbf11ecfd56fd165915baa85919eaf2e923b9 100644
  64. --- a/content/browser/renderer_host/renderer_sandboxed_process_launcher_delegate.h
  65. +++ b/content/browser/renderer_host/renderer_sandboxed_process_launcher_delegate.h
  66. @@ -18,6 +18,11 @@ class CONTENT_EXPORT RendererSandboxedProcessLauncherDelegate
  67. public:
  68. RendererSandboxedProcessLauncherDelegate() = default;
  69. +#if BUILDFLAG(USE_ZYGOTE)
  70. + RendererSandboxedProcessLauncherDelegate(bool use_zygote):
  71. + use_zygote_(use_zygote) {}
  72. +#endif
  73. +
  74. ~RendererSandboxedProcessLauncherDelegate() override = default;
  75. #if BUILDFLAG(USE_ZYGOTE)
  76. @@ -30,6 +35,11 @@ class CONTENT_EXPORT RendererSandboxedProcessLauncherDelegate
  77. // sandbox::policy::SandboxDelegate:
  78. sandbox::mojom::Sandbox GetSandboxType() override;
  79. +
  80. + private:
  81. +#if BUILDFLAG(USE_ZYGOTE)
  82. + bool use_zygote_ = true;
  83. +#endif
  84. };
  85. #if BUILDFLAG(IS_WIN)