Upgrade rustix (#1900)
This commit is contained in:
@@ -11,7 +11,7 @@ use nom::{
|
||||
sequence::Tuple,
|
||||
IResult, Parser,
|
||||
};
|
||||
use std::{path::Path, vec};
|
||||
use std::{ffi, path::Path, vec};
|
||||
|
||||
type SeObject<'a> = Vec<&'a str>;
|
||||
|
||||
@@ -660,19 +660,19 @@ impl<'a> TryFrom<&'a PolicyStatement<'a>> for Vec<AtomicStatement> {
|
||||
struct FfiPolicy {
|
||||
cmd: u32,
|
||||
subcmd: u32,
|
||||
sepol1: *const libc::c_char,
|
||||
sepol2: *const libc::c_char,
|
||||
sepol3: *const libc::c_char,
|
||||
sepol4: *const libc::c_char,
|
||||
sepol5: *const libc::c_char,
|
||||
sepol6: *const libc::c_char,
|
||||
sepol7: *const libc::c_char,
|
||||
sepol1: *const ffi::c_char,
|
||||
sepol2: *const ffi::c_char,
|
||||
sepol3: *const ffi::c_char,
|
||||
sepol4: *const ffi::c_char,
|
||||
sepol5: *const ffi::c_char,
|
||||
sepol6: *const ffi::c_char,
|
||||
sepol7: *const ffi::c_char,
|
||||
}
|
||||
|
||||
fn to_c_ptr(pol: &PolicyObject) -> *const libc::c_char {
|
||||
fn to_c_ptr(pol: &PolicyObject) -> *const ffi::c_char {
|
||||
match pol {
|
||||
PolicyObject::None | PolicyObject::All => std::ptr::null(),
|
||||
PolicyObject::One(s) => s.as_ptr().cast::<libc::c_char>(),
|
||||
PolicyObject::One(s) => s.as_ptr().cast::<ffi::c_char>(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,30 +19,16 @@ use rustix::{
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
pub fn grant_root(global_mnt: bool) -> Result<()> {
|
||||
const KERNEL_SU_OPTION: u32 = 0xDEAD_BEEF;
|
||||
const CMD_GRANT_ROOT: u64 = 0;
|
||||
rustix::process::ksu_grant_root()?;
|
||||
|
||||
let mut result: u32 = 0;
|
||||
unsafe {
|
||||
#[allow(clippy::cast_possible_wrap)]
|
||||
libc::prctl(
|
||||
KERNEL_SU_OPTION as i32, // supposed to overflow
|
||||
CMD_GRANT_ROOT,
|
||||
0,
|
||||
0,
|
||||
std::ptr::addr_of_mut!(result).cast::<libc::c_void>(),
|
||||
);
|
||||
}
|
||||
|
||||
anyhow::ensure!(result == KERNEL_SU_OPTION, "grant root failed");
|
||||
let mut command = std::process::Command::new("sh");
|
||||
let mut command = Command::new("sh");
|
||||
let command = unsafe {
|
||||
command.pre_exec(move || {
|
||||
if global_mnt {
|
||||
let _ = utils::switch_mnt_ns(1);
|
||||
let _ = utils::unshare_mnt_ns();
|
||||
}
|
||||
std::result::Result::Ok(())
|
||||
Result::Ok(())
|
||||
})
|
||||
};
|
||||
// add /data/adb/ksu/bin to PATH
|
||||
@@ -64,7 +50,7 @@ fn print_usage(program: &str, opts: Options) {
|
||||
fn set_identity(uid: u32, gid: u32, groups: &[u32]) {
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
{
|
||||
rustix::process::set_groups(
|
||||
rustix::thread::set_thread_groups(
|
||||
groups
|
||||
.iter()
|
||||
.map(|g| unsafe { Gid::from_raw(*g) })
|
||||
@@ -89,7 +75,7 @@ pub fn root_shell() -> Result<()> {
|
||||
// we are root now, this was set in kernel!
|
||||
|
||||
use anyhow::anyhow;
|
||||
let env_args: Vec<String> = std::env::args().collect();
|
||||
let env_args: Vec<String> = env::args().collect();
|
||||
let program = env_args[0].clone();
|
||||
let args = env_args
|
||||
.iter()
|
||||
@@ -154,7 +140,7 @@ pub fn root_shell() -> Result<()> {
|
||||
.collect::<Vec<String>>();
|
||||
|
||||
let matches = match opts.parse(&args[1..]) {
|
||||
std::result::Result::Ok(m) => m,
|
||||
Result::Ok(m) => m,
|
||||
Err(f) => {
|
||||
println!("{f}");
|
||||
print_usage(&program, opts);
|
||||
@@ -282,7 +268,7 @@ pub fn root_shell() -> Result<()> {
|
||||
|
||||
set_identity(uid, gid, &groups);
|
||||
|
||||
std::result::Result::Ok(())
|
||||
Result::Ok(())
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user