From f5b5210cd6c6f62f012c9fd894f5e2a2bb328cb0 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 26 Apr 2024 14:37:22 -0400 Subject: kernel: filedesc: Acquire mutex in read() Signed-off-by: Ian Moffett --- sys/kern/kern_filedesc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sys/kern/kern_filedesc.c b/sys/kern/kern_filedesc.c index f7ca2c8..203eefc 100644 --- a/sys/kern/kern_filedesc.c +++ b/sys/kern/kern_filedesc.c @@ -331,19 +331,24 @@ read(int fd, void *buf, size_t count) return -EBADF; } + mutex_acquire(&fd_desc->lock); if (fd_desc->oflag == O_WRONLY) { - return -EACCES; + bytes_read = -EACCES; + goto done; } sio.offset = fd_desc->offset; vnode = fd_desc->vnode; if (count > MAX_RW_SIZE) { - return -EINVAL; + bytes_read = -EACCES; + goto done; } bytes_read = vfs_read(vnode, &sio); fd_desc->offset += bytes_read; +done: + mutex_release(&fd_desc->lock); return bytes_read; } -- cgit v1.2.3