noaslr: add netbsd support (#1371)

This commit is contained in:
David CARLIER 2023-07-16 16:09:44 +01:00 committed by GitHub
parent 36b1d8aea2
commit f0563475c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -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"

View File

@ -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();