Fix permission groups #325
Open
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.
Problem
Terminal emulators and other applications launched via swhkd were missing supplementary groups, causing permission issues. This occurred when the user's GID differs from their UID (e.g., on NixOS and some enterprise Linux distributions).
The root cause was that the code only called
setgid()andsetuid()without callinginitgroups()to set supplementary groups. Additionally, it incorrectly assumed UID equals GID, passing the UID value tosetgid().Solution
This PR adds proper
initgroups()calls before dropping privileges when spawning command execution threads. The fix ensures processes launched via swhkd have all the groups the user belongs to, not just their primary group.Changes:
initgroups()with the username to set supplementary groupssetgid()instead of the UIDinitgroups→setgid→setuidperms.rsmodule for consistencyRelated
This follows the same approach used in commit 6b1e62e to fix CVE-2022-27814 and CVE-2022-27819, but applies it to command execution rather than just config file loading.
fixes #320
Testing
Tested on systems where UID ≠ GID (nixOs). Verified that spawned processes now have all supplementary groups correctly set.