Skip to content

Commit b4607cc

Browse files
committed
Always clear LD_PRELOAD on host process start
Some apps might not use the same execve call to start child processes, so clearing LD_PRELOAD there isn't actually safe. Fixes #32. Signed-off-by: Ryan Gonzalez <ryan.gonzalez@collabora.com>
1 parent 28573f6 commit b4607cc

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ preload_host_SOURCES := \
6666

6767
$(call build_shlib,preload_host)
6868

69+
preload_host_mimic_strategy_SOURCE_DIR := preload/host/mimic_strategy
70+
preload_host_mimic_strategy_NAME := zypak-preload-host-mimic-strategy
71+
preload_host_mimic_strategy_DEPS := preload base
72+
preload_host_mimic_strategy_SOURCES := \
73+
initialize.cc \
74+
75+
$(call build_shlib,preload_host_mimic_strategy)
76+
6977
preload_host_spawn_strategy_SOURCE_DIR := preload/host/spawn_strategy
7078
preload_host_spawn_strategy_NAME := zypak-preload-host-spawn-strategy
7179
preload_host_spawn_strategy_DEPS := preload dbus base
@@ -140,6 +148,7 @@ install : all
140148
install -Dm 755 -t $(FLATPAK_DEST)/bin build/zypak-helper
141149
install -Dm 755 -t $(FLATPAK_DEST)/bin build/zypak-sandbox
142150
install -Dm 755 -t $(FLATPAK_DEST)/lib build/libzypak-preload-host.so
151+
install -Dm 755 -t $(FLATPAK_DEST)/lib build/libzypak-preload-host-mimic-strategy.so
143152
install -Dm 755 -t $(FLATPAK_DEST)/lib build/libzypak-preload-host-spawn-strategy.so
144153
install -Dm 755 -t $(FLATPAK_DEST)/lib build/libzypak-preload-child.so
145154
install -Dm 755 -t $(FLATPAK_DEST)/lib build/libzypak-preload-child-mimic-strategy.so

src/helper/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ std::string GetPreload(std::string_view mode, std::string_view libdir) {
124124
preload_names.emplace_back(mode);
125125
if (Env::Test(Env::kZypakZygoteStrategySpawn)) {
126126
preload_names.push_back(std::string(mode) + "-spawn-strategy");
127-
} else if (mode == "child") {
127+
} else {
128128
preload_names.push_back(std::string(mode) + "-mimic-strategy");
129129
}
130130

src/preload/host/exec_zypak_sandbox.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ DECLARE_OVERRIDE(int, execvp, const char* file, char* const* argv) {
5555
return -1;
5656
}
5757

58-
Env::Clear("LD_PRELOAD");
59-
6058
if (file == SandboxPath::instance()->sandbox_path()) {
6159
file = "zypak-sandbox";
6260
} else if (auto type = GetTypeArg(argv);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2023 Ryan Gonzalez
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "base/env.h"
6+
#include "preload/main_override.h"
7+
8+
using namespace zypak;
9+
10+
int MAIN_OVERRIDE(int argc, char** argv, char** envp) {
11+
Env::Clear("LD_PRELOAD");
12+
return true_main(argc, argv, envp);
13+
}
14+
15+
INSTALL_MAIN_OVERRIDE()

src/preload/host/spawn_strategy/initialize.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "base/base.h"
1212
#include "base/debug.h"
13+
#include "base/env.h"
1314
#include "base/socket.h"
1415
#include "dbus/bus.h"
1516
#include "preload/declare_override.h"
@@ -20,6 +21,8 @@ using namespace zypak;
2021
using namespace zypak::preload;
2122

2223
int MAIN_OVERRIDE(int argc, char** argv, char** envp) {
24+
Env::Clear("LD_PRELOAD");
25+
2326
DebugContext::instance()->LoadFromEnvironment();
2427
DebugContext::instance()->set_name("preload-host-spawn-strategy");
2528

0 commit comments

Comments
 (0)