Description
When --userspec is provided without --groups, the code clears all supplementary groups instead of initializing them from the target user's actual group memberships:
// main.go:265-271
} else {
if err := syscall.Setgroups([]int{}); err != nil {
fmt.Fprintf(os.Stderr, "chroot: cannot set groups: %v\n", err)
logWarn("Failed to clear groups: %v", err)
os.Exit(1)
}
logInfo("Cleared supplementary groups")
}
Standard tools like chroot/su typically call the equivalent of initgroups() in this situation — looking up which groups the target user belongs to in /etc/group and applying that list. Here, the user silently loses all supplementary group memberships instead.
Impact
A process running as the target uid inside the chroot may unexpectedly lose access to files/resources that rely on group membership (e.g. group-readable/writable files), because none of the user's normal secondary groups are applied — and there's no indication to the operator that this happened beyond a debug-level log line.
Steps to reproduce
- Have a user in
/etc/passwd//etc/group (inside the new root) who is a member of one or more supplementary groups.
- Run
./warproot --userspec=<user> /path/to/root without --groups.
- Inside the chroot, check
id — supplementary groups are empty instead of matching /etc/group.
Expected behavior
When --groups is not specified, supplementary groups should be initialized from the target user's memberships in /etc/group (an initgroups()-style lookup), matching the behavior of standard chroot/su implementations — or, if clearing groups by default is an intentional security choice, this should be clearly documented in --help and the README.
Description
When
--userspecis provided without--groups, the code clears all supplementary groups instead of initializing them from the target user's actual group memberships:Standard tools like
chroot/sutypically call the equivalent ofinitgroups()in this situation — looking up which groups the target user belongs to in/etc/groupand applying that list. Here, the user silently loses all supplementary group memberships instead.Impact
A process running as the target uid inside the chroot may unexpectedly lose access to files/resources that rely on group membership (e.g. group-readable/writable files), because none of the user's normal secondary groups are applied — and there's no indication to the operator that this happened beyond a debug-level log line.
Steps to reproduce
/etc/passwd//etc/group(inside the new root) who is a member of one or more supplementary groups../warproot --userspec=<user> /path/to/rootwithout--groups.id— supplementary groups are empty instead of matching/etc/group.Expected behavior
When
--groupsis not specified, supplementary groups should be initialized from the target user's memberships in/etc/group(aninitgroups()-style lookup), matching the behavior of standardchroot/suimplementations — or, if clearing groups by default is an intentional security choice, this should be clearly documented in--helpand the README.