Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not try to acquire capabilities we are not allowed to #2000

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions crates/libcontainer/src/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ impl CapabilityExt for SpecCapability {
/// see <https://man7.org/linux/man-pages/man7/capabilities.7.html> for more information
pub fn reset_effective<S: Syscall + ?Sized>(syscall: &S) -> Result<(), SyscallError> {
tracing::debug!("reset all caps");
syscall.set_capability(CapSet::Effective, &caps::all())?;
// permitted capabilities are all the capabilities that we are allowed to acquire
let permitted = caps::read(None, CapSet::Permitted)?;
syscall.set_capability(CapSet::Effective, &permitted)?;
Ok(())
}

Expand Down Expand Up @@ -172,13 +174,14 @@ mod tests {
#[test]
fn test_reset_effective() {
let test_command = TestHelperSyscall::default();
let permitted_caps = caps::read(None, CapSet::Permitted).unwrap();
assert!(reset_effective(&test_command).is_ok());
let set_capability_args: Vec<_> = test_command
.get_set_capability_args()
.into_iter()
.map(|(_capset, caps)| caps)
.collect();
assert_eq!(set_capability_args, vec![caps::all()]);
assert_eq!(set_capability_args, vec![permitted_caps]);
}

#[test]
Expand Down