-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix symlink handling with Linux sandbox (#59)
This fixes an issue where dangling symbolic links would cause errors while locking down the sandbox since the `mount` syscall is not able to resolve the link. To ensure symlinks are mapped correctly, the Linux sandbox now maps every exception to its canonicalized path, granting access to the symlink's **TARGET**. Then if necessary the symlink pointing to this file is created to ensure access through the exception's original path.
- Loading branch information
Showing
7 changed files
with
183 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::os::unix::fs as unixfs; | ||
use std::path::PathBuf; | ||
use std::process::Command; | ||
|
||
use birdcage::{Birdcage, Exception, Sandbox}; | ||
|
||
fn main() { | ||
// Create symlinked executable dir. | ||
let tempdir = tempfile::tempdir().unwrap().into_path(); | ||
let symlink_dir = tempdir.join("bin"); | ||
unixfs::symlink("/usr/bin", &symlink_dir).unwrap(); | ||
|
||
let mut birdcage = Birdcage::new(); | ||
birdcage.add_exception(Exception::ExecuteAndRead(symlink_dir.clone())).unwrap(); | ||
if PathBuf::from("/lib64").exists() { | ||
birdcage.add_exception(Exception::ExecuteAndRead("/lib64".into())).unwrap(); | ||
} | ||
if PathBuf::from("/lib").exists() { | ||
birdcage.add_exception(Exception::ExecuteAndRead("/lib".into())).unwrap(); | ||
} | ||
birdcage.lock().unwrap(); | ||
|
||
// Ensure symlinked dir's executable works. | ||
let symlink_dir_exec = symlink_dir.join("true"); | ||
let cmd = Command::new(symlink_dir_exec).status().unwrap(); | ||
assert!(cmd.success()); | ||
|
||
// Ensure original dir's executable works. | ||
let cmd = Command::new("/usr/bin/true").status().unwrap(); | ||
assert!(cmd.success()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::os::unix::fs as unixfs; | ||
use std::path::PathBuf; | ||
use std::process::Command; | ||
|
||
use birdcage::{Birdcage, Exception, Sandbox}; | ||
|
||
fn main() { | ||
// Create symlinked executable dir. | ||
let tempdir = tempfile::tempdir().unwrap().into_path(); | ||
let symlink_dir = tempdir.join("bin"); | ||
let symlink_dir_exec = symlink_dir.join("true"); | ||
unixfs::symlink("/usr/bin", &symlink_dir).unwrap(); | ||
|
||
let mut birdcage = Birdcage::new(); | ||
birdcage.add_exception(Exception::ExecuteAndRead(symlink_dir_exec.clone())).unwrap(); | ||
if PathBuf::from("/lib64").exists() { | ||
birdcage.add_exception(Exception::ExecuteAndRead("/lib64".into())).unwrap(); | ||
} | ||
if PathBuf::from("/lib").exists() { | ||
birdcage.add_exception(Exception::ExecuteAndRead("/lib".into())).unwrap(); | ||
} | ||
birdcage.lock().unwrap(); | ||
|
||
// Ensure symlinked dir's executable works. | ||
let cmd = Command::new(symlink_dir_exec).status().unwrap(); | ||
assert!(cmd.success()); | ||
|
||
// Ensure original dir's executable works. | ||
let cmd = Command::new("/usr/bin/true").status().unwrap(); | ||
assert!(cmd.success()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::fs; | ||
use std::os::unix::fs as unixfs; | ||
use std::path::PathBuf; | ||
use std::process::Command; | ||
|
||
use birdcage::{Birdcage, Exception, Sandbox}; | ||
|
||
fn main() { | ||
// Create symlinked executable. | ||
let tempdir = tempfile::tempdir().unwrap().into_path(); | ||
let exec_dir = tempdir.join("bin"); | ||
fs::create_dir(&exec_dir).unwrap(); | ||
let symlink_exec = exec_dir.join("true"); | ||
unixfs::symlink("/usr/bin/true", &symlink_exec).unwrap(); | ||
|
||
let mut birdcage = Birdcage::new(); | ||
birdcage.add_exception(Exception::ExecuteAndRead(symlink_exec.clone())).unwrap(); | ||
if PathBuf::from("/lib64").exists() { | ||
birdcage.add_exception(Exception::ExecuteAndRead("/lib64".into())).unwrap(); | ||
} | ||
if PathBuf::from("/lib").exists() { | ||
birdcage.add_exception(Exception::ExecuteAndRead("/lib".into())).unwrap(); | ||
} | ||
birdcage.lock().unwrap(); | ||
|
||
// Ensure symlinked executable works. | ||
let cmd = Command::new(symlink_exec).status().unwrap(); | ||
assert!(cmd.success()); | ||
|
||
// Ensure original executable works. | ||
let cmd = Command::new("/usr/bin/true").status().unwrap(); | ||
assert!(cmd.success()); | ||
} |