Skip to content

Commit

Permalink
noaslr: add netbsd support (#1371)
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen authored Jul 16, 2023
1 parent 36b1d8a commit f056347
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion utils/noaslr/noaslr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ nix = { version = "0.26.2", default-features = false, features = ["process", "pe
readonly = { version = "0.2.8", default-features = false }
simplelog = { version = "0.12.1", default-features = false }

[target.'cfg(any(target_os = "freebsd", target_os = "dragonfly"))'.dependencies]
[target.'cfg(any(target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd"))'.dependencies]
libc = "0.2"
28 changes: 28 additions & 0 deletions utils/noaslr/noaslr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@ fn disable_aslr() -> Result<()> {
Ok(())
}

#[cfg(target_os = "netbsd")]
fn disable_aslr() -> Result<()> {
unsafe {
let mut aslr: i32 = 0;
let mut s = std::mem::size_of::<i32>();
let nm = CString::new("security.pax.aslr.enabled")
.map_err(|e| anyhow!("Failed to create sysctl oid: {e:}"))
.unwrap();
if libc::sysctlbyname(
nm.as_ptr(),
&mut aslr as *mut i32 as _,
&mut s,
std::ptr::null(),
0,
) < 0
{
return Err(anyhow!("Failed to get aslr status"));
}

if aslr > 0 {
return Err(anyhow!(
"Please disable aslr with sysctl -w security.pax.aslr.enabled=0 as privileged user"
));
}
}
Ok(())
}

fn main() -> Result<()> {
let args = Args::parse();

Expand Down

0 comments on commit f056347

Please sign in to comment.