util/noaslr porting to FreeBSD (the non-lib part). (#1337)
to port to the library, might need a nice layer over the FreeBSD's C api (nix?) before hand.
This commit is contained in:
parent
c0e1236a07
commit
4897c3f205
@ -1,4 +1,6 @@
|
||||
use {std::error::Error, vergen::EmitBuilder};
|
||||
use std::error::Error;
|
||||
|
||||
use vergen::EmitBuilder;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
EmitBuilder::builder()
|
||||
|
@ -1,16 +1,16 @@
|
||||
mod args;
|
||||
|
||||
use {
|
||||
crate::args::Args,
|
||||
anyhow::{anyhow, Result},
|
||||
clap::Parser,
|
||||
std::{
|
||||
use std::{
|
||||
env,
|
||||
fs::File,
|
||||
io::{BufRead, BufReader},
|
||||
},
|
||||
};
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use clap::Parser;
|
||||
|
||||
use crate::args::Args;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse();
|
||||
for (i, a) in env::args().enumerate() {
|
||||
|
@ -1,3 +1,4 @@
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
use {
|
||||
anyhow::{anyhow, Result},
|
||||
ctor::ctor,
|
||||
@ -8,6 +9,7 @@ use {
|
||||
std::{ffi::CString, fs::File, io::Read},
|
||||
};
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
fn read_null_lines(path: &str) -> Result<Vec<CString>> {
|
||||
let mut file = File::open(path).map_err(|e| anyhow!("Failed to open maps: {e:}"))?;
|
||||
let mut data = String::new();
|
||||
@ -20,6 +22,7 @@ fn read_null_lines(path: &str) -> Result<Vec<CString>> {
|
||||
.collect::<Result<Vec<CString>>>()
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
fn libnoaslr() -> Result<()> {
|
||||
let mut persona = personality::get().map_err(|e| anyhow!("Failed to get personality: {e:}"))?;
|
||||
if (persona & Persona::ADDR_NO_RANDOMIZE) == Persona::ADDR_NO_RANDOMIZE {
|
||||
@ -36,6 +39,7 @@ fn libnoaslr() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
#[ctor]
|
||||
fn init() {
|
||||
libnoaslr().unwrap();
|
||||
|
@ -13,3 +13,4 @@ log = { version = "0.4.19", default-features = false }
|
||||
nix = { version = "0.26.2", default-features = false, features = ["process", "personality"] }
|
||||
readonly = { version = "0.2.8", default-features = false }
|
||||
simplelog = { version = "0.12.1", default-features = false }
|
||||
libc = "0.2"
|
||||
|
@ -1,4 +1,6 @@
|
||||
use {std::error::Error, vergen::EmitBuilder};
|
||||
use std::error::Error;
|
||||
|
||||
use vergen::EmitBuilder;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
EmitBuilder::builder()
|
||||
|
@ -1,7 +1,6 @@
|
||||
use {
|
||||
clap::{builder::Str, Parser},
|
||||
std::iter,
|
||||
};
|
||||
use std::iter;
|
||||
|
||||
use clap::{builder::Str, Parser};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Version;
|
||||
|
@ -1,5 +1,14 @@
|
||||
mod args;
|
||||
|
||||
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
||||
use {
|
||||
crate::args::Args,
|
||||
anyhow::{anyhow, Result},
|
||||
clap::Parser,
|
||||
nix::unistd::execvp,
|
||||
std::ffi::CString,
|
||||
};
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
use {
|
||||
crate::args::Args,
|
||||
anyhow::{anyhow, Result},
|
||||
@ -11,11 +20,35 @@ use {
|
||||
std::ffi::CString,
|
||||
};
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse();
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
fn disable_aslr() -> Result<()> {
|
||||
let mut persona = personality::get().map_err(|e| anyhow!("Failed to get personality: {e:}"))?;
|
||||
persona |= Persona::ADDR_NO_RANDOMIZE;
|
||||
personality::set(persona).map_err(|e| anyhow!("Failed to set personality: {e:}"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
||||
fn disable_aslr() -> Result<()> {
|
||||
let mut status = libc::PROC_ASLR_FORCE_DISABLE;
|
||||
let r = unsafe {
|
||||
libc::procctl(
|
||||
libc::P_PID,
|
||||
0,
|
||||
libc::PROC_ASLR_CTL,
|
||||
&mut status as *mut i32 as *mut libc::c_void,
|
||||
)
|
||||
};
|
||||
if r < 0 {
|
||||
return Err(anyhow!("Failed to set aslr control"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse();
|
||||
|
||||
disable_aslr()?;
|
||||
|
||||
let cargs = args
|
||||
.argv()
|
||||
|
Loading…
x
Reference in New Issue
Block a user