kern: fix freebsd14 getgroups(2) compat

We need to actually copyout the remainder of the groups if the egid
succeeded, not failed.  My test that was designed to catch this along
with the previously-found syzkaller panic did not zero out the groups
array prior to re-fetching, so it did not catch that entries beyond the
first were not actually populated.

Pointy hat:	kevans
Fixes:	9da2fe96ff ("kern: fix setgroups(2) and getgroups(2) [...]")
This commit is contained in:
Kyle Evans
2025-08-15 10:08:18 -05:00
parent e7a766f9d0
commit 08f5e06c5e
+1 -1
View File
@@ -332,7 +332,7 @@ freebsd14_getgroups(struct thread *td, struct freebsd14_getgroups_args *uap)
}
error = copyout(&cred->cr_gid, uap->gidset, sizeof(gid_t));
if (error != 0)
if (error == 0)
error = copyout(cred->cr_groups, uap->gidset + 1,
(ngrp - 1) * sizeof(gid_t));