summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-09-28 23:34:17 -0400
committerIan Moffett <ian@osmora.org>2025-09-28 23:34:17 -0400
commit9f012538e238ed29804165f095d0a5d45da81818 (patch)
tree3bce69ac62255539a785a546a918139641ffa1d6
parent409887cb9675215048faa3196c24b5e566a07125 (diff)
kern: compat: Use copyin() in SYS_write
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--src/sys/compat/unix/os/os_filedesc.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/sys/compat/unix/os/os_filedesc.c b/src/sys/compat/unix/os/os_filedesc.c
index f36bd02..86bb62b 100644
--- a/src/sys/compat/unix/os/os_filedesc.c
+++ b/src/sys/compat/unix/os/os_filedesc.c
@@ -28,7 +28,9 @@
*/
#include <sys/syscall.h>
+#include <sys/errno.h>
#include <sys/types.h>
+#include <os/systm.h>
#include <os/filedesc.h>
#include <compat/unix/syscall.h>
@@ -45,8 +47,16 @@ scret_t
sys_write(struct syscall_args *scargs)
{
int fd = SCARG(scargs, int, 0);
+ int error;
const void *buf = SCARG(scargs, const void *, 1);
size_t count = SCARG(scargs, size_t, 2);
+ char kbuf[1024];
- return write(fd, buf, count);
+ error = copyin(buf, kbuf, MIN(count, sizeof(kbuf)));
+ if (error < 0) {
+ printf("sys_write: copyin() bad pointer\n");
+ return -EFAULT;
+ }
+
+ return write(fd, kbuf, count);
}