git: 91e5dbdc4da6 - main - kern_prot.c: add kern_ and user_ implementations
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 10 Nov 2026 12:33:02 UTC
The branch main has been updated by brooks:
URL: https://cgit.FreeBSD.org/src/commit/?id=91e5dbdc4da68a1a1001efb47ccbc2257ad106ee
commit 91e5dbdc4da68a1a1001efb47ccbc2257ad106ee
Author: Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2026-11-10 11:49:21 +0000
Commit: Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2026-11-10 11:49:21 +0000
kern_prot.c: add kern_ and user_ implementations
Effort: CHERI upstreaming
Sponsored by: Innovate UK
Pull Request: https://github.com/freebsd/freebsd-src/pull/2284
---
sys/kern/kern_prot.c | 89 ++++++++++++++++++++++++++++++++++-----------------
sys/sys/syscallsubr.h | 8 +++++
2 files changed, 67 insertions(+), 30 deletions(-)
diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c
index 005131b1561f..58fef9769fca 100644
--- a/sys/kern/kern_prot.c
+++ b/sys/kern/kern_prot.c
@@ -355,6 +355,12 @@ struct getgroups_args {
#endif
int
sys_getgroups(struct thread *td, struct getgroups_args *uap)
+{
+ return (kern_getgroups(td, uap->gidsetsize, uap->gidset));
+}
+
+int
+kern_getgroups(struct thread *td, int gidsetsize, gid_t *gidset)
{
struct ucred *cred;
int ngrp, error;
@@ -362,14 +368,14 @@ sys_getgroups(struct thread *td, struct getgroups_args *uap)
cred = td->td_ucred;
ngrp = cred->cr_ngroups;
- if (uap->gidsetsize == 0) {
+ if (gidsetsize == 0) {
error = 0;
goto out;
}
- if (uap->gidsetsize < ngrp)
+ if (gidsetsize < ngrp)
return (EINVAL);
- error = copyout(cred->cr_groups, uap->gidset, ngrp * sizeof(gid_t));
+ error = copyout(cred->cr_groups, gidset, ngrp * sizeof(gid_t));
out:
td->td_retval[0] = ngrp;
return (error);
@@ -1249,10 +1255,16 @@ struct setgroups_args {
/* ARGSUSED */
int
sys_setgroups(struct thread *td, struct setgroups_args *uap)
+{
+ return (user_setgroups(td, uap->gidsetsize, uap->gidset));
+}
+
+int
+user_setgroups(struct thread *td, int gidsetsize, const gid_t *gidset)
{
gid_t smallgroups[CRED_SMALLGROUPS_NB];
gid_t *groups;
- int gidsetsize, error;
+ int error;
/*
* Sanity check size now to avoid passing too big a value to copyin(),
@@ -1263,7 +1275,6 @@ sys_setgroups(struct thread *td, struct setgroups_args *uap)
* getgroups() to take an 'int' and it would be quite entrapping to have
* setgroups() differ.
*/
- gidsetsize = uap->gidsetsize;
if (gidsetsize > ngroups_max || gidsetsize < 0)
return (EINVAL);
@@ -1272,7 +1283,7 @@ sys_setgroups(struct thread *td, struct 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, false);
@@ -1691,20 +1702,23 @@ struct getresuid_args {
/* ARGSUSED */
int
sys_getresuid(struct thread *td, struct getresuid_args *uap)
+{
+ return (kern_getresuid(td, uap->ruid, uap->euid, uap->suid));
+}
+
+int
+kern_getresuid(struct thread *td, uid_t *ruid, uid_t *euid, uid_t *suid)
{
struct ucred *cred;
int error1 = 0, error2 = 0, error3 = 0;
cred = td->td_ucred;
- if (uap->ruid)
- error1 = copyout(&cred->cr_ruid,
- uap->ruid, sizeof(cred->cr_ruid));
- if (uap->euid)
- error2 = copyout(&cred->cr_uid,
- uap->euid, sizeof(cred->cr_uid));
- if (uap->suid)
- error3 = copyout(&cred->cr_svuid,
- uap->suid, sizeof(cred->cr_svuid));
+ if (ruid)
+ error1 = copyout(&cred->cr_ruid, ruid, sizeof(cred->cr_ruid));
+ if (euid)
+ error2 = copyout(&cred->cr_uid, euid, sizeof(cred->cr_uid));
+ if (suid)
+ error3 = copyout(&cred->cr_svuid, suid, sizeof(cred->cr_svuid));
return (error1 ? error1 : error2 ? error2 : error3);
}
@@ -1718,20 +1732,23 @@ struct getresgid_args {
/* ARGSUSED */
int
sys_getresgid(struct thread *td, struct getresgid_args *uap)
+{
+ return (kern_getresgid(td, uap->rgid, uap->egid, uap->sgid));
+}
+
+int
+kern_getresgid(struct thread *td, gid_t *rgid, gid_t *egid, gid_t *sgid)
{
struct ucred *cred;
int error1 = 0, error2 = 0, error3 = 0;
cred = td->td_ucred;
- if (uap->rgid)
- error1 = copyout(&cred->cr_rgid,
- uap->rgid, sizeof(cred->cr_rgid));
- if (uap->egid)
- error2 = copyout(&cred->cr_gid,
- uap->egid, sizeof(cred->cr_gid));
- if (uap->sgid)
- error3 = copyout(&cred->cr_svgid,
- uap->sgid, sizeof(cred->cr_svgid));
+ if (rgid)
+ error1 = copyout(&cred->cr_rgid, rgid, sizeof(cred->cr_rgid));
+ if (egid)
+ error2 = copyout(&cred->cr_gid, egid, sizeof(cred->cr_gid));
+ if (sgid)
+ error3 = copyout(&cred->cr_svgid, sgid, sizeof(cred->cr_svgid));
return (error1 ? error1 : error2 ? error2 : error3);
}
@@ -3118,21 +3135,27 @@ struct getlogin_args {
/* ARGSUSED */
int
sys_getlogin(struct thread *td, struct getlogin_args *uap)
+{
+ return (kern_getlogin(td, uap->namebuf, uap->namelen));
+}
+
+int
+kern_getlogin(struct thread *td, char *namebuf, u_int namelen)
{
char login[MAXLOGNAME];
struct proc *p = td->td_proc;
size_t len;
- if (uap->namelen > MAXLOGNAME)
- uap->namelen = MAXLOGNAME;
+ if (namelen > MAXLOGNAME)
+ namelen = MAXLOGNAME;
PROC_LOCK(p);
SESS_LOCK(p->p_session);
- len = strlcpy(login, p->p_session->s_login, uap->namelen) + 1;
+ len = strlcpy(login, p->p_session->s_login, namelen) + 1;
SESS_UNLOCK(p->p_session);
PROC_UNLOCK(p);
- if (len > uap->namelen)
+ if (len > namelen)
return (ERANGE);
- return (copyout(login, uap->namebuf, len));
+ return (copyout(login, namebuf, len));
}
/*
@@ -3146,6 +3169,12 @@ struct setlogin_args {
/* ARGSUSED */
int
sys_setlogin(struct thread *td, struct setlogin_args *uap)
+{
+ return (kern_setlogin(td, uap->namebuf));
+}
+
+int
+kern_setlogin(struct thread *td, const char *namebuf)
{
struct proc *p = td->td_proc;
int error;
@@ -3156,7 +3185,7 @@ sys_setlogin(struct thread *td, struct setlogin_args *uap)
error = priv_check(td, PRIV_PROC_SETLOGIN);
if (error)
return (error);
- error = copyinstr(uap->namebuf, logintmp, sizeof(logintmp), NULL);
+ error = copyinstr(namebuf, logintmp, sizeof(logintmp), NULL);
if (error != 0) {
if (error == ENAMETOOLONG)
error = EINVAL;
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index d8252c3becbd..fec04660b541 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -254,11 +254,17 @@ int kern_getfhat(struct thread *td, int flags, int fd, const char *path,
enum uio_seg pathseg, fhandle_t *fhp, enum uio_seg fhseg);
int kern_getfsstat(struct thread *td, struct statfs **buf, size_t bufsize,
size_t *countp, enum uio_seg bufseg, int mode);
+int kern_getgroups(struct thread *td, int gidsetsize, gid_t *gidset);
int kern_getitimer(struct thread *, u_int, struct itimerval *);
+int kern_getlogin(struct thread *td, char *namebuf, u_int namelen);
int kern_getloginclass(struct thread *td, char *namebuf, size_t namelen);
int kern_getppid(struct thread *);
int kern_getpeername(struct thread *td, int fd, struct sockaddr *sa);
int kern_getpriority(struct thread *td, int which, int who);
+int kern_getresgid(struct thread *td, gid_t *rgid, gid_t *egid,
+ gid_t *sgid);
+int kern_getresuid(struct thread *td, uid_t *ruid, uid_t *euid,
+ uid_t *suid);
int kern_getrusage(struct thread *td, int who, struct rusage *rup);
int kern_getsid(struct thread *td, pid_t pid);
int kern_getsockname(struct thread *td, int fd, struct sockaddr *sa);
@@ -425,6 +431,7 @@ int kern_setgroups(struct thread *td, int *ngrpp, gid_t *groups,
bool includes_egid);
int kern_setitimer(struct thread *, u_int, struct itimerval *,
struct itimerval *);
+int kern_setlogin(struct thread *td, const char *namebuf);
int kern_setloginclass(struct thread *td, const char *namebuf);
int kern_setpriority(struct thread *td, int which, int who, int prio);
int kern_setrlimit(struct thread *, u_int, struct rlimit *);
@@ -513,6 +520,7 @@ int user_jail_get(struct thread *td, struct iovec *iovp,
int user_jail_set(struct thread *td, struct iovec *iovp,
unsigned int iovcnt, int flags, copyinuio_t *copyinuio_f);
int user_kldload(struct thread *td, const char *file);
+int user_setgroups(struct thread *td, int gidsetsize, const gid_t *gidset);
int user_wait6(struct thread *td, enum idtype idtype, id_t id,
int *statusp, int options, struct __wrusage *wrusage,
siginfo_t *sip);