Export ModuleFileNamePatch feature from sandbox/policy.

This commit is contained in:
Aleksey Khoroshilov
2023-07-13 19:15:16 +07:00
parent 9d2463ff1e
commit be1fec24fc
8 changed files with 56 additions and 29 deletions
+1 -1
View File
@@ -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",
+12 -11
View File
@@ -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( \
@@ -6,16 +6,17 @@
#include <string>
#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);
}
}
@@ -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)
+14
View File
@@ -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
+19
View File
@@ -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_
@@ -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,
@@ -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);