git: 7b18863d597e - main - mac syscalls: add kern_ implementations
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 07 Nov 2026 12:11:00 UTC
The branch main has been updated by brooks:
URL: https://cgit.FreeBSD.org/src/commit/?id=7b18863d597e0dad0734cf6e06c5e7689be2047c
commit 7b18863d597e0dad0734cf6e06c5e7689be2047c
Author: Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2026-11-07 12:10:45 +0000
Commit: Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2026-11-07 12:10:45 +0000
mac syscalls: add kern_ implementations
Where the kern_ interfaces map trivially to the syscall interface, follow
the syscall name even if awkward (e.g., sys___mac* -> kern___mac*).
Otherwise use shorter names.
Effort: CHERI upstreaming
Sponsored by: DARPA, AFRL
Pull Request: https://github.com/freebsd/freebsd-src/pull/2284
---
sys/security/mac/mac_syscalls.c | 88 ++++++++++++++++++++++++++---------------
sys/sys/syscallsubr.h | 11 ++++++
2 files changed, 68 insertions(+), 31 deletions(-)
diff --git a/sys/security/mac/mac_syscalls.c b/sys/security/mac/mac_syscalls.c
index 9bafa6d30c36..5a5d4b1b7161 100644
--- a/sys/security/mac/mac_syscalls.c
+++ b/sys/security/mac/mac_syscalls.c
@@ -58,6 +58,7 @@
#include <sys/mac.h>
#include <sys/proc.h>
#include <sys/systm.h>
+#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
#include <sys/sysent.h>
#include <sys/sysproto.h>
@@ -78,11 +79,6 @@
FEATURE(security_mac, "Mandatory Access Control Framework support");
-static int kern___mac_get_path(struct thread *td, const char *path_p,
- struct mac *mac_p, int follow);
-static int kern___mac_set_path(struct thread *td, const char *path_p,
- struct mac *mac_p, int follow);
-
#ifdef COMPAT_FREEBSD32
struct mac32 {
uint32_t m_buflen; /* size_t */
@@ -161,6 +157,12 @@ free_copied_label(const struct mac *const mac)
int
sys___mac_get_pid(struct thread *td, struct __mac_get_pid_args *uap)
+{
+ return (kern___mac_get_pid(td, uap->pid, uap->mac_p));
+}
+
+int
+kern___mac_get_pid(struct thread *td, pid_t pid, void *mac_p)
{
char *buffer, *u_buffer;
struct mac mac;
@@ -168,11 +170,11 @@ sys___mac_get_pid(struct thread *td, struct __mac_get_pid_args *uap)
struct ucred *tcred;
int error;
- error = mac_label_copyin(uap->mac_p, &mac, &u_buffer);
+ error = mac_label_copyin(mac_p, &mac, &u_buffer);
if (error)
return (error);
- tproc = pfind(uap->pid);
+ tproc = pfind(pid);
if (tproc == NULL) {
error = ESRCH;
goto free_mac_and_exit;
@@ -201,12 +203,18 @@ free_mac_and_exit:
int
sys___mac_get_proc(struct thread *td, struct __mac_get_proc_args *uap)
+{
+ return (kern___mac_get_proc(td, uap->mac_p));
+}
+
+int
+kern___mac_get_proc(struct thread *td, void *mac_p)
{
char *buffer, *u_buffer;
struct mac mac;
int error;
- error = mac_label_copyin(uap->mac_p, &mac, &u_buffer);
+ error = mac_label_copyin(mac_p, &mac, &u_buffer);
if (error)
return (error);
@@ -454,6 +462,12 @@ mac_set_prison_finish(struct thread *const td, bool prison_label_set __unused,
int
sys___mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
+{
+ return (kern___mac_set_proc(td, uap->mac_p));
+}
+
+int
+kern___mac_set_proc(struct thread *td, void *mac_p)
{
struct ucred *newcred, *oldcred;
void *intlabel;
@@ -461,7 +475,7 @@ sys___mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap)
struct mac mac;
int error;
- error = mac_label_copyin(uap->mac_p, &mac, NULL);
+ error = mac_label_copyin(mac_p, &mac, NULL);
if (error)
return (error);
@@ -496,6 +510,12 @@ free_label:
int
sys___mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
+{
+ return (kern___mac_get_fd(td, uap->fd, uap->mac_p));
+}
+
+int
+kern___mac_get_fd(struct thread *td, int fd, void *mac_p)
{
char *u_buffer, *buffer;
struct label *intlabel;
@@ -508,13 +528,12 @@ sys___mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap)
cap_rights_t rights;
int error;
- error = mac_label_copyin(uap->mac_p, &mac, &u_buffer);
+ error = mac_label_copyin(mac_p, &mac, &u_buffer);
if (error)
return (error);
buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO);
- error = fget(td, uap->fd, cap_rights_init_one(&rights, CAP_MAC_GET),
- &fp);
+ error = fget(td, fd, cap_rights_init_one(&rights, CAP_MAC_GET), &fp);
if (error)
goto out;
@@ -600,19 +619,17 @@ out:
int
sys___mac_get_file(struct thread *td, struct __mac_get_file_args *uap)
{
-
- return (kern___mac_get_path(td, uap->path_p, uap->mac_p, FOLLOW));
+ return (kern_mac_get_path(td, uap->path_p, uap->mac_p, FOLLOW));
}
int
sys___mac_get_link(struct thread *td, struct __mac_get_link_args *uap)
{
-
- return (kern___mac_get_path(td, uap->path_p, uap->mac_p, NOFOLLOW));
+ return (kern_mac_get_path(td, uap->path_p, uap->mac_p, NOFOLLOW));
}
-static int
-kern___mac_get_path(struct thread *td, const char *path_p, struct mac *mac_p,
+int
+kern_mac_get_path(struct thread *td, const char *path_p, struct mac *mac_p,
int follow)
{
char *u_buffer, *buffer;
@@ -654,6 +671,12 @@ out:
int
sys___mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
+{
+ return (kern___mac_set_fd(td, uap->fd, uap->mac_p));
+}
+
+int
+kern___mac_set_fd(struct thread *td, int fd, void *mac_p)
{
struct label *intlabel;
struct pipe *pipe;
@@ -666,11 +689,11 @@ sys___mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
cap_rights_t rights;
int error;
- error = mac_label_copyin(uap->mac_p, &mac, NULL);
+ error = mac_label_copyin(mac_p, &mac, NULL);
if (error)
return (error);
- error = fget(td, uap->fd, cap_rights_init_one(&rights, CAP_MAC_SET),
+ error = fget(td, fd, cap_rights_init_one(&rights, CAP_MAC_SET),
&fp);
if (error)
goto out;
@@ -767,19 +790,17 @@ out:
int
sys___mac_set_file(struct thread *td, struct __mac_set_file_args *uap)
{
-
- return (kern___mac_set_path(td, uap->path_p, uap->mac_p, FOLLOW));
+ return (kern_mac_set_path(td, uap->path_p, uap->mac_p, FOLLOW));
}
int
sys___mac_set_link(struct thread *td, struct __mac_set_link_args *uap)
{
-
- return (kern___mac_set_path(td, uap->path_p, uap->mac_p, NOFOLLOW));
+ return (kern_mac_set_path(td, uap->path_p, uap->mac_p, NOFOLLOW));
}
-static int
-kern___mac_set_path(struct thread *td, const char *path_p, struct mac *mac_p,
+int
+kern_mac_set_path(struct thread *td, const char *path_p, struct mac *mac_p,
int follow)
{
struct label *intlabel;
@@ -820,12 +841,18 @@ out:
int
sys_mac_syscall(struct thread *td, struct mac_syscall_args *uap)
+{
+ return (kern_mac_syscall(td, uap->policy, uap->call, uap->arg));
+}
+
+int
+kern_mac_syscall(struct thread *td, const char *policy, int call, void *arg)
{
struct mac_policy_conf *mpc;
char target[MAC_MAX_POLICY_NAME];
int error;
- error = copyinstr(uap->policy, target, sizeof(target), NULL);
+ error = copyinstr(policy, target, sizeof(target), NULL);
if (error)
return (error);
@@ -833,8 +860,7 @@ sys_mac_syscall(struct thread *td, struct mac_syscall_args *uap)
LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) {
if (strcmp(mpc->mpc_name, target) == 0 &&
mpc->mpc_ops->mpo_syscall != NULL) {
- error = mpc->mpc_ops->mpo_syscall(td,
- uap->call, uap->arg);
+ error = mpc->mpc_ops->mpo_syscall(td, call, arg);
goto out;
}
}
@@ -844,8 +870,8 @@ sys_mac_syscall(struct thread *td, struct mac_syscall_args *uap)
LIST_FOREACH(mpc, &mac_policy_list, mpc_list) {
if (strcmp(mpc->mpc_name, target) == 0 &&
mpc->mpc_ops->mpo_syscall != NULL) {
- error = mpc->mpc_ops->mpo_syscall(td,
- uap->call, uap->arg);
+ error = mpc->mpc_ops->mpo_syscall(td, call,
+ arg);
break;
}
}
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index a9cf1ef4390d..1abd99438bce 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -108,6 +108,11 @@ typedef int (updateiov_t)(const struct uio *uiop, void *iovp);
uint64_t at2cnpflags(u_int at_flags, u_int mask);
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);
+int kern___mac_get_pid(struct thread *td, pid_t pid, void *mac_p);
+int kern___mac_get_proc(struct thread *td, void *mac_p);
+int kern___mac_set_fd(struct thread *td, int fd, void *mac_p);
+int kern___mac_set_proc(struct thread *td, void *mac_p);
int kern_abort2(struct thread *td, const char *why, int nargs,
void **uargs);
int kern_accept(struct thread *td, int s, struct sockaddr *sa,
@@ -275,6 +280,12 @@ int kern_listen(struct thread *td, int s, int backlog);
int kern_lseek(struct thread *td, int fd, off_t offset, int whence);
int kern_lutimes(struct thread *td, const char *path, enum uio_seg pathseg,
const struct timeval *tptr, enum uio_seg tptrseg);
+int kern_mac_get_path(struct thread *td, const char *path_p,
+ struct mac *mac_p, int follow);
+int kern_mac_set_path(struct thread *td, const char *path_p,
+ struct mac *mac_p, int follow);
+int kern_mac_syscall(struct thread *td, const char *policy, int call,
+ void *arg);
int kern_madvise(struct thread *td, uintptr_t addr, size_t len, int behav);
int kern_membarrier(struct thread *td, int cmd, unsigned flags,
int cpu_id);