Skip to content

Commit dba06d8

Browse files
committed
Fix ordering for AttachRequest as well
1 parent c9086d2 commit dba06d8

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "1.89.0"
2+
channel = "1.95.0"
33
components = ["rustfmt", "rust-std", "clippy"]

src/wrap.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,8 +844,6 @@ impl Wrappable for AttachRequest {
844844
warn!("unable to set process limits");
845845
}
846846

847-
apply_capabilities(self.capabilities.as_ref())?;
848-
849847
// Ensure the process receives the desired out-of-memory score adjustment.
850848
if let Some(score) = self.exec.oom_score_adj {
851849
fs::write("/proc/self/oom_score_adj", score.to_string())?;
@@ -854,11 +852,18 @@ impl Wrappable for AttachRequest {
854852
debug!("all namespaces joined -- forking child");
855853
fork_and_wait()?;
856854

855+
// Mirror CreateRequest ordering: SECBIT_NO_SETUID_FIXUP first so a UID
856+
// change from 0 to non-zero doesn't clear the permitted/effective cap
857+
// sets, then change UID/GID, then apply caps as the final step before
858+
// exec. Applying caps before the UID change would silently drop any
859+
// raised caps for non-root targets.
860+
set_keep_caps()?;
857861
apply_gid_uid(
858862
self.exec.gid,
859863
self.exec.uid,
860864
self.exec.supplemental_gids.as_ref(),
861865
)?;
866+
apply_capabilities(self.capabilities.as_ref())?;
862867

863868
self.exec.execute()
864869
}

0 commit comments

Comments
 (0)