summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-07-09 01:07:03 -0400
committerIan Moffett <ian@osmora.org>2025-07-09 01:07:39 -0400
commit524b56b5e28875b48613b812be92476573bb8325 (patch)
tree6064c42485aabc5e5400ab0218fd30dc736eb4bc
parentee2e8661148b7e9fe1413a714fdf8779f867afc0 (diff)
kernel: cred: Introduce SYS_setuid syscall
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--sys/include/sys/syscall.h1
-rw-r--r--sys/include/sys/ucred.h5
-rw-r--r--sys/kern/kern_cred.c11
-rw-r--r--sys/kern/kern_syscall.c4
4 files changed, 20 insertions, 1 deletions
diff --git a/sys/include/sys/syscall.h b/sys/include/sys/syscall.h
index 3650e7a..05288f4 100644
--- a/sys/include/sys/syscall.h
+++ b/sys/include/sys/syscall.h
@@ -56,6 +56,7 @@
#define SYS_inject 15
#define SYS_getpid 16
#define SYS_getppid 17
+#define SYS_setuid 18
#if defined(_KERNEL)
/* Syscall return value and arg type */
diff --git a/sys/include/sys/ucred.h b/sys/include/sys/ucred.h
index ef66a18..b44a7fe 100644
--- a/sys/include/sys/ucred.h
+++ b/sys/include/sys/ucred.h
@@ -33,6 +33,7 @@
#include <sys/types.h>
#if defined(_KERNEL)
#include <sys/spinlock.h>
+#include <sys/syscall.h>
#endif
/*
@@ -47,4 +48,8 @@ struct ucred {
};
int setuid(uid_t new);
+
+#if defined(_KERNEL)
+scret_t sys_setuid(struct syscall_args *scargs);
+#endif
#endif /* !_SYS_UCRED_H_ */
diff --git a/sys/kern/kern_cred.c b/sys/kern/kern_cred.c
index 828ba3b..e1202fc 100644
--- a/sys/kern/kern_cred.c
+++ b/sys/kern/kern_cred.c
@@ -55,3 +55,14 @@ setuid(uid_t new)
spinlock_release(&cur_cred->lock);
return 0;
}
+
+/*
+ * setuid() syscall
+ *
+ * arg0: `new'
+ */
+scret_t
+sys_setuid(struct syscall_args *scargs)
+{
+ return setuid(scargs->arg0);
+}
diff --git a/sys/kern/kern_syscall.c b/sys/kern/kern_syscall.c
index 739dd7f..276c7c7 100644
--- a/sys/kern/kern_syscall.c
+++ b/sys/kern/kern_syscall.c
@@ -31,6 +31,7 @@
#include <sys/sysctl.h>
#include <sys/reboot.h>
#include <sys/types.h>
+#include <sys/ucred.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/proc.h>
@@ -55,7 +56,8 @@ scret_t(*g_sctab[])(struct syscall_args *) = {
sys_sleep, /* SYS_sleep */
sys_inject, /* SYS_inject */
sys_getpid, /* SYS_getpid */
- sys_getppid /* SYS_getppid */
+ sys_getppid, /* SYS_getppid */
+ sys_setuid, /* SYS_setuid */
};
const size_t MAX_SYSCALLS = NELEM(g_sctab);