aboutsummaryrefslogtreecommitdiff
path: root/kernel/drivers/fb.c
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/fb.c
parent68a0ad7f21ba07b93cd63613996e27afd8780f9c (diff)
Hardened syscalls
Diffstat (limited to 'kernel/drivers/fb.c')
-rw-r--r--kernel/drivers/fb.c21
1 files changed, 16 insertions, 5 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;
}