kinfo_proc: Restore outputting the effective GID

In particular, fixes 'procstat -s' on a live system or a core file (only
if there are less than 16 groups).

Reviewed by:    kib
Fixes:          be1f7435ef ("kern: start tracking cr_gid outside of cr_groups[]")
MFC after:      9 days
Sponsored by:   The FreeBSD Foundation
Differential Revision:  https://reviews.freebsd.org/D52259
This commit is contained in:
Olivier Certner 2025-08-26 15:53:06 +02:00
parent 5568b4441d
commit 63a40ca813
No known key found for this signature in database
GPG key ID: 8CA13040971E2627

View file

@ -1112,13 +1112,14 @@ fill_kinfo_proc_only(struct proc *p, struct kinfo_proc *kp)
if (cred->cr_flags & CRED_FLAG_CAPMODE)
kp->ki_cr_flags |= KI_CRF_CAPABILITY_MODE;
/* XXX bde doesn't like KI_NGROUPS */
if (cred->cr_ngroups > KI_NGROUPS) {
if (1 + cred->cr_ngroups > KI_NGROUPS) {
kp->ki_ngroups = KI_NGROUPS;
kp->ki_cr_flags |= KI_CRF_GRP_OVERFLOW;
} else
kp->ki_ngroups = cred->cr_ngroups;
bcopy(cred->cr_groups, kp->ki_groups,
kp->ki_ngroups * sizeof(gid_t));
kp->ki_ngroups = 1 + cred->cr_ngroups;
kp->ki_groups[0] = cred->cr_gid;
bcopy(cred->cr_groups, kp->ki_groups + 1,
(kp->ki_ngroups - 1) * sizeof(gid_t));
kp->ki_rgid = cred->cr_rgid;
kp->ki_svgid = cred->cr_svgid;
/* If jailed(cred), emulate the old P_JAILED flag. */