mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 05:46:03 +00:00
Fix Electron Node mode sandbox injection (#2418)
* Fix Electron Node mode sandbox injection * fix(preload): treat any nonempty ELECTRON_RUN_AS_NODE as Electron Node mode
This commit is contained in:
1 parent
3c96df4ab1
commit
055e2ec78f
5 files changed
+111
-18
No files matched your search
@@ -22,22 +22,29 @@ extern char **environ;
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 3) return 2;
|
||||
const char *how = argv[1], *file = argv[2];
|
||||
char *node_env[] = {"ELECTRON_RUN_AS_NODE=1", NULL};
|
||||
char *const *child_env = !strcmp(how, "execve-node") || !strcmp(how, "execvpe-node") ||
|
||||
!strcmp(how, "spawn-node") || !strcmp(how, "spawnp-node") ? node_env : environ;
|
||||
char **args = argv + 2;
|
||||
if (!strcmp(how, "access")) {
|
||||
int result = access(file, X_OK);
|
||||
printf("access %d %d\n", result, result ? errno : 0);
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(how, "spawn") || !strcmp(how, "spawnp")) {
|
||||
if (!strcmp(how, "spawn") || !strcmp(how, "spawnp") || !strcmp(how, "spawn-node") ||
|
||||
!strcmp(how, "spawnp-node")) {
|
||||
pid_t pid;
|
||||
int error = how[5] ? posix_spawnp(&pid, file, NULL, NULL, args, environ) : posix_spawn(&pid, file, NULL, NULL, args, environ);
|
||||
int spawnp = !strcmp(how, "spawnp") || !strcmp(how, "spawnp-node");
|
||||
int error = spawnp ? posix_spawnp(&pid, file, NULL, NULL, args, child_env)
|
||||
: posix_spawn(&pid, file, NULL, NULL, args, child_env);
|
||||
if (error) { printf("errno %d\n", error); return 3; }
|
||||
int status;
|
||||
waitpid(pid, &status, 0);
|
||||
printf("exit %d\n", WEXITSTATUS(status));
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(how, "execve")) execve(file, args, environ);
|
||||
if (!strcmp(how, "execve") || !strcmp(how, "execve-node")) execve(file, args, (char *const *)child_env);
|
||||
else if (!strcmp(how, "execvpe-node")) execvpe(file, args, (char *const *)child_env);
|
||||
else if (!strcmp(how, "execv")) execv(file, args);
|
||||
else if (!strcmp(how, "execvp")) execvp(file, args);
|
||||
else if (!strcmp(how, "execvpe")) execvpe(file, args, environ);
|
||||
@@ -88,6 +95,15 @@ class BinfmtPreloadTest(unittest.TestCase):
|
||||
path.chmod(mode)
|
||||
return path
|
||||
|
||||
def chromium_script(self):
|
||||
folder = self.dir / "vscode"
|
||||
folder.mkdir()
|
||||
executable = folder / "code"
|
||||
executable.write_text("#!/bin/sh\nprintf '%s\\n' \"$@\"\n")
|
||||
executable.chmod(0o755)
|
||||
(folder / "chrome-sandbox").touch()
|
||||
return executable
|
||||
|
||||
def environment(self, desktop=True, **extra):
|
||||
env = {"PATH": "%s:/usr/bin:/bin" % self.dir, "LD_PRELOAD": str(self.library), "HANDLER_LOG": str(self.log)}
|
||||
if desktop:
|
||||
@@ -161,6 +177,17 @@ class BinfmtPreloadTest(unittest.TestCase):
|
||||
self.file("script.sh", b"#!/bin/sh\nexit 5\n")
|
||||
self.assertEqual(self.run_program("spawnp", "script.sh"), (0, "exit 5", None))
|
||||
|
||||
def test_explicit_node_child_environment_skips_injection_for_execve_and_spawn(self):
|
||||
code = self.chromium_script()
|
||||
self.assertEqual(self.run_program("execve-node", code, "--version"), (0, "--version", None))
|
||||
self.assertEqual(self.run_program("execvpe-node", code, "--version"), (0, "--version", None))
|
||||
self.assertEqual(self.run_program("spawn-node", code, "--version"), (0, "--version\nexit 0", None))
|
||||
self.assertEqual(self.run_program("spawnp-node", code, "--version"), (0, "--version\nexit 0", None))
|
||||
|
||||
def test_chromium_gui_launch_without_node_mode_still_receives_no_sandbox(self):
|
||||
code = self.chromium_script()
|
||||
self.assertEqual(self.run_program("execve", code, "--version"), (0, "--no-sandbox\n--version", None))
|
||||
|
||||
def test_the_hand_off_switch_works_without_the_desktop(self):
|
||||
tool = self.x86()
|
||||
for how in ("execve", "execvp"):
|
||||
|
||||
Reference in new issue
Block a user