support_mixed_sandbox_with_zygote.patch 4.3 KB

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