mmap: check file permissions before allowing it to be mapped

This commit is contained in:
Matheus
2024-08-25 11:58:09 -03:00
parent 02f5c15e35
commit 12dd3dc089
+9
View File
@@ -68,6 +68,14 @@ syscallret_t syscall_mmap(context_t *context, void *hint, size_t len, int prot,
return ret;
}
int type = file->vnode->type;
if ((type != V_TYPE_REGULAR && type != V_TYPE_BLKDEV && type != V_TYPE_CHDEV)
|| ((prot & PROT_READ) && (file->flags & FILE_READ) == 0)
|| ((flags & MAP_SHARED) && (prot & PROT_WRITE) && (file->flags & FILE_WRITE) == 0)) {
ret.errno = EACCES;
goto cleanup;
}
vfd.node = file->vnode;
vfd.offset = offset;
}
@@ -79,6 +87,7 @@ syscallret_t syscall_mmap(context_t *context, void *hint, size_t len, int prot,
if (ret.ret == 0)
ret.errno = ENOMEM;
cleanup:
if (isfile)
fd_release(file);