Skip to content

Commit 5930629

Browse files
committed
remove usage of absolute rpaths
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.
1 parent 68903f2 commit 5930629

File tree

1 file changed

+1
-29
lines changed

1 file changed

+1
-29
lines changed

src/librustc/back/rpath.rs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ fn get_rpaths(os: abi::Os,
8686
// crates they depend on.
8787
let rel_rpaths = get_rpaths_relative_to_output(os, output, libs);
8888

89-
// Make backup absolute paths to the libraries. Binaries can
90-
// be moved as long as the crates they link against don't move.
91-
let abs_rpaths = get_absolute_rpaths(libs);
92-
9389
// And a final backup rpath to the global library location.
9490
let fallback_rpaths = ~[get_install_prefix_rpath(target_triple)];
9591

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

10399
log_rpaths("relative", rel_rpaths);
104-
log_rpaths("absolute", abs_rpaths);
105100
log_rpaths("fallback", fallback_rpaths);
106101

107102
let mut rpaths = rel_rpaths;
108-
rpaths.push_all(abs_rpaths);
109103
rpaths.push_all(fallback_rpaths);
110104

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

148-
fn get_absolute_rpaths(libs: &[Path]) -> ~[~str] {
149-
libs.iter().map(|a| get_absolute_rpath(a)).collect()
150-
}
151-
152-
pub fn get_absolute_rpath(lib: &Path) -> ~str {
153-
let mut p = os::make_absolute(lib);
154-
p.pop();
155-
// FIXME (#9639): This needs to handle non-utf8 paths
156-
p.as_str().expect("non-utf8 component in rpath").to_owned()
157-
}
158-
159142
pub fn get_install_prefix_rpath(target_triple: &str) -> ~str {
160143
let install_prefix = env!("CFG_PREFIX");
161144

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

185-
use back::rpath::{get_absolute_rpath, get_install_prefix_rpath};
168+
use back::rpath::get_install_prefix_rpath;
186169
use back::rpath::{minimize_rpaths, rpaths_to_flags, get_rpath_relative_to_output};
187170
use syntax::abi;
188171
use metadata::filesearch;
@@ -255,15 +238,4 @@ mod test {
255238
&Path::new("lib/libstd.so"));
256239
assert_eq!(res.as_slice(), "@loader_path/../lib");
257240
}
258-
259-
#[test]
260-
fn test_get_absolute_rpath() {
261-
let res = get_absolute_rpath(&Path::new("lib/libstd.so"));
262-
let lib = os::make_absolute(&Path::new("lib"));
263-
debug!("test_get_absolute_rpath: {} vs. {}",
264-
res.to_str(), lib.display());
265-
266-
// FIXME (#9639): This needs to handle non-utf8 paths
267-
assert_eq!(res.as_slice(), lib.as_str().expect("non-utf8 component in path"));
268-
}
269241
}

0 commit comments

Comments
 (0)