aboutsummaryrefslogtreecommitdiff
path: root/kernel/drivers
diff options
context:
space:
mode:
authorMarvin Borner2021-03-21 12:40:41 +0100
committerMarvin Borner2021-03-21 12:46:08 +0100
commit09c3bdb186868204cb03d457244e05e12eb685d6 (patch)
tree7bf59794173d700df08ad303acd6c5a49193a9eb /kernel/drivers
parent68a0ad7f21ba07b93cd63613996e27afd8780f9c (diff)
Hardened syscalls
Diffstat (limited to 'kernel/drivers')
-rw-r--r--kernel/drivers/fb.c21
-rw-r--r--kernel/drivers/ide.c2
-rw-r--r--kernel/drivers/keyboard.c4
-rw-r--r--kernel/drivers/mouse.c4
4 files changed, 21 insertions, 10 deletions
diff --git a/kernel/drivers/fb.c b/kernel/drivers/fb.c
index 2db05f2..0a9494a 100644
--- a/kernel/drivers/fb.c
+++ b/kernel/drivers/fb.c
@@ -2,6 +2,7 @@
#include <assert.h>
#include <def.h>
+#include <errno.h>
#include <fb.h>
#include <fs.h>
#include <ioctl.h>
@@ -23,7 +24,8 @@ struct vbe_basic {
static u32 dev_id = 0;
static struct vid_info *info = NULL;
-static s32 fb_ioctl(u32 request, void *arg1, void *arg2, void *arg3, struct device *dev)
+static u32 fb_owner = 0;
+static res fb_ioctl(u32 request, void *arg1, void *arg2, void *arg3, struct device *dev)
{
UNUSED(arg2);
UNUSED(arg3);
@@ -32,17 +34,26 @@ static s32 fb_ioctl(u32 request, void *arg1, void *arg2, void *arg3, struct devi
switch (request) {
case IO_FB_GET: {
if (!info)
- return -1;
+ return -ENOENT;
+
+ if (!arg1 || !memory_valid(arg1))
+ return -EFAULT;
+
+ if (fb_owner != 0 && proc_from_pid(fb_owner))
+ return -EBUSY;
+ else
+ fb_owner = proc_current()->pid;
+
memcpy(arg1, info->vbe, sizeof(struct vbe_basic));
fb_map_buffer(proc_current()->page_dir, info);
- return 0;
+ return EOK;
}
default:
- return -1;
+ return -EINVAL;
}
}
-static s32 fb_ready(void)
+static res fb_ready(void)
{
return 1;
}
diff --git a/kernel/drivers/ide.c b/kernel/drivers/ide.c
index 2d02f94..7146eb2 100644
--- a/kernel/drivers/ide.c
+++ b/kernel/drivers/ide.c
@@ -106,7 +106,7 @@ static u8 ata_read_one(u8 *buf, u32 lba, struct device *dev)
return 1;
}
-static s32 ata_read(void *buf, u32 lba, u32 sector_count, struct device *dev)
+static res ata_read(void *buf, u32 lba, u32 sector_count, struct device *dev)
{
u8 *b = buf; // I love bytes, yk
for (u32 i = 0; i < sector_count; i++) {
diff --git a/kernel/drivers/keyboard.c b/kernel/drivers/keyboard.c
index 79cd579..b123bcc 100644
--- a/kernel/drivers/keyboard.c
+++ b/kernel/drivers/keyboard.c
@@ -61,7 +61,7 @@ static void keyboard_rate(void)
outb(0x60, 0x0); // Rate{00000} Delay{00} 0
}*/
-static s32 keyboard_read(void *buf, u32 offset, u32 count, struct device *dev)
+static res keyboard_read(void *buf, u32 offset, u32 count, struct device *dev)
{
UNUSED(dev);
if (stack_empty(queue))
@@ -73,7 +73,7 @@ static s32 keyboard_read(void *buf, u32 offset, u32 count, struct device *dev)
return MIN(count, sizeof(*e));
}
-static s32 keyboard_ready(void)
+static res keyboard_ready(void)
{
return !stack_empty(queue);
}
diff --git a/kernel/drivers/mouse.c b/kernel/drivers/mouse.c
index 8545099..ad36cc4 100644
--- a/kernel/drivers/mouse.c
+++ b/kernel/drivers/mouse.c
@@ -84,12 +84,12 @@ static u8 mouse_serial_read(void)
return inb(0x60);
}
-static s32 mouse_ready(void)
+static res mouse_ready(void)
{
return !stack_empty(queue);
}
-static s32 mouse_read(void *buf, u32 offset, u32 count, struct device *dev)
+static res mouse_read(void *buf, u32 offset, u32 count, struct device *dev)
{
(void)dev;
if (stack_empty(queue))