Replace setuid, setgid with setreuid, setregid

This commit is contained in:
Jeremy Soller 2016-11-17 14:16:39 -07:00
parent c5e0d77085
commit 1f28ec72b7
6 changed files with 47 additions and 17 deletions

View file

@ -5,11 +5,13 @@ use context;
use syscall::error::Result;
pub fn resource() -> Result<Vec<u8>> {
let mut string = format!("{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<8}{:<6}{}\n",
let mut string = format!("{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<8}{:<6}{}\n",
"PID",
"PPID",
"UID",
"GID",
"RUID",
"RGID",
"EUID",
"EGID",
"STAT",
"CPU",
"MEM",
@ -83,9 +85,11 @@ pub fn resource() -> Result<Vec<u8>> {
let name_bytes = context.name.lock();
let name = str::from_utf8(&name_bytes).unwrap_or("");
string.push_str(&format!("{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<8}{:<6}{}\n",
string.push_str(&format!("{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<6}{:<8}{:<6}{}\n",
context.id.into(),
context.ppid.into(),
context.ruid,
context.rgid,
context.euid,
context.egid,
stat_string,

View file

@ -86,8 +86,8 @@ pub extern fn syscall(a: usize, b: usize, c: usize, d: usize, e: usize, f: usize
SYS_GETGID => getgid(),
SYS_GETEUID => geteuid(),
SYS_GETEGID => getegid(),
SYS_SETUID => setuid(b as u32),
SYS_SETGID => setgid(b as u32),
SYS_SETREUID => setreuid(b as u32, c as u32),
SYS_SETREGID => setregid(b as u32, c as u32),
SYS_SETNS => setns(validate_slice(b as *const [usize; 2], c)?),
SYS_PIPE2 => pipe2(validate_slice_mut(b as *mut usize, 2)?, c),
SYS_PHYSALLOC => physalloc(b),

View file

@ -33,26 +33,52 @@ pub fn getuid() -> Result<usize> {
Ok(context.ruid as usize)
}
pub fn setgid(gid: u32) -> Result<usize> {
pub fn setregid(rgid: u32, egid: u32) -> Result<usize> {
let contexts = context::contexts();
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
let mut context = context_lock.write();
if context.egid == 0 {
context.rgid = gid;
context.egid = gid;
if (context.euid == 0
|| rgid as i32 == -1
|| rgid == context.egid
|| rgid == context.rgid)
&& (context.euid == 0
|| egid as i32 == -1
|| egid == context.egid
|| egid == context.rgid)
{
if rgid as i32 != -1 {
context.rgid = rgid;
}
if egid as i32 != -1 {
context.egid = egid;
}
Ok(0)
} else {
Err(Error::new(EPERM))
}
}
pub fn setuid(uid: u32) -> Result<usize> {
pub fn setreuid(ruid: u32, euid: u32) -> Result<usize> {
let contexts = context::contexts();
let context_lock = contexts.current().ok_or(Error::new(ESRCH))?;
let mut context = context_lock.write();
if context.euid == 0 {
context.ruid = uid;
context.euid = uid;
if (context.euid == 0
|| ruid as i32 == -1
|| ruid == context.euid
|| ruid == context.ruid)
&& (context.euid == 0
|| euid as i32 == -1
|| euid == context.euid
|| euid == context.ruid)
{
if ruid as i32 != -1 {
context.ruid = ruid;
}
if euid as i32 != -1 {
context.euid = euid;
}
Ok(0)
} else {
Err(Error::new(EPERM))

View file

@ -8,7 +8,7 @@ use self::syscall::data::{Stat, TimeSpec};
pub use self::syscall::error::*;
pub use self::syscall::flag::*;
pub use self::syscall::{
clock_gettime, clone, execve as exec, exit, futex, getpid, kill, nanosleep, setgid, setuid, waitpid,
clock_gettime, clone, execve as exec, exit, futex, getpid, kill, nanosleep, setregid, setreuid, waitpid,
chdir, chmod, getcwd, open, mkdir, rmdir, unlink, dup, pipe2,
read, write, fcntl, fpath, fstat, fsync, ftruncate, lseek, close
};

2
rust

@ -1 +1 @@
Subproject commit f01add1a3bc3d86ee62f5819fa6ed9f79d453665
Subproject commit 2556400a5d4c9b56084332c29b6c91ac5cd3a9fa

@ -1 +1 @@
Subproject commit 7b8cc598909189526d8c0caa8057e4a6b23f0fdc
Subproject commit 8ce29a6ea29042d4101733cc25e84a013a74018a