Skip to content

Commit 75d2080

Browse files
authored
Set groups when dropping privileges to not leak supplementary group access (#1202)
Changing the real and effective user/group IDs and the saved set-user/group-ID is not enough to get rid of intial access permissions. The list of groups must be cleared also, otherwise a process changing from, e.g. `root:root` to `nobody:nobody` retains rights to access `:wheel` files (assuming `root` is a member of the `wheel` group). For example: ``` # id uid=0(root) gid=0(wheel) groups=0(wheel), 2(kmem), 3(sys), 4(tty), 5(operator), 20(staff), 31(guest) # ./yggdrasil -autoconf -logto /dev/null -user nobody & [1] 4337 # ps -o command,user,group,supgrp -U nobody COMMAND USER GROUP SUPGRP ./yggdrasil -aut nobody nobody wheel,kmem,sys,tty,operator,staff,guest ``` Fix that so the process runs as mere ``` COMMAND USER GROUP SUPGRP ./yggdrasil -aut nobody nobody nobody ``` Fixes #927.
1 parent 8346800 commit 75d2080

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

cmd/yggdrasil/chuser_unix.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func chuser(user string) error {
5353
gid, _ := strconv.ParseUint(g.Gid, 10, 32)
5454
var err error
5555
if gid < math.MaxInt {
56+
if err := syscall.Setgroups([]int{int(gid)}); err != nil {
57+
return fmt.Errorf("failed to setgroups %d: %v", gid, err)
58+
}
5659
err = syscall.Setgid(int(gid))
5760
} else {
5861
err = errors.New("gid too big")
@@ -63,6 +66,9 @@ func chuser(user string) error {
6366
}
6467
} else if u != nil {
6568
gid, _ := strconv.ParseUint(u.Gid, 10, 32)
69+
if err := syscall.Setgroups([]int{int(uint32(gid))}); err != nil {
70+
return fmt.Errorf("failed to setgroups %d: %v", gid, err)
71+
}
6672
err := syscall.Setgid(int(uint32(gid)))
6773
if err != nil {
6874
return fmt.Errorf("failed to setgid %d: %v", gid, err)

0 commit comments

Comments
 (0)