support_mixed_sandbox_with_zygote.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 f40f089582ff616ea54b7f44309e78515b5967f5..0cd572d4793ebe72ce576000ffbc302aa703b58c 100644
  22. --- a/content/browser/renderer_host/render_process_host_impl.cc
  23. +++ b/content/browser/renderer_host/render_process_host_impl.cc
  24. @@ -413,6 +413,11 @@ class RendererSandboxedProcessLauncherDelegate
  25. {
  26. }
  27. +#if BUILDFLAG(USE_ZYGOTE_HANDLE)
  28. + RendererSandboxedProcessLauncherDelegate(bool use_zygote):
  29. + use_zygote_(use_zygote) {}
  30. +#endif
  31. +
  32. ~RendererSandboxedProcessLauncherDelegate() override {}
  33. #if defined(OS_WIN)
  34. @@ -434,6 +439,9 @@ class RendererSandboxedProcessLauncherDelegate
  35. #if BUILDFLAG(USE_ZYGOTE_HANDLE)
  36. ZygoteHandle GetZygote() override {
  37. + if (!use_zygote_) {
  38. + return nullptr;
  39. + }
  40. const base::CommandLine& browser_command_line =
  41. *base::CommandLine::ForCurrentProcess();
  42. base::CommandLine::StringType renderer_prefix =
  43. @@ -448,10 +456,13 @@ class RendererSandboxedProcessLauncherDelegate
  44. return sandbox::policy::SandboxType::kRenderer;
  45. }
  46. -#if defined(OS_WIN)
  47. private:
  48. +#if defined(OS_WIN)
  49. const bool renderer_code_integrity_enabled_;
  50. #endif
  51. +#if BUILDFLAG(USE_ZYGOTE_HANDLE)
  52. + bool use_zygote_ = true;
  53. +#endif
  54. };
  55. const char kSessionStorageHolderKey[] = "kSessionStorageHolderKey";
  56. @@ -1858,11 +1869,18 @@ bool RenderProcessHostImpl::Init() {
  57. cmd_line->PrependWrapper(renderer_prefix);
  58. AppendRendererCommandLine(cmd_line.get());
  59. +#if BUILDFLAG(USE_ZYGOTE_HANDLE)
  60. + bool use_zygote = !cmd_line->HasSwitch(switches::kNoZygote);
  61. + auto delegate = std::make_unique<RendererSandboxedProcessLauncherDelegate>(use_zygote);
  62. +#else
  63. + auto delegate = std::make_unique<RendererSandboxedProcessLauncherDelegate>();
  64. +#endif
  65. +
  66. // Spawn the child process asynchronously to avoid blocking the UI thread.
  67. // As long as there's no renderer prefix, we can use the zygote process
  68. // at this stage.
  69. child_process_launcher_ = std::make_unique<ChildProcessLauncher>(
  70. - std::make_unique<RendererSandboxedProcessLauncherDelegate>(),
  71. + std::move(delegate),
  72. std::move(cmd_line), GetID(), this, std::move(mojo_invitation_),
  73. base::BindRepeating(&RenderProcessHostImpl::OnMojoError, id_),
  74. GetV8SnapshotFilesToPreload());