From 8e017f25af73dcbb1861b677ab108bf84a7bcf2b Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Tue, 23 Jun 2020 15:56:53 +0200 Subject: [PATCH] add content/2020-06-23-rust-static-pie.md --- content/2020-06-23-rust-static-pie.md | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 content/2020-06-23-rust-static-pie.md diff --git a/content/2020-06-23-rust-static-pie.md b/content/2020-06-23-rust-static-pie.md new file mode 100644 index 0000000..27c1263 --- /dev/null +++ b/content/2020-06-23-rust-static-pie.md @@ -0,0 +1,54 @@ ++++ +title = "Rust - Static PIE and ASLR for the x86_64-unknown-linux-musl Target" +date = 2020-06-23 +[taxonomies] +tags = ["rust", "musl"] +categories = ["programming"] ++++ + +With current rust nightly the default binary output of the `x86_64-unknown-linux-musl` target is a +static position independent executable (static-pie) +with address space layout randomization (ASLR) on execution. + + + +hello.rs: +```rust +fn main() { + println!("main = {:#x}", &main as *const _ as usize); +} +``` + +Current stable rust 1.44.1 produces the usual static elf binary: +```console +$ rustc --version + rustc 1.44.1 (c7087fe00 2020-06-17) + +$ rustc --target x86_64-unknown-linux-musl hello.rs + +$ file hello +hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=3f44a4c3315d4c7c94c64b332a3fb3e604a7c066, with debug_info, not stripped + +$ ./hello +main = 0x43b008 + +$ ./hello +main = 0x43b008 +``` + +Current nightly rust 1.46.0 produces a static-pie with ASLR: +```console +$ rustc +nightly --version +rustc 1.46.0-nightly (6bb3dbfc6 2020-06-22) + +$ rustc +nightly --target x86_64-unknown-linux-musl hello.rs + +$ file hello +hello: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=9592de3bfd3e9b71296edb494f1eac23958a4c59, with debug_info, not stripped + +$ ./hello +main = 0x7f7310574008 + +$ ./hello +main = 0x7fb552b0c008 +``` \ No newline at end of file