Skip to content
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

noaslr netbsd implementation proposal #1371

Merged
merged 1 commit into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we run sysctl as directly?

Copy link
Contributor Author

@devnexen devnexen Jul 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It requires privileged user, it might have more its place into scripts/ eventually IMHO.

));
}
}
Ok(())
}

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

Expand Down