git: d60162816083 - main - freebsd14_[gs]groups: add kern_ and user_ implementations

From: Brooks Davis <brooks_at_FreeBSD.org>
Date: Thu, 12 Nov 2026 11:01:56 UTC
The branch main has been updated by brooks:

URL: https://cgit.FreeBSD.org/src/commit/?id=d60162816083c0dc54c1c6655bceb5f0257e40a7

commit d60162816083c0dc54c1c6655bceb5f0257e40a7
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2026-11-12 11:01:30 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2026-11-12 11:01:30 +0000

    freebsd14_[gs]groups: add kern_ and user_ implementations
    
    Effort:         CHERI upstreaming
    Sponsored by:   DARPA, AFRL
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/2284
---
 sys/kern/kern_prot.c  | 27 ++++++++++++++++++++-------
 sys/sys/syscallsubr.h |  4 ++++
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c
index 58fef9769fca..8f4dc4f5ebdf 100644
--- a/sys/kern/kern_prot.c
+++ b/sys/kern/kern_prot.c
@@ -317,6 +317,12 @@ sys_getegid(struct thread *td, struct getegid_args *uap)
 #ifdef COMPAT_FREEBSD14
 int
 freebsd14_getgroups(struct thread *td, struct freebsd14_getgroups_args *uap)
+{
+	return (kern_freebsd14_getgroups(td, uap->gidsetsize, uap->gidset));
+}
+
+int
+kern_freebsd14_getgroups(struct thread *td, int gidsetsize, gid_t *gidset)
 {
 	struct ucred *cred;
 	int ngrp, error;
@@ -328,16 +334,16 @@ freebsd14_getgroups(struct thread *td, struct freebsd14_getgroups_args *uap)
 	 * beginning of the group list prior to all supplementary groups.
 	 */
 	ngrp = cred->cr_ngroups + 1;
-	if (uap->gidsetsize == 0) {
+	if (gidsetsize == 0) {
 		error = 0;
 		goto out;
-	} else if (uap->gidsetsize < ngrp) {
+	} else if (gidsetsize < ngrp) {
 		return (EINVAL);
 	}
 
-	error = copyout(&cred->cr_gid, uap->gidset, sizeof(gid_t));
+	error = copyout(&cred->cr_gid, gidset, sizeof(gid_t));
 	if (error == 0)
-		error = copyout(cred->cr_groups, uap->gidset + 1,
+		error = copyout(cred->cr_groups, gidset + 1,
 		    (ngrp - 1) * sizeof(gid_t));
 
 out:
@@ -1218,16 +1224,23 @@ fail:
 #ifdef COMPAT_FREEBSD14
 int
 freebsd14_setgroups(struct thread *td, struct freebsd14_setgroups_args *uap)
+{
+	return (user_freebsd14_setgroups(td, uap->gidsetsize,
+	    uap->gidset));
+}
+
+int
+user_freebsd14_setgroups(struct thread *td, int gidsetsize,
+    const gid_t *gidset)
 {
 	gid_t smallgroups[CRED_SMALLGROUPS_NB];
 	gid_t *groups;
-	int gidsetsize, error;
+	int error;
 
 	/*
 	 * Before FreeBSD 15.0, we allow one more group to be supplied to
 	 * account for the egid appearing before the supplementary groups.
 	 */
-	gidsetsize = uap->gidsetsize;
 	if (gidsetsize > ngroups_max + 1 || gidsetsize < 0)
 		return (EINVAL);
 
@@ -1236,7 +1249,7 @@ freebsd14_setgroups(struct thread *td, struct freebsd14_setgroups_args *uap)
 	else
 		groups = smallgroups;
 
-	error = copyin(uap->gidset, groups, gidsetsize * sizeof(gid_t));
+	error = copyin(gidset, groups, gidsetsize * sizeof(gid_t));
 	if (error == 0)
 		error = kern_setgroups(td, &gidsetsize, groups, true);
 
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index f098ee5ed750..c65836b9104c 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -265,6 +265,8 @@ int	kern_filewrite(struct thread *td, int fd, struct file *fp,
 int	kern_fpathconf(struct thread *td, int fd, int name, long *valuep);
 int	kern_freebsd11_getfsstat(struct thread *td,
 	    struct freebsd11_statfs *ubuf, long bufsize, int mode);
+int	kern_freebsd14_getgroups(struct thread *td, int gidsetsize,
+	    gid_t *gidset);
 int	kern_frmdirat(struct thread *td, int dfd, const char *path, int fd,
 	    enum uio_seg pathseg, int flag);
 int	kern_fstat(struct thread *td, int fd, struct stat *sbp);
@@ -631,6 +633,8 @@ int	user_fhstat(struct thread *td, const struct fhandle *u_fhp,
 	    struct stat *usb);
 int	user_fhstatfs(struct thread *td, const struct fhandle *u_fhp,
 	    struct statfs *buf);
+int	user_freebsd14_setgroups(struct thread *td, int gidsetsize,
+	    const gid_t *gidset);
 int	user_fspacectl(struct thread *td, int fd, int cmd,
 	    const struct spacectl_range *rqsrp, int flags,
 	    struct spacectl_range *rmsrp);