ksud: fix gid is override by uid
This commit is contained in:
@@ -58,11 +58,11 @@ fn print_usage(program: &str, opts: Options) {
|
|||||||
print!("{}", opts.usage(&brief));
|
print!("{}", opts.usage(&brief));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_identity(uid: u32) {
|
fn set_identity(uid: u32, gid: u32) {
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
unsafe {
|
unsafe {
|
||||||
libc::seteuid(uid);
|
libc::seteuid(uid);
|
||||||
libc::setresgid(uid, uid, uid);
|
libc::setresgid(gid, gid, gid);
|
||||||
libc::setresuid(uid, uid, uid);
|
libc::setresuid(uid, uid, uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,6 +170,7 @@ pub fn root_shell() -> Result<()> {
|
|||||||
|
|
||||||
// use current uid if no user specified, these has been done in kernel!
|
// use current uid if no user specified, these has been done in kernel!
|
||||||
let mut uid = unsafe { libc::getuid() };
|
let mut uid = unsafe { libc::getuid() };
|
||||||
|
let gid = unsafe { libc::getgid() };
|
||||||
if free_idx < matches.free.len() {
|
if free_idx < matches.free.len() {
|
||||||
let name = &matches.free[free_idx];
|
let name = &matches.free[free_idx];
|
||||||
uid = unsafe {
|
uid = unsafe {
|
||||||
@@ -235,7 +236,7 @@ pub fn root_shell() -> Result<()> {
|
|||||||
let _ = utils::unshare_mnt_ns();
|
let _ = utils::unshare_mnt_ns();
|
||||||
}
|
}
|
||||||
|
|
||||||
set_identity(uid);
|
set_identity(uid, gid);
|
||||||
|
|
||||||
std::result::Result::Ok(())
|
std::result::Result::Ok(())
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user