Skip to content

Conversation

@andycandy-dev
Copy link

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() and setuid() without calling initgroups() to set supplementary groups. Additionally, it incorrectly assumed UID equals GID, passing the UID value to setgid().

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:

  • Look up the User structure to get the actual GID (instead of assuming UID = GID)
  • Call initgroups() with the username to set supplementary groups
  • Use the correct GID for setgid() instead of the UID
  • Maintain proper privilege dropping order: initgroupssetgidsetuid
  • Apply the same fix to perms.rs module for consistency

Related

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.

@andycandy-dev andycandy-dev changed the title Fix permission groups #320 Fix permission groups Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Linux groups are not set correctly after new security model

1 participant