Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve symlinks before mounting system executable path to sandbox #206

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion task-maker-exec/src/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ impl Sandbox {
ExecutionCommand::System(cmd) => {
if let Ok(cmd) = which::which(cmd) {
// Always mount the directory with the executable.
let cmd = std::fs::canonicalize(cmd).context("Failed to canonicalize path")?;
let path = cmd.parent().expect("invalid binary path");
if !mounted_dirs.contains(path) {
config.mount(path, path, false);
Expand Down Expand Up @@ -672,7 +673,10 @@ mod tests {
assert_eq!(config.stdin, Some("/dev/null".into()));
assert_eq!(config.stdout, Some("/dev/null".into()));
assert_eq!(config.stderr, Some("/dev/null".into()));
assert_eq!(config.executable, Path::new("/bin/sh"));
assert_eq!(
config.executable,
std::fs::canonicalize(Path::new("/bin/sh")).unwrap()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applications should note that the standard PATH to the shell cannot be assumed to be either /bin/sh or /usr/bin/sh, and should be determined by interrogation of the PATH returned by getconf PATH

https://pubs.opengroup.org/onlinepubs/009695399/utilities/sh.html

);
assert_eq!(config.args, vec!["bar", "baz"]);
}
}