The vulnerability (CVE-2025-5791 / GHSA-m65q-v92h-cm7q) in the users crate (versions >= 0.8.0, <= 0.11.0) stems from improper handling of fixed-size buffers when interfacing with libc functions (getgroups and getgrouplist) to retrieve group information.
The root cause is consistent across two key functions: users::base::group_access_list (which provides the group access list of the current process) and users::base::get_user_groups (which provides the supplementary groups of a user and is called by users::User::groups).
In both functions:
- A buffer of 1024 elements (
gid_t or i32 on macOS) is allocated and initialized with 0. The GID 0 typically corresponds to the root group.
- A libc function (
getgroups or getgrouplist) is called to fill this buffer with actual group IDs. These functions also indicate how many group IDs were actually written.
- The Rust code then fails to limit its processing to only the portion of the buffer that was filled with valid data. Instead, it iterates over the entire 1024-element buffer (or a version of it modified by
dedup that still includes extraneous zeros if the buffer wasn't full).
- Consequently, if the actual number of groups is less than 1024, the remaining zero-initialized elements in the buffer are treated as valid GIDs. These
0s are then resolved to the root group, causing root to be incorrectly appended to the resulting group list.
This behavior leads to privilege escalation if an application relies on the accuracy of these group lists for access control decisions, as it might incorrectly grant root privileges. The vulnerability does not manifest if the correct group listing happens to be exactly 1024 groups, as the buffer would be completely filled with legitimate data in that specific scenario.
The crate is unmaintained, and no patched version is available. Downgrading to versions older than 0.8.0 or using alternative crates like uzers or sysinfo are the recommended workarounds.