From nobody Wed Nov 11 09:58:15 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jPf943gpsz6yxyh for ; Wed, 11 Nov 2026 09:58:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jPf9411Ltz4kqj for ; Wed, 11 Nov 2026 09:58:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794391096; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=X7rWEbegbX0PeT7QxZ5undt9kgsq0G1+AvOvdY1rqFk=; b=AtgP6A6cgIFUlA+yeNoImD9lfz97/VYU5mMPxHux+36rVnoxsWCDm+dP7axU0OGC8kr3xN y9jG3GZB1cKrmhl0rvtflqnqODegLc+M0GFPysCiu7AF64SpPZHajyhT1XbVnp9XmlckCM +wE4PrG+x6uoBog5DtoaL0dN0SkOs4ZTOJ8ubNCwN2izoDInsnBBV8O+dv4q05qy6TG1ay 6vvlFlUW4J8k2V0gHn1mJio4ZWzGz+xq20jZK7o8Du+5Fv4NFjFZEF2OFnkE8+KBgvU9nm lHxFejX/wlCF1RhOqB5hwCzT6smzEF8/RL7P1mfeJ4iHWFFIoS0G0fnkgL3eog== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794391096; b=awyASEZkn9QcA9DF+RbGqmrIl2l0lu8YQFNxJJC/uw4OSGeHGzMrv1Rex9STGqR5xxXhjv /v2T7gy7BEuumRA+Y8AVfuvK1Av36hdUaZ2d6l8rWjSPzCL6cDvYPTxWfZ57xIjEkzShPf o4lm95d4qar5wJXXLbVb/JM/RCEiMFsGoKB71MgPcLrbgdAJe1lEGbVL2eSLdxM8ecK/0E 8a6v9SA8ddppYiQCZ+f1upOB+gQ+/j49QH0B9r68qw9mB1871NkSTNi9t/2DzSLfDjxccD HquP8p9Qb4gBzRicovEQNGw/cNU/GhzcyUtmRhPLNYJ5Hkwecs+FFg/LXmThAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794391096; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=X7rWEbegbX0PeT7QxZ5undt9kgsq0G1+AvOvdY1rqFk=; b=EpfXJYQaemqNC/uJyGQHKyRRcQ62Ob5mSRIGDNN2fD+DDy7rnURn/Oe2YbdZbMdrkoNDSt ShhT5xbjnPwzVOzhOkpbNC230hMaPMzoD/UT+ygw1TjeUlC3Rd4t2xNLFKEBUrS7zM611a NCEHzrQKLeDpyJYL6r5Qovv42w1FTI0KvLdifDiEJozYReZyZ9d6RcK1o43Z1XjQp5QW9U rFnVlhB1eWcpCgI0YjRhMzi9yHXTEic2Rv4TfEsWq2lB2caHIawvukBBzT00WLHbUaDPps TOlkYEhMO0HDCIegQOHopvcBchK+xzOC3JGZRhz+LGcZQtbMHAJFjgZv/mWb3g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jPf936jLQz186n for ; Wed, 11 Nov 2026 09:58:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 10373 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 11 Nov 2026 09:58:15 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Brooks Davis Subject: git: 974320334844 - main - sys_capability.c: add kern_ and user_ implementations List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: brooks X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 974320334844517558365608615dc6f3cc86cdae Auto-Submitted: auto-generated Date: Wed, 11 Nov 2026 09:58:15 +0000 Message-Id: <6af43c37.10373.78dc0e2@gitrepo.freebsd.org> The branch main has been updated by brooks: URL: https://cgit.FreeBSD.org/src/commit/?id=974320334844517558365608615dc6f3cc86cdae commit 974320334844517558365608615dc6f3cc86cdae Author: Brooks Davis AuthorDate: 2026-11-11 09:40:41 +0000 Commit: Brooks Davis CommitDate: 2026-11-11 09:40:41 +0000 sys_capability.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/sys_capability.c | 82 +++++++++++++++++++++++++++++++---------------- sys/sys/syscallsubr.h | 9 ++++++ 2 files changed, 63 insertions(+), 28 deletions(-) diff --git a/sys/kern/sys_capability.c b/sys/kern/sys_capability.c index e7187b7904ee..3b25ac16eb2c 100644 --- a/sys/kern/sys_capability.c +++ b/sys/kern/sys_capability.c @@ -138,11 +138,17 @@ out1: */ int sys_cap_getmode(struct thread *td, struct cap_getmode_args *uap) +{ + return (kern_cap_getmode(td, uap->modep)); +} + +int +kern_cap_getmode(struct thread *td, u_int *modep) { u_int i; i = IN_CAPABILITY_MODE(td) ? 1 : 0; - return (copyout(&i, uap->modep, sizeof(i))); + return (copyout(&i, modep, sizeof(i))); } #else /* !CAPABILITY_MODE */ @@ -281,20 +287,26 @@ kern_cap_rights_limit(struct thread *td, int fd, cap_rights_t *rights) */ int sys_cap_rights_limit(struct thread *td, struct cap_rights_limit_args *uap) +{ + return (user_cap_rights_limit(td, uap->fd, uap->rightsp)); +} + +int +user_cap_rights_limit(struct thread *td, int fd, cap_rights_t *rightsp) { cap_rights_t rights; int error, version; cap_rights_init_zero(&rights); - error = copyin(uap->rightsp, &rights, sizeof(rights.cr_rights[0])); + error = copyin(rightsp, &rights, sizeof(rights.cr_rights[0])); if (error != 0) return (error); version = CAPVER(&rights); if (version != CAP_RIGHTS_VERSION_00) return (EINVAL); - error = copyin(uap->rightsp, &rights, + error = copyin(rightsp, &rights, sizeof(rights.cr_rights[0]) * CAPARSIZE(&rights)); if (error != 0) return (error); @@ -314,9 +326,9 @@ sys_cap_rights_limit(struct thread *td, struct cap_rights_limit_args *uap) ktrcaprights(&rights); #endif - AUDIT_ARG_FD(uap->fd); + AUDIT_ARG_FD(fd); AUDIT_ARG_RIGHTS(&rights); - return (kern_cap_rights_limit(td, uap->fd, &rights)); + return (kern_cap_rights_limit(td, fd, &rights)); } /* @@ -324,16 +336,21 @@ sys_cap_rights_limit(struct thread *td, struct cap_rights_limit_args *uap) */ int sys___cap_rights_get(struct thread *td, struct __cap_rights_get_args *uap) +{ + return (kern___cap_rights_get(td, uap->version, uap->fd, uap->rightsp)); +} + +int +kern___cap_rights_get(struct thread *td, int version, int fd, + cap_rights_t *rightsp) { struct filedesc *fdp; cap_rights_t rights; - int error, fd, i, n; + int error, i, n; - if (uap->version != CAP_RIGHTS_VERSION_00) + if (version != CAP_RIGHTS_VERSION_00) return (EINVAL); - fd = uap->fd; - AUDIT_ARG_FD(fd); fdp = td->td_proc->p_fd; @@ -344,8 +361,8 @@ sys___cap_rights_get(struct thread *td, struct __cap_rights_get_args *uap) } rights = *cap_rights(fdp, fd); FILEDESC_SUNLOCK(fdp); - n = uap->version + 2; - if (uap->version != CAPVER(&rights)) { + n = version + 2; + if (version != CAPVER(&rights)) { /* * For older versions we need to check if the descriptor * doesn't contain rights not understood by the caller. @@ -356,7 +373,7 @@ sys___cap_rights_get(struct thread *td, struct __cap_rights_get_args *uap) return (EINVAL); } } - error = copyout(&rights, uap->rightsp, sizeof(rights.cr_rights[0]) * n); + error = copyout(&rights, rightsp, sizeof(rights.cr_rights[0]) * n); #ifdef KTRACE if (error == 0 && KTRPOINT(td, KTR_STRUCT)) ktrcaprights(&rights); @@ -473,13 +490,17 @@ out_free: int sys_cap_ioctls_limit(struct thread *td, struct cap_ioctls_limit_args *uap) +{ + return (user_cap_ioctls_limit(td, uap->fd, uap->cmds, uap->ncmds)); +} + +int +user_cap_ioctls_limit(struct thread *td, int fd, const u_long *ucmds, + size_t ncmds) { u_long *cmds; - size_t ncmds; int error; - ncmds = uap->ncmds; - if (ncmds > IOCTLS_MAX_COUNT) return (EINVAL); @@ -487,29 +508,31 @@ sys_cap_ioctls_limit(struct thread *td, struct cap_ioctls_limit_args *uap) cmds = NULL; } else { cmds = malloc(sizeof(cmds[0]) * ncmds, M_FILECAPS, M_WAITOK); - error = copyin(uap->cmds, cmds, sizeof(cmds[0]) * ncmds); + error = copyin(ucmds, cmds, sizeof(cmds[0]) * ncmds); if (error != 0) { free(cmds, M_FILECAPS); return (error); } } - return (kern_cap_ioctls_limit(td, uap->fd, cmds, ncmds)); + return (kern_cap_ioctls_limit(td, fd, cmds, ncmds)); } int sys_cap_ioctls_get(struct thread *td, struct cap_ioctls_get_args *uap) +{ + return (kern_cap_ioctls_get(td, uap->fd, uap->cmds, uap->maxcmds)); +} + +int +kern_cap_ioctls_get(struct thread *td, int fd, u_long *dstcmds, size_t maxcmds) { struct filedesc *fdp; struct filedescent *fdep; - u_long *cmdsp, *dstcmds; - size_t maxcmds, ncmds; + u_long *cmdsp; + size_t ncmds; int16_t count; - int error, fd; - - fd = uap->fd; - dstcmds = uap->cmds; - maxcmds = uap->maxcmds; + int error; AUDIT_ARG_FD(fd); @@ -627,13 +650,16 @@ sys_cap_fcntls_limit(struct thread *td, struct cap_fcntls_limit_args *uap) int sys_cap_fcntls_get(struct thread *td, struct cap_fcntls_get_args *uap) +{ + return (kern_cap_fcntls_get(td, uap->fd, uap->fcntlrightsp)); +} + +int +kern_cap_fcntls_get(struct thread *td, int fd, uint32_t *fcntlrightsp) { struct filedesc *fdp; struct filedescent *fdep; uint32_t rights; - int fd; - - fd = uap->fd; AUDIT_ARG_FD(fd); @@ -647,7 +673,7 @@ sys_cap_fcntls_get(struct thread *td, struct cap_fcntls_get_args *uap) rights = fdep->fde_fcntls; FILEDESC_SUNLOCK(fdp); - return (copyout(&rights, uap->fcntlrightsp, sizeof(rights))); + return (copyout(&rights, fcntlrightsp, sizeof(rights))); } #else /* !CAPABILITIES */ diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h index 7dbba4b28b95..37093ffb7bd4 100644 --- a/sys/sys/syscallsubr.h +++ b/sys/sys/syscallsubr.h @@ -120,6 +120,8 @@ typedef int (copyinuio_t)(const void *iovp, unsigned int iovcnt, typedef int (updateiov_t)(const struct uio *uiop, void *iovp); uint64_t at2cnpflags(u_int at_flags, u_int mask); +int kern___cap_rights_get(struct thread *td, int version, int fd, + cap_rights_t *rightsp); int kern___getcwd(struct thread *td, char *buf, enum uio_seg bufseg, size_t buflen, size_t path_max); int kern___mac_get_fd(struct thread *td, int fd, void *mac_p); @@ -143,6 +145,10 @@ int kern_auditctl(struct thread *td, const char *path); int kern_auditon(struct thread *td, int cmd, void *data, u_int length); int kern_bindat(struct thread *td, int dirfd, int fd, struct sockaddr *sa); int kern_break(struct thread *td, uintptr_t *addr); +int kern_cap_fcntls_get(struct thread *td, int fd, uint32_t *fcntlrightsp); +int kern_cap_getmode(struct thread *td, u_int *modep); +int kern_cap_ioctls_get(struct thread *td, int fd, u_long *dstcmds, + size_t maxcmds); int kern_cap_ioctls_limit(struct thread *td, int fd, u_long *cmds, size_t ncmds); int kern_cap_rights_limit(struct thread *td, int fd, cap_rights_t *rights); @@ -533,6 +539,9 @@ int kern_socketpair(struct thread *td, int domain, int type, int protocol, int *rsv); int kern_unmount(struct thread *td, const char *path, uint64_t flags); +int user_cap_ioctls_limit(struct thread *td, int fd, const u_long *ucmds, + size_t ncmds); +int user_cap_rights_limit(struct thread *td, int fd, cap_rights_t *rightsp); int user_clock_nanosleep(struct thread *td, clockid_t clock_id, int flags, const struct timespec *ua_rqtp, struct timespec *ua_rmtp);