Skip to content

Commit c7ce230

Browse files
fix(EXC-1811): Disable anyhow backtraces in sandbox (#2991)
EXC-1811 As of version 1.0.77, the `anyhow` crate will capture a backtrace any time an error is generated (if `RUST_BACKTRACE` is set). This triggers some SELinux denials in the sandbox because libunwind reads and writes to a pipe when capturing the backtrace. We can disable the capturing in the sandbox by setting the `RUST_LIB_BACKTRACE` env variable since we don't use these backtraces anyway.
1 parent 8622959 commit c7ce230

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

rs/canister_sandbox/src/launcher.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,12 @@ impl LauncherService for LauncherServer {
174174
socket,
175175
}: LaunchSandboxRequest,
176176
) -> rpc::Call<LaunchSandboxReply> {
177-
match spawn_socketed_process(&sandbox_exec_path, &argv, socket) {
177+
match spawn_socketed_process(
178+
&sandbox_exec_path,
179+
&argv,
180+
&[("RUST_LIB_BACKTRACE", "0")],
181+
socket,
182+
) {
178183
Ok(child_handle) => {
179184
// Ensure the launcher closes its end of the socket.
180185
drop(unsafe { UnixStream::from_raw_fd(socket) });
@@ -218,7 +223,7 @@ impl LauncherService for LauncherServer {
218223
args.push("--embedder-config".to_string());
219224
args.push(self.embedder_config_arg.clone());
220225

221-
match spawn_socketed_process(&exec_path, &args, socket) {
226+
match spawn_socketed_process(&exec_path, &args, &[], socket) {
222227
Ok(child_handle) => {
223228
// Ensure the launcher closes its end of the socket.
224229
drop(unsafe { UnixStream::from_raw_fd(socket) });

rs/canister_sandbox/src/process.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ use std::sync::Arc;
1818
pub fn spawn_socketed_process(
1919
exec_path: &str,
2020
argv: &[String],
21+
env: &[(&str, &str)],
2122
socket: RawFd,
2223
) -> std::io::Result<Child> {
2324
let mut cmd = Command::new(exec_path);
2425
cmd.args(argv);
26+
for (k, v) in env {
27+
cmd.env(k, v);
28+
}
2529

2630
// In case of Command we inherit the current process's environment. This should
2731
// particularly include things such as Rust backtrace flags. It might be
@@ -46,6 +50,7 @@ pub fn spawn_socketed_process(
4650
Ok(child_handle)
4751
}
4852

53+
/// Only used for testing setups.
4954
/// Spawn a canister sandbox process and yield RPC interface object to
5055
/// communicate with it.
5156
///
@@ -61,6 +66,8 @@ pub fn spawn_canister_sandbox_process(
6166
) -> std::io::Result<(Arc<dyn SandboxService>, Pid, std::thread::JoinHandle<()>)> {
6267
spawn_canister_sandbox_process_with_factory(exec_path, argv, controller_service, safe_shutdown)
6368
}
69+
70+
/// Only used for testing setups.
6471
/// Spawn a canister sandbox process and yield RPC interface object to
6572
/// communicate with it. When the socket is closed by the other side,
6673
/// we check if the safe_shutdown flag was set. If not this function
@@ -77,7 +84,7 @@ pub fn spawn_canister_sandbox_process_with_factory(
7784
safe_shutdown: Arc<AtomicBool>,
7885
) -> std::io::Result<(Arc<dyn SandboxService>, Pid, std::thread::JoinHandle<()>)> {
7986
let (socket, sock_sandbox) = std::os::unix::net::UnixStream::pair()?;
80-
let pid = spawn_socketed_process(exec_path, argv, sock_sandbox.as_raw_fd())?.id() as i32;
87+
let pid = spawn_socketed_process(exec_path, argv, &[], sock_sandbox.as_raw_fd())?.id() as i32;
8188

8289
let socket = Arc::new(socket);
8390

rs/canister_sandbox/src/replica_controller/launch_as_process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn spawn_launcher_process(
2626
>,
2727
) -> std::io::Result<(Box<dyn LauncherService>, Child)> {
2828
let (socket, sock_launcher) = std::os::unix::net::UnixStream::pair()?;
29-
let child_handle = spawn_socketed_process(exec_path, argv, sock_launcher.as_raw_fd())?;
29+
let child_handle = spawn_socketed_process(exec_path, argv, &[], sock_launcher.as_raw_fd())?;
3030

3131
let socket = Arc::new(socket);
3232

0 commit comments

Comments
 (0)