aboutsummaryrefslogtreecommitdiff
path: root/kernel/features/fs.c
diff options
context:
space:
mode:
authorMarvin Borner2021-02-07 14:23:32 +0100
committerMarvin Borner2021-02-07 14:23:32 +0100
commiteca4dfd49216f6158df69143994a18a0b3edd4fe (patch)
tree831e2ffe1724d4761d734fe753df0d0ea6958dd2 /kernel/features/fs.c
parent03b8f1d1976e0f74c80556315105734354fc06fc (diff)
Added filesystem and proc permissions
Diffstat (limited to 'kernel/features/fs.c')
-rw-r--r--kernel/features/fs.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/kernel/features/fs.c b/kernel/features/fs.c
index b59eb03..ecb2b85 100644
--- a/kernel/features/fs.c
+++ b/kernel/features/fs.c
@@ -130,12 +130,15 @@ s32 vfs_read(const char *path, void *buf, u32 offset, u32 count)
path++;
struct mount_info *m = vfs_find_mount_info(path);
- assert(m && m->dev && m->dev->vfs && m->dev->vfs->read);
+ assert(m && m->dev && m->dev->vfs && m->dev->vfs->read && m->dev->vfs->perm);
u32 len = strlen(m->path);
if (len > 1)
path += len;
+ if (!m->dev->vfs->perm(path, VFS_READ, m->dev) && !proc_super())
+ return -1;
+
return m->dev->vfs->read(path, buf, offset, count, m->dev);
}
@@ -151,12 +154,15 @@ s32 vfs_write(const char *path, void *buf, u32 offset, u32 count)
path++;
struct mount_info *m = vfs_find_mount_info(path);
- assert(m && m->dev && m->dev->vfs && m->dev->vfs->write);
+ assert(m && m->dev && m->dev->vfs && m->dev->vfs->write && m->dev->vfs->perm);
u32 len = strlen(m->path);
if (len > 1)
path += len;
+ if (!m->dev->vfs->perm(path, VFS_WRITE, m->dev) && !proc_super())
+ return -1;
+
return m->dev->vfs->write(path, buf, offset, count, m->dev);
}
@@ -237,6 +243,14 @@ s32 devfs_read(const char *path, void *buf, u32 offset, u32 count, struct device
return target->read(buf, offset, count, dev);
}
+u8 devfs_perm(const char *path, enum vfs_perm perm, struct device *dev)
+{
+ (void)path;
+ (void)perm;
+ (void)dev;
+ return 1;
+}
+
u8 devfs_ready(const char *path, struct device *dev)
{
(void)dev;
@@ -307,7 +321,7 @@ struct ext2_inode *get_inode(u32 i, struct device *dev)
(struct ext2_inode *)((u32)buf +
(index % (BLOCK_SIZE / EXT2_INODE_SIZE)) * EXT2_INODE_SIZE);
- free(buf);
+ free(buf); // TODO: Fix use after free with *in
free(s);
free(b - block_group);
@@ -466,6 +480,22 @@ s32 ext2_stat(const char *path, struct stat *buf, struct device *dev)
return 0;
}
+u8 ext2_perm(const char *path, enum vfs_perm perm, struct device *dev)
+{
+ struct ext2_inode *in = find_inode_by_path(path, dev);
+
+ switch (perm) {
+ case VFS_EXEC:
+ return (in->mode & EXT2_PERM_UEXEC) != 0;
+ case VFS_WRITE:
+ return (in->mode & EXT2_PERM_UWRITE) != 0;
+ case VFS_READ:
+ return (in->mode & EXT2_PERM_UREAD) != 0;
+ default:
+ return 0;
+ }
+}
+
u8 ext2_ready(const char *path, struct device *dev)
{
(void)path;