Repository navigation
posixsubprocess: call libc setgroups directly in the child - #8609
Merged
Merged
Conversation
`setgroups_if_needed` was compiled out on macOS, so `extra_groups` was accepted and then silently ignored there. nix gates `unistd::setgroups` off `apple_targets`, `redox` and `haiku`; calling `libc::setgroups` and checking the return with `nix::Error::result` is the shape the adjacent `setregid_if_needed` and `setreuid_if_needed` already use, and libc declares the function everywhere except redox. `u32` and `libc::gid_t` have the same layout, so the caller's slice is passed as-is instead of being collected into a fresh `Vec` after fork and before exec. `ngroups` is `c_int` on the BSDs and `size_t` on linux, hence `as _`. Assisted-by: Claude
Contributor
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
ChangesPOSIX group setup
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
youknowone
marked this pull request as ready for review
August 30, 2026 01:52
youknowone
added a commit
that referenced
this pull request
Sep 16, 2026
`setgroups_if_needed` was compiled out on macOS, so `extra_groups` was accepted and then silently ignored there. nix gates `unistd::setgroups` off `apple_targets`, `redox` and `haiku`; calling `libc::setgroups` and checking the return with `nix::Error::result` is the shape the adjacent `setregid_if_needed` and `setreuid_if_needed` already use, and libc declares the function everywhere except redox. `u32` and `libc::gid_t` have the same layout, so the caller's slice is passed as-is instead of being collected into a fresh `Vec` after fork and before exec. `ngroups` is `c_int` on the BSDs and `size_t` on linux, hence `as _`. Assisted-by: Claude
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
setgroups_if_neededcarriedtarget_os = "macos"in itscfg(not(any(...))), so on macOS theextra_groupsargument was accepted by_posixsubprocess.fork_execand then silently dropped — the child ran with the parent's group list.nix gates
unistd::setgroupsoffapple_targets,redoxandhaiku, which is where that exclusion came from.libcdeclaressetgroupson every one of those except redox, so this calls it directly and checks the return withnix::Error::result— the same shape the adjacentsetregid_if_neededandsetreuid_if_neededalready use.ngroupsisc_inton the BSDs andsize_ton linux, henceas _.Passing the caller's
&[u32]straight through also drops an allocation:u32andlibc::gid_thave the same layout, so noVec<Gid>needs to be built. That code runs in the child betweenforkandexec, wheremallocis not async-signal-safe.Draft: not yet exercised against
test_subprocess'sextra_groupscases on macOS, and iOS is still excluded.— commented by Claude
Summary by CodeRabbit