summaryrefslogtreecommitdiff
path: root/chromium/content/browser/utility_sandbox_delegate.cc
blob: b9ed59e5e3279882d8482de93bf8da30893ddc03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/utility_sandbox_delegate.h"

#include "base/check.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "content/public/common/sandboxed_process_launcher_delegate.h"
#include "content/public/common/zygote/zygote_buildflags.h"
#include "printing/buildflags/buildflags.h"
#include "sandbox/policy/sandbox_type.h"

#if BUILDFLAG(USE_ZYGOTE_HANDLE)
#include "content/common/zygote/zygote_handle_impl_linux.h"
#endif

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chromeos/assistant/buildflags.h"
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

namespace content {

UtilitySandboxedProcessLauncherDelegate::
    UtilitySandboxedProcessLauncherDelegate(
        sandbox::policy::SandboxType sandbox_type,
        const base::EnvironmentMap& env,
        const base::CommandLine& cmd_line)
    :
#if defined(OS_POSIX)
      env_(env),
#endif
      sandbox_type_(sandbox_type),
      cmd_line_(cmd_line) {
#if DCHECK_IS_ON()
  bool supported_sandbox_type =
      sandbox_type_ == sandbox::policy::SandboxType::kNoSandbox ||
#if defined(OS_WIN)
      sandbox_type_ ==
          sandbox::policy::SandboxType::kNoSandboxAndElevatedPrivileges ||
      sandbox_type_ == sandbox::policy::SandboxType::kXrCompositing ||
      sandbox_type_ == sandbox::policy::SandboxType::kProxyResolver ||
      sandbox_type_ == sandbox::policy::SandboxType::kPdfConversion ||
      sandbox_type_ == sandbox::policy::SandboxType::kIconReader ||
      sandbox_type_ == sandbox::policy::SandboxType::kMediaFoundationCdm ||
#endif
#if defined(OS_MAC)
      sandbox_type_ == sandbox::policy::SandboxType::kMirroring ||
#endif
      sandbox_type_ == sandbox::policy::SandboxType::kUtility ||
      sandbox_type_ == sandbox::policy::SandboxType::kNetwork ||
      sandbox_type_ == sandbox::policy::SandboxType::kCdm ||
#if BUILDFLAG(ENABLE_PRINTING)
      sandbox_type_ == sandbox::policy::SandboxType::kPrintBackend ||
#endif
      sandbox_type_ == sandbox::policy::SandboxType::kPrintCompositor ||
      sandbox_type_ == sandbox::policy::SandboxType::kPpapi ||
      sandbox_type_ == sandbox::policy::SandboxType::kVideoCapture ||
#if BUILDFLAG(IS_CHROMEOS_ASH)
      sandbox_type_ == sandbox::policy::SandboxType::kIme ||
      sandbox_type_ == sandbox::policy::SandboxType::kTts ||
#if BUILDFLAG(ENABLE_CROS_LIBASSISTANT)
      sandbox_type_ == sandbox::policy::SandboxType::kLibassistant ||
#endif  // BUILDFLAG(ENABLE_CROS_LIBASSISTANT)
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)
      sandbox_type_ == sandbox::policy::SandboxType::kAudio ||
#if !defined(OS_MAC)
      sandbox_type_ == sandbox::policy::SandboxType::kService ||
#endif
      sandbox_type_ == sandbox::policy::SandboxType::kSpeechRecognition;
  DCHECK(supported_sandbox_type);
#endif  // DCHECK_IS_ON()
}

UtilitySandboxedProcessLauncherDelegate::
    ~UtilitySandboxedProcessLauncherDelegate() {}

sandbox::policy::SandboxType
UtilitySandboxedProcessLauncherDelegate::GetSandboxType() {
  return sandbox_type_;
}

#if defined(OS_POSIX)
base::EnvironmentMap UtilitySandboxedProcessLauncherDelegate::GetEnvironment() {
  return env_;
}
#endif  // OS_POSIX

#if BUILDFLAG(USE_ZYGOTE_HANDLE)
ZygoteHandle UtilitySandboxedProcessLauncherDelegate::GetZygote() {
  // If the sandbox has been disabled for a given type, don't use a zygote.
  if (sandbox::policy::IsUnsandboxedSandboxType(sandbox_type_))
    return nullptr;

  // Utility processes which need specialized sandboxes fork from the
  // unsandboxed zygote and then apply their actual sandboxes in the forked
  // process upon startup.
  if (sandbox_type_ == sandbox::policy::SandboxType::kNetwork ||
#if BUILDFLAG(IS_CHROMEOS_ASH)
      sandbox_type_ == sandbox::policy::SandboxType::kIme ||
      sandbox_type_ == sandbox::policy::SandboxType::kTts ||
#if BUILDFLAG(ENABLE_CROS_LIBASSISTANT)
      sandbox_type_ == sandbox::policy::SandboxType::kLibassistant ||
#endif  // BUILDFLAG(ENABLE_CROS_LIBASSISTANT)
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)
      sandbox_type_ == sandbox::policy::SandboxType::kAudio ||
#if BUILDFLAG(ENABLE_PRINTING)
      sandbox_type_ == sandbox::policy::SandboxType::kPrintBackend ||
#endif
      sandbox_type_ == sandbox::policy::SandboxType::kSpeechRecognition) {
    return GetUnsandboxedZygote();
  }

  // All other types use the pre-sandboxed zygote.
  return GetGenericZygote();
}
#endif  // BUILDFLAG(USE_ZYGOTE_HANDLE)

}  // namespace content