Skip to content

Commit 0f27712

Browse files
Eugenynornagon
authored andcommitted
fix: allow unsandboxed renderers to request new privileges (6-0-x) (electron#20023)
1 parent b2da0b8 commit 0f27712

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

patches/common/chromium/.patches

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,4 @@ frame_host_manager.patch
8282
crashpad_pid_check.patch
8383
fix_use_weakptr_to_detect_deletion.patch
8484
fix_disabling_compositor_recycling.patch
85+
allow_new_privileges_in_unsandboxed_child_processes.patch
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Jeremy Apthorp <nornagon@nornagon.net>
3+
Date: Mon, 26 Aug 2019 12:02:51 -0700
4+
Subject: allow new privileges in unsandboxed child processes
5+
6+
This allows unsandboxed renderers to launch setuid processes on Linux.
7+
8+
diff --git a/content/browser/child_process_launcher_helper_linux.cc b/content/browser/child_process_launcher_helper_linux.cc
9+
index 720b92a1a3a7ab5512f839005b272e4989d2ac65..b1759109627cd00053489dcdd397e942fa9d289f 100644
10+
--- a/content/browser/child_process_launcher_helper_linux.cc
11+
+++ b/content/browser/child_process_launcher_helper_linux.cc
12+
@@ -54,6 +54,18 @@ bool ChildProcessLauncherHelper::BeforeLaunchOnLauncherThread(
13+
const int sandbox_fd = SandboxHostLinux::GetInstance()->GetChildSocket();
14+
options->fds_to_remap.push_back(
15+
std::make_pair(sandbox_fd, service_manager::GetSandboxFD()));
16+
+
17+
+ // (For Electron), if we're launching without zygote, that means we're
18+
+ // launching an unsandboxed process (since all sandboxed processes are
19+
+ // forked from the zygote). Relax the allow_new_privs option to permit
20+
+ // launching suid processes from unsandboxed renderers.
21+
+ service_manager::ZygoteHandle zygote_handle =
22+
+ base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoZygote)
23+
+ ? nullptr
24+
+ : delegate_->GetZygote();
25+
+ if (!zygote_handle) {
26+
+ options->allow_new_privs = true;
27+
+ }
28+
}
29+
30+
options->environment = delegate_->GetEnvironment();

spec/node-spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,19 @@ describe('node feature', () => {
155155
})
156156
})
157157
})
158+
159+
describe('child_process.exec', () => {
160+
(process.platform === 'linux' ? it : it.skip)('allows executing a setuid binary from non-sandboxed renderer', () => {
161+
// Chrome uses prctl(2) to set the NO_NEW_PRIVILEGES flag on Linux (see
162+
// https://github.com/torvalds/linux/blob/40fde647cc/Documentation/userspace-api/no_new_privs.rst).
163+
// We disable this for unsandboxed processes, which the remote tests
164+
// are running in. If this test fails with an error like 'effective uid
165+
// is not 0', then it's likely that our patch to prevent the flag from
166+
// being set has become ineffective.
167+
const stdout = ChildProcess.execSync('sudo --help')
168+
expect(stdout).to.not.be.empty()
169+
})
170+
})
158171
})
159172

160173
describe('contexts', () => {

0 commit comments

Comments
 (0)