noaslr: add netbsd support (#1371)
This commit is contained in:
parent
36b1d8aea2
commit
f0563475c3
@ -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"
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user