electron/patches/chromium/process_singleton.patch
electron-roller[bot] d02c9f8bc6
chore: bump chromium to 111.0.5544.3 (main) (#36820)
* chore: bump chromium in DEPS to 111.0.5522.0

* chore: bump chromium in DEPS to 111.0.5524.0

* chore: bump chromium in DEPS to 111.0.5526.0

* chore: bump chromium in DEPS to 111.0.5528.0

* chore: update patches/chromium/mas_avoid_usage_of_private_macos_apis.patch

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4132807

Fix simple code shear

* chore: update patches/chromium/unsandboxed_ppapi_processes_skip_zygote.patch

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4130675

Fix simple code shear

* chore: update patches/chromium/hack_plugin_response_interceptor_to_point_to_electron.patch

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4144281

Fix simple code shear; applied cleanly w/patch-fuzz

* chore: update patches/chromium/disable_unload_metrics.patch

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4126173

Fix simple code shear; applied cleanly w/patch-fuzz

* chore: update patches/chromium/feat_add_data_parameter_to_processsingleton.patch

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4144281

Fix simple code shear; applied cleanly w/patch-fuzz

* chore: update patches/chromium/preconnect_manager.patch

https://chromium-review.googlesource.com/c/chromium/src/+/4144281

Fix simple code shear; applied cleanly w/patch-fuzz

* chore: update patches/v8/force_cppheapcreateparams_to_be_noncopyable.patch

https://chromium-review.googlesource.com/c/v8/v8/+/3533019

Fix simple code shear; applied cleanly w/patch-fuzz

* chore: update patches

* chore: update patches/chromium/add_maximized_parameter_to_linuxui_getwindowframeprovider.patch

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4128765

Upstream added a new call to HeaderContext(), whose signature we have patched

* chore: bump chromium in DEPS to 111.0.5530.0

* chore: update patches

* Move ChildProcessHost* from content/common to content/browser

Xref: Move ChildProcessHost* from content/common to content/browser

* Remove RenderViewHostChanged

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4134103
[upstream removal of RenderViewHostChanged]

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4092763
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4093234
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133892
Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4134103
[examples of upstream code adjusting to the change]

Upstream handles this change in roughly two approaches:

1. Move the code over to RenderFrameHostChanged(old_host, new_host)
   but test for new_host->IsInPrimaryMainFrame() before acting

2. Migrate to the PrimaryPageChanged(page) API and use
   page.GetMainDocument() to get the RenderFrameHost.

I've chosen 1. because electron_api_web_contents needed that pointer
to old_host to call RemoveInputEventListener(), but I may be missing
some context & would appreciate review on this commit.

* Make electron/shell/browser/relauncher_win.cc use <winternl.h>

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4129135

Many internal Windows types are now available in winternl.h
so upstrem no longer defines the types themselves.

* Move ChildProcessHost* from content/common to content/browser

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4134795

* fixup! Make electron/shell/browser/relauncher_win.cc use <winternl.h>

winternl.h does not define the field we need, so clone the struct Chromium was using into unnamed namespace

* fixup! Move ChildProcessHost* from content/common to content/browser

chore: update #includes too

* chore: bump chromium in DEPS to 111.0.5532.0

* chore: sync patches/chromium/pepper_plugin_support.patch

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133323

manually reync patch; no code changes

* chore: sync patches/chromium/mas_no_private_api.patch

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4143865

the content/common/pseudonymization_salt.cc patch is no longer needed

* chore: sync patches/chromium/mas_disable_remote_accessibility.patch

patch-fuzz update; no manual changes

* chore: sync patches/chromium/build_do_not_depend_on_packed_resource_integrity.patch

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4111725

manually reync patch; no code changes

* chore: sync patches/chromium/create_browser_v8_snapshot_file_name_fuse.patch

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133323

manually reync patch; no code changes

* chore: sync patches/v8/fix_build_deprecated_attribute_for_older_msvc_versions.patch

Xref: https://chromium-review.googlesource.com/c/v8/v8/+/4127230

patch-fuzz update; no manual changes

* chore: rebuild patches

* fixup! Remove RenderViewHostChanged

Use PrimaryPageChanged()

* chore: remove unused method TabsUpdateFunction::OnExecuteCodeFinished()

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133991

This private, already-unused function showed up as a FTBFS because it
took a base::ListValue parameter and ListValue was removed upstream.

* task posting v3: remove includes of runner handles and IWYU task runners

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4133323

* chore: lint

* chore: more lint

* fixup! task posting v3: remove includes of runner handles and IWYU task runners

macOS, too

* fixup! task posting v3: remove includes of runner handles and IWYU task runners

* chore: bump chromium in DEPS to 111.0.5534.0

* chore: sync patches/chromium/allow_new_privileges_in_unsandboxed_child_processes.patch

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4141862

patch-fuzz update; no manual changes

* chore: sync patches/chromium/logging_win32_only_create_a_console_if_logging_to_stderr.patch

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4153110

Sync to minor upstream changes. Add const correctness.

* chore: sync electron/patches/chromium/feat_configure_launch_options_for_service_process.patch

https://chromium-review.googlesource.com/c/chromium/src/+/4141862

patch-fuzz update; no manual changes

* chore: patches/v8/fix_build_deprecated_attribute_for_older_msvc_versions.patch

sync https://chromium-review.googlesource.com/c/v8/v8/+/4147787

patch-fuzz update; no manual changes

* chore: update patches

* chore: bump chromium in DEPS to 111.0.5536.0

* chore: sync patches/chromium/allow_new_privileges_in_unsandboxed_child_processes.patch

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4141863

Sync with upstream code changes. Minor code golf for readability.

Note: upstream is laying groundwork for being able to work off of env vars
instead of switches. Doesn't affect us yet but worth being aware of.

> + // Environment variables could be supported in the future, but are not
> + // currently supported when launching with the zygote.

* chore: update patches/chromium/feat_expose_raw_response_headers_from_urlloader.patch

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4126836

patch-fuzz update; no manual changes

* chore: sync electron/patches/chromium/feat_configure_launch_options_for_service_process.patch

Xref: https://chromium-review.googlesource.com/c/chromium/src/+/4141863

manual sync

* chore: sync electron/patches/v8/fix_build_deprecated_attribute_for_older_msvc_versions.patch

https://chromium-review.googlesource.com/c/v8/v8/+/4147788

fuzz-patch

* chore: rebuild patches

* chore: bump chromium in DEPS to 111.0.5538.0

* chore: bump chromium in DEPS to 111.0.5540.0

* chore: update patches

* Remove sdk_forward_declarations

https://chromium-review.googlesource.com/c/chromium/src/+/4166680

* task posting v3: Remove task runner handles from codebase entirely

Refs https://chromium-review.googlesource.com/c/chromium/src/+/4150928

* Cleanup child_process_launcher_helper*

Refs https://chromium-review.googlesource.com/c/chromium/src/+/4141863

* fix: utilityprocess spec on macOS

* fix: build on windows

Refs https://chromium-review.googlesource.com/c/chromium/src/+/4141863

* chore: fix lint

* chore: bump chromium 111.0.5544.3

* chore: gen filenames.libcxx.gni

* Add check for Executable+Writable handles in renderer processes.

Refs https://chromium-review.googlesource.com/c/chromium/src/+/3774416

* fixup! Add check for Executable+Writable handles in renderer processes.

* 4143761: [110] Disable SwiftShader for WebGL on M1 Macs.

https://chromium-review.googlesource.com/c/chromium/src/+/4143761
(cherry picked from commit 2f74db3c2139424c416f92d9169aeaa8a2f9c1ec)

* chore: bump chromium to 111.0.5555.0

* 56085: Remove hmac.h include from ssl.h.

https://boringssl-review.googlesource.com/c/boringssl/+/56085

* 4167020: Remove forwarding headers

https://chromium-review.googlesource.com/c/chromium/src/+/4167020

* chore: bump chromium to 111.0.5559.0

* 4181044: Restrict WebCursor usage to RenderWidgetHostViewAura

https://chromium-review.googlesource.com/c/chromium/src/+/4181044

* 4189437: views: rename ink_drop_host_view to ink_drop_host

https://chromium-review.googlesource.com/c/chromium/src/+/4189437

* chore: bump chromium to 111.0.5560.0

* 4167016: win7dep: remove non aeroglass code

https://chromium-review.googlesource.com/c/chromium/src/+/4167016

* fixup after rebase: Remove forwarding header

s https://chromium-review.googlesource.com/c/chromium/src/+/4167020

* 4125755: Reland "Reject getDisplayMedia calls without user activation"

https://chromium-review.googlesource.com/c/chromium/src/+/4125755

* test: add workaround

* chore: update patches

* fix: alter coreModuleRegExp to prevent arm crash

* Revert "fix: alter coreModuleRegExp to prevent arm crash"

This reverts commit 7e50630c98137831a711c5abdbc8809e60cf1d73.

* 4218354: Disable the use of preserve_most on arm64 Windows

https://chromium-review.googlesource.com/c/v8/v8/+/4218354

* chore: review changes

---------

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2023-02-03 12:43:42 +01:00

256 lines
10 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Raymond Zhao <raymondzhao@microsoft.com>
Date: Wed, 18 Aug 2021 08:24:10 -0700
Subject: extend ProcessSingleton
This patch applies Electron ProcessSingleton changes onto the Chromium
files.
This patch adds a few changes to the Chromium code:
1. It adds a parameter `program_name` to the Windows constructor, making
the generated mutex name on the Windows-side program-dependent,
rather than shared between all Electron applications.
2. It adds an `IsAppSandboxed` check for macOS so that
sandboxed applications generate shorter temp paths.
3. It adds a `ChangeWindowMessageFilterEx` call to the Windows
implementation, along with a parameter `is_app_sandboxed` in the
constructor, to handle the case when the primary app is run with
admin permissions.
diff --git a/chrome/browser/process_singleton.h b/chrome/browser/process_singleton.h
index b05c0157ecca222452fb38e3b28c9d7cc6bcfbfd..02d9eabfef9521722340739bf86df3dfc30018d7 100644
--- a/chrome/browser/process_singleton.h
+++ b/chrome/browser/process_singleton.h
@@ -102,12 +102,19 @@ class ProcessSingleton {
base::RepeatingCallback<bool(const base::CommandLine& command_line,
const base::FilePath& current_directory)>;
+#if BUILDFLAG(IS_WIN)
+ ProcessSingleton(const std::string& program_name,
+ const base::FilePath& user_data_dir,
+ bool is_sandboxed,
+ const NotificationCallback& notification_callback);
+#else
ProcessSingleton(const base::FilePath& user_data_dir,
const NotificationCallback& notification_callback);
ProcessSingleton(const ProcessSingleton&) = delete;
ProcessSingleton& operator=(const ProcessSingleton&) = delete;
+#endif
~ProcessSingleton();
// Notify another process, if available. Otherwise sets ourselves as the
@@ -176,6 +183,8 @@ class ProcessSingleton {
#if BUILDFLAG(IS_WIN)
bool EscapeVirtualization(const base::FilePath& user_data_dir);
+ std::string program_name_; // Used for mutexName.
+ bool is_app_sandboxed_; // Whether the Electron app is sandboxed.
HWND remote_window_; // The HWND_MESSAGE of another browser.
base::win::MessageWindow window_; // The message-only window.
bool is_virtualized_; // Stuck inside Microsoft Softricity VM environment.
diff --git a/chrome/browser/process_singleton_posix.cc b/chrome/browser/process_singleton_posix.cc
index e9ba0101791d7ca84ae8a6801aa7b3607d5a6ded..0e1baf024e7aee3bc1edad1e0620bd56647d042b 100644
--- a/chrome/browser/process_singleton_posix.cc
+++ b/chrome/browser/process_singleton_posix.cc
@@ -54,6 +54,7 @@
#include <memory>
#include <set>
#include <string>
+#include <tuple>
#include <type_traits>
#include "base/base_paths.h"
@@ -81,6 +82,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner_helpers.h"
#include "base/task/single_thread_task_runner.h"
+#include "base/threading/thread_restrictions.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
@@ -96,9 +98,11 @@
#include "net/base/network_interfaces.h"
#include "ui/base/l10n/l10n_util.h"
+#if 0
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/ui/process_singleton_dialog_linux.h"
#endif
+#endif
using content::BrowserThread;
@@ -342,6 +346,9 @@ bool SymlinkPath(const base::FilePath& target, const base::FilePath& path) {
bool DisplayProfileInUseError(const base::FilePath& lock_path,
const std::string& hostname,
int pid) {
+ return true;
+
+#if 0
std::u16string error = l10n_util::GetStringFUTF16(
IDS_PROFILE_IN_USE_POSIX, base::NumberToString16(pid),
base::ASCIIToUTF16(hostname));
@@ -361,6 +368,7 @@ bool DisplayProfileInUseError(const base::FilePath& lock_path,
NOTREACHED();
return false;
+#endif
}
bool IsChromeProcess(pid_t pid) {
@@ -401,6 +409,21 @@ bool CheckCookie(const base::FilePath& path, const base::FilePath& cookie) {
return (cookie == ReadLink(path));
}
+bool IsAppSandboxed() {
+#if BUILDFLAG(IS_MAC)
+ // NB: There is no sane API for this, we have to just guess by
+ // reading tea leaves
+ base::FilePath home_dir;
+ if (!base::PathService::Get(base::DIR_HOME, &home_dir)) {
+ return false;
+ }
+
+ return home_dir.value().find("Library/Containers") != std::string::npos;
+#else
+ return false;
+#endif // BUILDFLAG(IS_MAC)
+}
+
bool ConnectSocket(ScopedSocket* socket,
const base::FilePath& socket_path,
const base::FilePath& cookie_path) {
@@ -768,6 +791,10 @@ ProcessSingleton::ProcessSingleton(
ProcessSingleton::~ProcessSingleton() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+ // Manually free resources with IO explicitly allowed.
+ base::ScopedAllowBlocking allow_blocking;
+ watcher_ = nullptr;
+ std::ignore = socket_dir_.Delete();
}
ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() {
@@ -1031,14 +1058,32 @@ bool ProcessSingleton::Create() {
#endif
}
- // Create the socket file somewhere in /tmp which is usually mounted as a
- // normal filesystem. Some network filesystems (notably AFS) are screwy and
- // do not support Unix domain sockets.
- if (!socket_dir_.CreateUniqueTempDir()) {
- LOG(ERROR) << "Failed to create socket directory.";
+ base::FilePath tmp_dir;
+ if (!base::GetTempDir(&tmp_dir)) {
+ LOG(ERROR) << "Failed to get temporary directory.";
return false;
}
+ if (IsAppSandboxed()) {
+ // For sandboxed applications, the tmp dir could be too long to fit
+ // addr->sun_path, so we need to make it as short as possible.
+ if (!socket_dir_.Set(tmp_dir.Append("S"))) {
+ LOG(ERROR) << "Failed to set socket directory.";
+ return false;
+ }
+ } else {
+ // Create the socket file somewhere in /tmp which is usually mounted as a
+ // normal filesystem. Some network filesystems (notably AFS) are screwy and
+ // do not support Unix domain sockets.
+ // Prefer CreateUniqueTempDirUnderPath rather than CreateUniqueTempDir as
+ // the latter will calculate unique paths based on bundle ids which can
+ // increase the socket path length than what is allowed.
+ if (!socket_dir_.CreateUniqueTempDirUnderPath(tmp_dir)) {
+ LOG(ERROR) << "Failed to create socket directory.";
+ return false;
+ }
+ }
+
// Check that the directory was created with the correct permissions.
int dir_mode = 0;
CHECK(base::GetPosixFilePermissions(socket_dir_.GetPath(), &dir_mode) &&
diff --git a/chrome/browser/process_singleton_win.cc b/chrome/browser/process_singleton_win.cc
index 046764b67c98924b79405ef7d5d90ca9fa972d6e..51a109504c1c8f79ef8748641ef21efed3a9315d 100644
--- a/chrome/browser/process_singleton_win.cc
+++ b/chrome/browser/process_singleton_win.cc
@@ -29,7 +29,9 @@
#include "base/win/wmi.h"
#include "chrome/browser/process_singleton_internal.h"
#include "chrome/browser/shell_integration.h"
+#if 0
#include "chrome/browser/ui/simple_message_box.h"
+#endif
#include "chrome/browser/win/chrome_process_finder.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
@@ -164,6 +166,7 @@ bool ProcessLaunchNotification(
}
bool DisplayShouldKillMessageBox() {
+#if 0
TRACE_EVENT0("startup", "ProcessSingleton:DisplayShouldKillMessageBox");
// Ensure there is an instance of ResourceBundle that is initialized for
@@ -174,6 +177,10 @@ bool DisplayShouldKillMessageBox() {
NULL, l10n_util::GetStringUTF16(IDS_PRODUCT_NAME),
l10n_util::GetStringUTF16(IDS_BROWSER_HUNGBROWSER_MESSAGE)) !=
chrome::MESSAGE_BOX_RESULT_NO;
+#endif
+ // This is called when the secondary process can't ping the primary
+ // process.
+ return false;
}
// Function was copied from Process::Terminate.
@@ -258,9 +265,13 @@ bool ProcessSingleton::EscapeVirtualization(
}
ProcessSingleton::ProcessSingleton(
+ const std::string& program_name,
const base::FilePath& user_data_dir,
+ bool is_app_sandboxed,
const NotificationCallback& notification_callback)
: notification_callback_(notification_callback),
+ program_name_(program_name),
+ is_app_sandboxed_(is_app_sandboxed),
is_virtualized_(false),
lock_file_(INVALID_HANDLE_VALUE),
user_data_dir_(user_data_dir),
@@ -380,7 +391,7 @@ ProcessSingleton::NotifyOtherProcessOrCreate() {
bool ProcessSingleton::Create() {
TRACE_EVENT0("startup", "ProcessSingleton::Create");
- static const wchar_t kMutexName[] = L"Local\\ChromeProcessSingletonStartup!";
+ std::wstring mutexName = base::UTF8ToWide("Local\\" + program_name_ + "ProcessSingletonStartup");
remote_window_ = chrome::FindRunningChromeWindow(user_data_dir_);
if (!remote_window_ && !EscapeVirtualization(user_data_dir_)) {
@@ -389,7 +400,7 @@ bool ProcessSingleton::Create() {
// access. As documented, it's clearer to NOT request ownership on creation
// since it isn't guaranteed we will get it. It is better to create it
// without ownership and explicitly get the ownership afterward.
- base::win::ScopedHandle only_me(::CreateMutex(NULL, FALSE, kMutexName));
+ base::win::ScopedHandle only_me(::CreateMutex(NULL, FALSE, mutexName.c_str()));
if (!only_me.IsValid()) {
DPLOG(FATAL) << "CreateMutex failed";
return false;
@@ -428,6 +439,17 @@ bool ProcessSingleton::Create() {
window_.CreateNamed(base::BindRepeating(&ProcessLaunchNotification,
notification_callback_),
user_data_dir_.value());
+
+ // When the app is sandboxed, firstly, the app should not be in
+ // admin mode, and even if it somehow is, messages from an unelevated
+ // instance should not be able to be sent to it.
+ if (!is_app_sandboxed_) {
+ // NB: Ensure that if the primary app gets started as elevated
+ // admin inadvertently, secondary windows running not as elevated
+ // will still be able to send messages.
+ ::ChangeWindowMessageFilterEx(window_.hwnd(), WM_COPYDATA, MSGFLT_ALLOW,
+ NULL);
+ }
CHECK(result && window_.hwnd());
}
}