Skip to content

Commit

Permalink
Create new kPdfConversion sandbox type for Windows.
Browse files Browse the repository at this point in the history
In order to support updates to InitializePDF() to better scope the GDI
patching to only processes which need it, this change creates a new
sandbox type for PDF conversion which can be easily detected at runtime.

Bug: 1028670
Change-Id: I5cd7cb252d638eb376127d2926e75bdd590ccb16
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2087855
Reviewed-by: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: Will Harris <wfh@chromium.org>
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Cliff Smolinsky <cliffsmo@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#748387}
  • Loading branch information
Cliff Smolinsky authored and Commit Bot committed Mar 9, 2020
1 parent b1e1da9 commit 0aa7ca7
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions chrome/browser/chrome_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3607,6 +3607,7 @@ base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType(
case service_manager::SandboxType::kAudio:
case service_manager::SandboxType::kSoda:
case service_manager::SandboxType::kProxyResolver:
case service_manager::SandboxType::kPdfConversion:
// Should never reach here.
CHECK(0);
return base::string16();
Expand Down
5 changes: 4 additions & 1 deletion chrome/browser/printing/printing_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "chrome/browser/printing/printing_service.h"

#include "base/no_destructor.h"
#include "build/build_config.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/service_process_host.h"

Expand All @@ -16,7 +17,9 @@ const mojo::Remote<printing::mojom::PrintingService>& GetPrintingService() {
remote->BindNewPipeAndPassReceiver(),
content::ServiceProcessHost::Options()
.WithDisplayName(IDS_UTILITY_PROCESS_PRINTING_SERVICE_NAME)
.WithSandboxType(service_manager::SandboxType::kUtility)
#if defined(OS_WIN)
.WithSandboxType(service_manager::SandboxType::kPdfConversion)
#endif
.Pass());

// Ensure that if the interface is ever disconnected (e.g. the service
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/ui/webui/sandbox/sandbox_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ std::string GetSandboxTypeInEnglish(content::SandboxType sandbox_type) {
return "SODA";
case content::SandboxType::kProxyResolver:
return "Proxy Resolver";
case content::SandboxType::kPdfConversion:
return "PDF Conversion";
}
}

Expand Down
1 change: 1 addition & 0 deletions content/browser/utility_process_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class UtilitySandboxedProcessLauncherDelegate
service_manager::SandboxType::kNoSandboxAndElevatedPrivileges ||
sandbox_type_ == service_manager::SandboxType::kXrCompositing ||
sandbox_type_ == service_manager::SandboxType::kProxyResolver ||
sandbox_type_ == service_manager::SandboxType::kPdfConversion ||
#endif
sandbox_type_ == service_manager::SandboxType::kUtility ||
sandbox_type_ == service_manager::SandboxType::kNetwork ||
Expand Down
6 changes: 6 additions & 0 deletions services/service_manager/sandbox/sandbox_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ bool IsUnsandboxedSandboxType(SandboxType sandbox_type) {
return !base::FeatureList::IsEnabled(
service_manager::features::kXRSandbox);
case SandboxType::kProxyResolver:
case SandboxType::kPdfConversion:
return false;
#endif
case SandboxType::kAudio:
Expand Down Expand Up @@ -93,6 +94,7 @@ void SetCommandLineFlagsForSandboxType(base::CommandLine* command_line,
#if defined(OS_WIN)
case SandboxType::kXrCompositing:
case SandboxType::kProxyResolver:
case SandboxType::kPdfConversion:
#endif // defined(OS_WIN)
#if defined(OS_CHROMEOS)
case SandboxType::kIme:
Expand Down Expand Up @@ -180,6 +182,8 @@ std::string StringFromUtilitySandboxType(SandboxType sandbox_type) {
return switches::kXrCompositingSandbox;
case SandboxType::kProxyResolver:
return switches::kProxyResolverSandbox;
case SandboxType::kPdfConversion:
return switches::kPdfConversionSandbox;
#endif // defined(OS_WIN)
#if defined(OS_CHROMEOS)
case SandboxType::kIme:
Expand Down Expand Up @@ -226,6 +230,8 @@ SandboxType UtilitySandboxTypeFromString(const std::string& sandbox_string) {
return SandboxType::kXrCompositing;
if (sandbox_string == switches::kProxyResolverSandbox)
return SandboxType::kProxyResolver;
if (sandbox_string == switches::kPdfConversionSandbox)
return SandboxType::kPdfConversion;
#endif
if (sandbox_string == switches::kAudioSandbox)
return SandboxType::kAudio;
Expand Down
3 changes: 3 additions & 0 deletions services/service_manager/sandbox/sandbox_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ enum class SandboxType {

// The proxy resolver process.
kProxyResolver,

// The PDF conversion service process used in printing.
kPdfConversion,
#endif

#if defined(OS_FUCHSIA)
Expand Down
1 change: 1 addition & 0 deletions services/service_manager/sandbox/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const char kAudioSandbox[] = "audio";
const char kSodaSandbox[] = "soda";

#if defined(OS_WIN)
const char kPdfConversionSandbox[] = "pdf_conversion";
const char kProxyResolverSandbox[] = "proxy_resolver";
const char kXrCompositingSandbox[] = "xr_compositing";
#endif // OS_WIN
Expand Down
1 change: 1 addition & 0 deletions services/service_manager/sandbox/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ SERVICE_MANAGER_SANDBOX_EXPORT extern const char kAudioSandbox[];
SERVICE_MANAGER_SANDBOX_EXPORT extern const char kSodaSandbox[];

#if defined(OS_WIN)
SERVICE_MANAGER_SANDBOX_EXPORT extern const char kPdfConversionSandbox[];
SERVICE_MANAGER_SANDBOX_EXPORT extern const char kProxyResolverSandbox[];
SERVICE_MANAGER_SANDBOX_EXPORT extern const char kXrCompositingSandbox[];
#endif // OS_WIN
Expand Down
28 changes: 28 additions & 0 deletions services/service_manager/tests/sandbox/sandbox_type_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,34 @@ TEST(SandboxTypeTest, Utility) {
EXPECT_EQ(SandboxType::kPrintCompositor,
SandboxTypeFromCommandLine(command_line7));

base::CommandLine command_line8(command_line);
SetCommandLineFlagsForSandboxType(&command_line8, SandboxType::kAudio);
EXPECT_EQ(SandboxType::kAudio, SandboxTypeFromCommandLine(command_line8));

base::CommandLine command_line9(command_line);
SetCommandLineFlagsForSandboxType(&command_line9, SandboxType::kSoda);
EXPECT_EQ(SandboxType::kSoda, SandboxTypeFromCommandLine(command_line9));

#if defined(OS_WIN)
base::CommandLine command_line10(command_line);
SetCommandLineFlagsForSandboxType(&command_line10,
SandboxType::kXrCompositing);
EXPECT_EQ(SandboxType::kXrCompositing,
SandboxTypeFromCommandLine(command_line10));

base::CommandLine command_line11(command_line);
SetCommandLineFlagsForSandboxType(&command_line11,
SandboxType::kProxyResolver);
EXPECT_EQ(SandboxType::kProxyResolver,
SandboxTypeFromCommandLine(command_line11));

base::CommandLine command_line12(command_line);
SetCommandLineFlagsForSandboxType(&command_line12,
SandboxType::kPdfConversion);
EXPECT_EQ(SandboxType::kPdfConversion,
SandboxTypeFromCommandLine(command_line12));
#endif

command_line.AppendSwitch(switches::kNoSandbox);
EXPECT_EQ(SandboxType::kNoSandbox, SandboxTypeFromCommandLine(command_line));
}
Expand Down

0 comments on commit 0aa7ca7

Please sign in to comment.