From be1fec24fc5a558a6dd7df688a0caacfa3d664a0 Mon Sep 17 00:00:00 2001 From: Aleksey Khoroshilov Date: Thu, 13 Jul 2023 15:24:16 +0700 Subject: [PATCH] Export ModuleFileNamePatch feature from sandbox/policy. --- browser/DEPS | 2 +- browser/about_flags.cc | 23 ++++++++++--------- .../win/module_file_name_patch_browsertest.cc | 9 ++++---- .../content/browser/gpu/gpu_process_host.cc | 10 ++++---- chromium_src/sandbox/policy/features.cc | 14 +++++++++++ chromium_src/sandbox/policy/features.h | 19 +++++++++++++++ .../win/src/module_file_name_interception.cc | 4 ---- .../win/src/module_file_name_interception.h | 4 ---- 8 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 chromium_src/sandbox/policy/features.cc create mode 100644 chromium_src/sandbox/policy/features.h diff --git a/browser/DEPS b/browser/DEPS index 4ba8e9314a7..f8f8520d1da 100644 --- a/browser/DEPS +++ b/browser/DEPS @@ -38,7 +38,7 @@ include_rules = [ "+mojo/public", "+net", "+sandbox/mac", - "+sandbox/win/src", + "+sandbox/policy", "+services/audio/public", "+services/cert_verifier", "+services/data_decoder/public", diff --git a/browser/about_flags.cc b/browser/about_flags.cc index cbdbb1af599..0eaf3092ac4 100644 --- a/browser/about_flags.cc +++ b/browser/about_flags.cc @@ -76,7 +76,7 @@ #endif #if BUILDFLAG(IS_WIN) -#include "brave/sandbox/win/src/module_file_name_interception.h" +#include "sandbox/policy/features.h" #endif #define EXPAND_FEATURE_ENTRIES(...) __VA_ARGS__, @@ -151,16 +151,17 @@ FEATURE_VALUE_TYPE(request_otr::features::kBraveRequestOTRTab), \ })) -#define BRAVE_MODULE_FILENAME_PATCH \ - IF_BUILDFLAG(IS_WIN, \ - EXPAND_FEATURE_ENTRIES({ \ - "brave-module-filename-patch", \ - "Enable Module Filename patch", \ - "Enables patching of executable's name from brave.exe to " \ - "chrome.exe in sandboxed processes.", \ - kOsWin, \ - FEATURE_VALUE_TYPE(sandbox::kModuleFileNamePatch), \ - })) +#define BRAVE_MODULE_FILENAME_PATCH \ + IF_BUILDFLAG( \ + IS_WIN, \ + EXPAND_FEATURE_ENTRIES({ \ + "brave-module-filename-patch", \ + "Enable Module Filename patch", \ + "Enables patching of executable's name from brave.exe to " \ + "chrome.exe in sandboxed processes.", \ + kOsWin, \ + FEATURE_VALUE_TYPE(sandbox::policy::features::kModuleFileNamePatch), \ + })) #define BRAVE_REWARDS_GEMINI_FEATURE_ENTRIES \ IF_BUILDFLAG( \ diff --git a/browser/sandbox/win/module_file_name_patch_browsertest.cc b/browser/sandbox/win/module_file_name_patch_browsertest.cc index 4bbbe427008..140afd58779 100644 --- a/browser/sandbox/win/module_file_name_patch_browsertest.cc +++ b/browser/sandbox/win/module_file_name_patch_browsertest.cc @@ -6,16 +6,17 @@ #include #include "base/test/scoped_feature_list.h" -#include "brave/sandbox/win/src/module_file_name_interception.h" #include "chrome/test/base/in_process_browser_test.h" -#include "chrome/test/base/ui_test_utils.h" #include "content/public/test/browser_test.h" +#include "sandbox/policy/features.h" // This header is private to //content/browser and can be used only from // content_browser_tests, but we don't have such target, so we workaround it // with `nogncheck`. #include "content/browser/gpu/gpu_process_host.h" // nogncheck +using sandbox::policy::features::kModuleFileNamePatch; + namespace { void NonBlockingDelay(const base::TimeDelta& delay) { @@ -41,9 +42,9 @@ class ModuleFileNameBrowserTest : public InProcessBrowserTest, public: ModuleFileNameBrowserTest() { if (GetParam()) { - feature_list_.InitAndEnableFeature(sandbox::kModuleFileNamePatch); + feature_list_.InitAndEnableFeature(kModuleFileNamePatch); } else { - feature_list_.InitAndDisableFeature(sandbox::kModuleFileNamePatch); + feature_list_.InitAndDisableFeature(kModuleFileNamePatch); } } diff --git a/chromium_src/content/browser/gpu/gpu_process_host.cc b/chromium_src/content/browser/gpu/gpu_process_host.cc index 644915f22b5..6145610b766 100644 --- a/chromium_src/content/browser/gpu/gpu_process_host.cc +++ b/chromium_src/content/browser/gpu/gpu_process_host.cc @@ -7,13 +7,13 @@ #if BUILDFLAG(IS_WIN) -#include "brave/sandbox/win/src/module_file_name_interception.h" +#include "sandbox/policy/features.h" #include "sandbox/win/src/sandbox_policy.h" -#define AddDllToUnload(x) \ - AddDllToUnload(x); \ - config->SetShouldPatchModuleFileName( \ - base::FeatureList::IsEnabled(sandbox::kModuleFileNamePatch)) +#define AddDllToUnload(x) \ + AddDllToUnload(x); \ + config->SetShouldPatchModuleFileName(base::FeatureList::IsEnabled( \ + sandbox::policy::features::kModuleFileNamePatch)) #endif // BUILDFLAG(IS_WIN) diff --git a/chromium_src/sandbox/policy/features.cc b/chromium_src/sandbox/policy/features.cc new file mode 100644 index 00000000000..949b0b4319b --- /dev/null +++ b/chromium_src/sandbox/policy/features.cc @@ -0,0 +1,14 @@ +/* Copyright (c) 2023 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. */ + +#include "src/sandbox/policy/features.cc" + +namespace sandbox::policy::features { + +BASE_FEATURE(kModuleFileNamePatch, + "ModuleFileNamePatch", + base::FEATURE_DISABLED_BY_DEFAULT); + +} // namespace sandbox::policy::features diff --git a/chromium_src/sandbox/policy/features.h b/chromium_src/sandbox/policy/features.h new file mode 100644 index 00000000000..cded39919d7 --- /dev/null +++ b/chromium_src/sandbox/policy/features.h @@ -0,0 +1,19 @@ +/* Copyright (c) 2023 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_CHROMIUM_SRC_SANDBOX_POLICY_FEATURES_H_ +#define BRAVE_CHROMIUM_SRC_SANDBOX_POLICY_FEATURES_H_ + +#include "src/sandbox/policy/features.h" // IWYU pragma: export + +namespace sandbox::policy::features { + +// Enables patching of executable's name from brave.exe to chrome.exe in +// sandboxed processes. +SANDBOX_POLICY_EXPORT BASE_DECLARE_FEATURE(kModuleFileNamePatch); + +} // namespace sandbox::policy::features + +#endif // BRAVE_CHROMIUM_SRC_SANDBOX_POLICY_FEATURES_H_ diff --git a/sandbox/win/src/module_file_name_interception.cc b/sandbox/win/src/module_file_name_interception.cc index 2023366cc8f..d752b364241 100644 --- a/sandbox/win/src/module_file_name_interception.cc +++ b/sandbox/win/src/module_file_name_interception.cc @@ -99,10 +99,6 @@ DWORD PatchFilename(CharT* filename, DWORD length, DWORD size) { namespace sandbox { -BASE_FEATURE(kModuleFileNamePatch, - "ModuleFileNamePatch", - base::FEATURE_DISABLED_BY_DEFAULT); - SANDBOX_INTERCEPT DWORD WINAPI TargetGetModuleFileNameA(GetModuleFileNameAFunction orig, HMODULE hModule, diff --git a/sandbox/win/src/module_file_name_interception.h b/sandbox/win/src/module_file_name_interception.h index 1bd971f5706..deef9b1c72c 100644 --- a/sandbox/win/src/module_file_name_interception.h +++ b/sandbox/win/src/module_file_name_interception.h @@ -19,10 +19,6 @@ namespace sandbox { -// Enables patching of executable's name from brave.exe to chrome.exe in -// sandboxed processes. -BASE_DECLARE_FEATURE(kModuleFileNamePatch); - using GetModuleFileNameAFunction = decltype(&::GetModuleFileNameA); using GetModuleFileNameWFunction = decltype(&::GetModuleFileNameW); using GetModuleFileNameExAFunction = decltype(&::GetModuleFileNameExA);