Skip to content

Commit

Permalink
remove usage of absolute rpaths
Browse files Browse the repository at this point in the history
This is a significant security issue as it adds a hidden library path
based on the location of the build directory. It is *always* wrong in an
installed package, and can be leveraged by an unprivileged user to
inject libraries into a binary called by another user or even root.

Closes #11746

This is a step towards fixing #11747 but is only a partial solution.
  • Loading branch information
thestinger committed Mar 7, 2014
1 parent 68903f2 commit 5930629
Showing 1 changed file with 1 addition and 29 deletions.
30 changes: 1 addition & 29 deletions src/librustc/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ fn get_rpaths(os: abi::Os,
// crates they depend on.
let rel_rpaths = get_rpaths_relative_to_output(os, output, libs);

// Make backup absolute paths to the libraries. Binaries can
// be moved as long as the crates they link against don't move.
let abs_rpaths = get_absolute_rpaths(libs);

// And a final backup rpath to the global library location.
let fallback_rpaths = ~[get_install_prefix_rpath(target_triple)];

Expand All @@ -101,11 +97,9 @@ fn get_rpaths(os: abi::Os,
}

log_rpaths("relative", rel_rpaths);
log_rpaths("absolute", abs_rpaths);
log_rpaths("fallback", fallback_rpaths);

let mut rpaths = rel_rpaths;
rpaths.push_all(abs_rpaths);
rpaths.push_all(fallback_rpaths);

// Remove duplicates
Expand Down Expand Up @@ -145,17 +139,6 @@ pub fn get_rpath_relative_to_output(os: abi::Os,
prefix+"/"+relative.as_str().expect("non-utf8 component in path")
}

fn get_absolute_rpaths(libs: &[Path]) -> ~[~str] {
libs.iter().map(|a| get_absolute_rpath(a)).collect()
}

pub fn get_absolute_rpath(lib: &Path) -> ~str {
let mut p = os::make_absolute(lib);
p.pop();
// FIXME (#9639): This needs to handle non-utf8 paths
p.as_str().expect("non-utf8 component in rpath").to_owned()
}

pub fn get_install_prefix_rpath(target_triple: &str) -> ~str {
let install_prefix = env!("CFG_PREFIX");

Expand All @@ -182,7 +165,7 @@ pub fn minimize_rpaths(rpaths: &[~str]) -> ~[~str] {
mod test {
use std::os;

use back::rpath::{get_absolute_rpath, get_install_prefix_rpath};
use back::rpath::get_install_prefix_rpath;
use back::rpath::{minimize_rpaths, rpaths_to_flags, get_rpath_relative_to_output};
use syntax::abi;
use metadata::filesearch;
Expand Down Expand Up @@ -255,15 +238,4 @@ mod test {
&Path::new("lib/libstd.so"));
assert_eq!(res.as_slice(), "@loader_path/../lib");
}

#[test]
fn test_get_absolute_rpath() {
let res = get_absolute_rpath(&Path::new("lib/libstd.so"));
let lib = os::make_absolute(&Path::new("lib"));
debug!("test_get_absolute_rpath: {} vs. {}",
res.to_str(), lib.display());

// FIXME (#9639): This needs to handle non-utf8 paths
assert_eq!(res.as_slice(), lib.as_str().expect("non-utf8 component in path"));
}
}

4 comments on commit 5930629

@bors
Copy link
Contributor

@bors bors commented on 5930629 Mar 7, 2014

Choose a reason for hiding this comment

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

@bors
Copy link
Contributor

@bors bors commented on 5930629 Mar 7, 2014

Choose a reason for hiding this comment

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

merging thestinger/rust/rpath = 5930629 into auto

@bors
Copy link
Contributor

@bors bors commented on 5930629 Mar 7, 2014

Choose a reason for hiding this comment

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

thestinger/rust/rpath = 5930629 merged ok, testing candidate = 4092108e

@bors
Copy link
Contributor

@bors bors commented on 5930629 Mar 7, 2014

Choose a reason for hiding this comment

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

Please sign in to comment.