-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Enabling static-pie for musl #70740
Merged
Merged
Enabling static-pie for musl #70740
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-include ../../run-make-fulldeps/tools.mk | ||
|
||
# only-x86_64-unknown-linux-musl | ||
|
||
# How to manually run this | ||
# $ ./x.py test --target x86_64-unknown-linux-musl src/test/run-make/static-pie | ||
|
||
all: | ||
$(RUSTC) --target $(TARGET) -C target-feature=+crt-static test-aslr.rs | ||
# Check that no dynamic interpreter is set | ||
! readelf -l $(call RUN_BINFILE,test-aslr) | $(CGREP) INTERP | ||
# Check that we have a dynamic executable | ||
readelf -l $(call RUN_BINFILE,test-aslr) | $(CGREP) DYNAMIC | ||
# Check for address space layout randomization | ||
$(call RUN,test-aslr) --test-aslr |
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,43 @@ | ||
const NUM_RUNS: usize = 10; | ||
|
||
fn run_self(exe: &str) -> usize { | ||
use std::process::Command; | ||
let mut set = std::collections::HashSet::new(); | ||
|
||
let mut cmd = Command::new(exe); | ||
cmd.arg("--report"); | ||
(0..NUM_RUNS).for_each(|_| { | ||
set.insert(cmd.output().expect("failed to execute process").stdout); | ||
}); | ||
set.len() | ||
} | ||
|
||
fn main() { | ||
let mut args = std::env::args(); | ||
let arg0 = args.next().unwrap(); | ||
match args.next() { | ||
Some(s) if s.eq("--report") => { | ||
println!("main = {:#?}", &main as *const _); | ||
} | ||
Some(s) if s.eq("--test-no-aslr") => { | ||
let cnt = run_self(&arg0); | ||
if cnt != 1 { | ||
eprintln!("FAIL: {} most likely ASLR", arg0); | ||
std::process::exit(1); | ||
} | ||
println!("PASS: {} does no ASLR", arg0); | ||
} | ||
Some(s) if s.eq("--test-aslr") => { | ||
let cnt = run_self(&arg0); | ||
if cnt != NUM_RUNS { | ||
eprintln!("FAIL: {} most likely no ASLR", arg0); | ||
std::process::exit(1); | ||
} | ||
println!("PASS: {} does ASLR", arg0); | ||
} | ||
Some(_) | None => { | ||
println!("Usage: {} --test-no-aslr | --test-aslr", arg0); | ||
std::process::exit(1); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this won't be a subject to birthday paradox occasionally, causing spurious failures. (I didn't calculate the exact probability though. Are all pages equally probable with ASLR?)
Perhaps
cnt == 1
would be more reliable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix this in a follow-up PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or to give credit, you should fix it 😄