diff options
author | dzwdz | 2022-08-12 00:30:14 +0200 |
---|---|---|
committer | dzwdz | 2022-08-12 00:30:14 +0200 |
commit | 215aa95c8d8c85985c1dcc5a994ad164823b39e6 (patch) | |
tree | a8346262dea6d5d32b552c8ccf407256d370e086 /src/kernel | |
parent | d170ceb6c9f26f222558012ccbb75614ec2a6b8f (diff) |
vfs: OPEN_RO flag, read-only whitelist entries
Diffstat (limited to 'src/kernel')
-rw-r--r-- | src/kernel/handle.h | 1 | ||||
-rw-r--r-- | src/kernel/syscalls.c | 5 | ||||
-rw-r--r-- | src/kernel/vfs/request.c | 8 |
3 files changed, 11 insertions, 3 deletions
diff --git a/src/kernel/handle.h b/src/kernel/handle.h index 233c2fa..54ef412 100644 --- a/src/kernel/handle.h +++ b/src/kernel/handle.h @@ -17,6 +17,7 @@ struct handle { enum handle_type type; struct vfs_backend *backend; // HANDLE_FILE | HANDLE_FS_FRONT void __user *file_id; // only applicable to HANDLE_FILE + bool ro; /* currently only for HANDLE_FILE */ struct { struct process *queued; bool write_end; diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index 7bc018d..68c0241 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -88,6 +88,8 @@ handle_t _syscall_open(const char __user *path, long len, int flags) { struct vfs_mount *mount; char *path_buf = NULL; + if (flags & ~(OPEN_CREATE | OPEN_RO)) SYSCALL_RETURN(-ENOSYS); + if (PATH_MAX < len) SYSCALL_RETURN(-1); if (process_find_free_handle(process_current, 0) < 0) @@ -210,6 +212,8 @@ static long simple_vfsop( struct handle *h = process_handle_get(process_current, hid); if (!h) SYSCALL_RETURN(-1); if (h->type == HANDLE_FILE) { + if (h->ro && !(vfsop == VFSOP_READ || vfsop == VFSOP_GETSIZE)) + SYSCALL_RETURN(-EACCES); struct vfs_request req = (struct vfs_request){ .type = vfsop, .backend = h->backend, @@ -257,6 +261,7 @@ long _syscall_remove(handle_t hid) { struct handle **hslot = &process_current->handles[hid]; struct handle *h = *hslot; if (!h) SYSCALL_RETURN(-1); + if (h->ro) SYSCALL_RETURN(-EACCES); if (h->type == HANDLE_FILE) { vfsreq_create((struct vfs_request) { .type = VFSOP_REMOVE, diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c index 82f4731..f4db0db 100644 --- a/src/kernel/vfs/request.c +++ b/src/kernel/vfs/request.c @@ -1,5 +1,5 @@ #include <camellia/errno.h> -#include <kernel/arch/amd64/driver/fsroot.h> +#include <camellia/flags.h> #include <kernel/mem/alloc.h> #include <kernel/mem/virt.h> #include <kernel/panic.h> @@ -19,9 +19,10 @@ void vfsreq_create(struct vfs_request req_) { req = kmalloc(sizeof *req); } memcpy(req, &req_, sizeof *req); + if (req->backend) req->backend->refcount++; - if (req->backend) - req->backend->refcount++; + if (req->type == VFSOP_OPEN && (req->flags & OPEN_RO)) + req->flags &= ~OPEN_CREATE; if (req->backend && req->backend->potential_handlers) { struct vfs_request **iter = &req->backend->queue; @@ -51,6 +52,7 @@ void vfsreq_finish(struct vfs_request *req, char __user *stored, long ret, backing->backend = req->backend; req->backend->refcount++; backing->file_id = stored; + backing->ro = req->flags & OPEN_RO; req->caller->handles[handle] = backing; } else { /* delegating - moving a handle to the caller */ |