support_mixed_sandbox_with_zygote.patch 3.7 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 91f8afb5d2153ebd6f26f06caa214237a2fd37c1..2c066cd7de6fb60d770a8eb3cb7abad59e8dbf12 100644
  22. --- a/content/browser/renderer_host/render_process_host_impl.cc
  23. +++ b/content/browser/renderer_host/render_process_host_impl.cc
  24. @@ -389,10 +389,18 @@ class RendererSandboxedProcessLauncherDelegate
  25. public:
  26. RendererSandboxedProcessLauncherDelegate() = default;
  27. +#if BUILDFLAG(USE_ZYGOTE_HANDLE)
  28. + RendererSandboxedProcessLauncherDelegate(bool use_zygote):
  29. + use_zygote_(use_zygote) {}
  30. +#endif
  31. +
  32. ~RendererSandboxedProcessLauncherDelegate() override = default;
  33. #if BUILDFLAG(USE_ZYGOTE_HANDLE)
  34. ZygoteHandle GetZygote() override {
  35. + if (!use_zygote_) {
  36. + return nullptr;
  37. + }
  38. const base::CommandLine& browser_command_line =
  39. *base::CommandLine::ForCurrentProcess();
  40. base::CommandLine::StringType renderer_prefix =
  41. @@ -410,6 +418,11 @@ class RendererSandboxedProcessLauncherDelegate
  42. sandbox::policy::SandboxType GetSandboxType() override {
  43. return sandbox::policy::SandboxType::kRenderer;
  44. }
  45. +
  46. + private:
  47. +#if BUILDFLAG(USE_ZYGOTE_HANDLE)
  48. + bool use_zygote_ = true;
  49. +#endif
  50. };
  51. #if defined(OS_WIN)
  52. @@ -420,6 +433,9 @@ class RendererSandboxedProcessLauncherDelegateWin
  53. RendererSandboxedProcessLauncherDelegateWin(base::CommandLine* cmd_line)
  54. : renderer_code_integrity_enabled_(
  55. GetContentClient()->browser()->IsRendererCodeIntegrityEnabled()) {
  56. +#if BUILDFLAG(USE_ZYGOTE_HANDLE)
  57. + use_zygote_ = !cmd_line->HasSwitch(switches::kNoZygote);
  58. +#endif
  59. if (cmd_line->HasSwitch(switches::kJavaScriptFlags)) {
  60. std::string js_flags =
  61. cmd_line->GetSwitchValueASCII(switches::kJavaScriptFlags);
  62. @@ -1848,9 +1864,15 @@ bool RenderProcessHostImpl::Init() {
  63. std::unique_ptr<SandboxedProcessLauncherDelegate> sandbox_delegate =
  64. std::make_unique<RendererSandboxedProcessLauncherDelegateWin>(
  65. cmd_line.get());
  66. +#else
  67. +#if BUILDFLAG(USE_ZYGOTE_HANDLE)
  68. + bool use_zygote = !cmd_line->HasSwitch(switches::kNoZygote);
  69. + std::unique_ptr<SandboxedProcessLauncherDelegate> sandbox_delegate =
  70. + std::make_unique<RendererSandboxedProcessLauncherDelegate>(use_zygote);
  71. #else
  72. std::unique_ptr<SandboxedProcessLauncherDelegate> sandbox_delegate =
  73. std::make_unique<RendererSandboxedProcessLauncherDelegate>();
  74. +#endif
  75. #endif
  76. // Spawn the child process asynchronously to avoid blocking the UI thread.
  77. // As long as there's no renderer prefix, we can use the zygote process