-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Closed
Labels
A-processArea: `std::process` and `std::env`Area: `std::process` and `std::env`C-bugCategory: This is a bug.Category: This is a bug.O-linuxOperating system: LinuxOperating system: LinuxO-unixOperating system: Unix-likeOperating system: Unix-likeT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Description
Commit 22ddcd1 made libstd drops ancillary groups when uid == 0:
rust/library/std/src/sys/unix/process/process_unix.rs
Lines 312 to 314 in 385f8e2
if libc::getuid() == 0 && self.get_groups().is_none() { | |
cvt(libc::setgroups(0, ptr::null()))?; | |
} |
Before that it unconditionally dropped group membership.
The new logic is wrong on Linux: it doesn't account for processes whose uid != 0 but have the CAP_SETGID capability.
Such processes can and should drop ancillary groups, otherwise child processes inherit permissions they otherwise wouldn't have.
Suggested change:
if self.get_groups().is_none() {
let _ = libc::setgroups(0, ptr::null()); // or return unless EPERM
}
Metadata
Metadata
Assignees
Labels
A-processArea: `std::process` and `std::env`Area: `std::process` and `std::env`C-bugCategory: This is a bug.Category: This is a bug.O-linuxOperating system: LinuxOperating system: LinuxO-unixOperating system: Unix-likeOperating system: Unix-likeT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.