Skip to content

Commit 62297a7

Browse files
authored
Upgrade rustix (tiann#1900)
1 parent 54322c0 commit 62297a7

File tree

3 files changed

+38
-52
lines changed

3 files changed

+38
-52
lines changed

userspace/ksud/Cargo.lock

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

userspace/ksud/src/sepolicy.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use nom::{
1111
sequence::Tuple,
1212
IResult, Parser,
1313
};
14-
use std::{path::Path, vec};
14+
use std::{ffi, path::Path, vec};
1515

1616
type SeObject<'a> = Vec<&'a str>;
1717

@@ -660,19 +660,19 @@ impl<'a> TryFrom<&'a PolicyStatement<'a>> for Vec<AtomicStatement> {
660660
struct FfiPolicy {
661661
cmd: u32,
662662
subcmd: u32,
663-
sepol1: *const libc::c_char,
664-
sepol2: *const libc::c_char,
665-
sepol3: *const libc::c_char,
666-
sepol4: *const libc::c_char,
667-
sepol5: *const libc::c_char,
668-
sepol6: *const libc::c_char,
669-
sepol7: *const libc::c_char,
663+
sepol1: *const ffi::c_char,
664+
sepol2: *const ffi::c_char,
665+
sepol3: *const ffi::c_char,
666+
sepol4: *const ffi::c_char,
667+
sepol5: *const ffi::c_char,
668+
sepol6: *const ffi::c_char,
669+
sepol7: *const ffi::c_char,
670670
}
671671

672-
fn to_c_ptr(pol: &PolicyObject) -> *const libc::c_char {
672+
fn to_c_ptr(pol: &PolicyObject) -> *const ffi::c_char {
673673
match pol {
674674
PolicyObject::None | PolicyObject::All => std::ptr::null(),
675-
PolicyObject::One(s) => s.as_ptr().cast::<libc::c_char>(),
675+
PolicyObject::One(s) => s.as_ptr().cast::<ffi::c_char>(),
676676
}
677677
}
678678

userspace/ksud/src/su.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,16 @@ use rustix::{
1919

2020
#[cfg(any(target_os = "linux", target_os = "android"))]
2121
pub fn grant_root(global_mnt: bool) -> Result<()> {
22-
const KERNEL_SU_OPTION: u32 = 0xDEAD_BEEF;
23-
const CMD_GRANT_ROOT: u64 = 0;
24-
25-
let mut result: u32 = 0;
26-
unsafe {
27-
#[allow(clippy::cast_possible_wrap)]
28-
libc::prctl(
29-
KERNEL_SU_OPTION as i32, // supposed to overflow
30-
CMD_GRANT_ROOT,
31-
0,
32-
0,
33-
std::ptr::addr_of_mut!(result).cast::<libc::c_void>(),
34-
);
35-
}
22+
rustix::process::ksu_grant_root()?;
3623

37-
anyhow::ensure!(result == KERNEL_SU_OPTION, "grant root failed");
38-
let mut command = std::process::Command::new("sh");
24+
let mut command = Command::new("sh");
3925
let command = unsafe {
4026
command.pre_exec(move || {
4127
if global_mnt {
4228
let _ = utils::switch_mnt_ns(1);
4329
let _ = utils::unshare_mnt_ns();
4430
}
45-
std::result::Result::Ok(())
31+
Result::Ok(())
4632
})
4733
};
4834
// add /data/adb/ksu/bin to PATH
@@ -64,7 +50,7 @@ fn print_usage(program: &str, opts: Options) {
6450
fn set_identity(uid: u32, gid: u32, groups: &[u32]) {
6551
#[cfg(any(target_os = "linux", target_os = "android"))]
6652
{
67-
rustix::process::set_groups(
53+
rustix::thread::set_thread_groups(
6854
groups
6955
.iter()
7056
.map(|g| unsafe { Gid::from_raw(*g) })
@@ -89,7 +75,7 @@ pub fn root_shell() -> Result<()> {
8975
// we are root now, this was set in kernel!
9076

9177
use anyhow::anyhow;
92-
let env_args: Vec<String> = std::env::args().collect();
78+
let env_args: Vec<String> = env::args().collect();
9379
let program = env_args[0].clone();
9480
let args = env_args
9581
.iter()
@@ -154,7 +140,7 @@ pub fn root_shell() -> Result<()> {
154140
.collect::<Vec<String>>();
155141

156142
let matches = match opts.parse(&args[1..]) {
157-
std::result::Result::Ok(m) => m,
143+
Result::Ok(m) => m,
158144
Err(f) => {
159145
println!("{f}");
160146
print_usage(&program, opts);
@@ -282,7 +268,7 @@ pub fn root_shell() -> Result<()> {
282268

283269
set_identity(uid, gid, &groups);
284270

285-
std::result::Result::Ok(())
271+
Result::Ok(())
286272
})
287273
};
288274

0 commit comments

Comments
 (0)