From 9f012538e238ed29804165f095d0a5d45da81818 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sun, 28 Sep 2025 23:34:17 -0400 Subject: kern: compat: Use copyin() in SYS_write Signed-off-by: Ian Moffett --- src/sys/compat/unix/os/os_filedesc.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/sys/compat') 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 +#include #include +#include #include #include @@ -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); } -- cgit v1.2.3