Allow current process to access its own proc data

This commit is contained in:
Jeremy Soller
2021-08-10 16:33:49 -06:00
parent 0b1445f8bd
commit f94dc3beb8

View File

@@ -277,21 +277,24 @@ impl Scheme for ProcScheme {
let current = contexts.current().ok_or(Error::new(ESRCH))?;
let current = current.read();
// Do we own the process?
if uid != target.euid && gid != target.egid {
return Err(Error::new(EPERM));
}
// Are we the process?
if target.id != current.id {
// Do we own the process?
if uid != target.euid && gid != target.egid {
return Err(Error::new(EPERM));
}
// Is it a subprocess of us? In the future, a capability could
// bypass this check.
match contexts.ancestors(target.ppid).find(|&(id, _context)| id == current.id) {
Some((id, context)) => {
// Paranoid sanity check, as ptrace security holes
// wouldn't be fun
assert_eq!(id, current.id);
assert_eq!(id, context.read().id);
},
None => return Err(Error::new(EPERM)),
// Is it a subprocess of us? In the future, a capability could
// bypass this check.
match contexts.ancestors(target.ppid).find(|&(id, _context)| id == current.id) {
Some((id, context)) => {
// Paranoid sanity check, as ptrace security holes
// wouldn't be fun
assert_eq!(id, current.id);
assert_eq!(id, context.read().id);
},
None => return Err(Error::new(EPERM)),
}
}
}
};