diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-09-14 21:30:11 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-09-14 21:30:11 +0300 |
| commit | cabbf335824db0df835e4c541c19d3803ce38454 (patch) | |
| tree | e7397d2b6637545b8e18f26135e3ad2a0a2fbe1e /common/uapi | |
| parent | 025778e89e7d0fe3cd1ad53537c9cc6f3cd819cc (diff) | |
| download | kmi-cabbf335824db0df835e4c541c19d3803ce38454.tar.gz kmi-cabbf335824db0df835e4c541c19d3803ce38454.zip | |
add canary to kernel stack
Diffstat (limited to 'common/uapi')
| -rw-r--r-- | common/uapi/dispatch.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/common/uapi/dispatch.c b/common/uapi/dispatch.c index c2ddbcf..73e037a 100644 --- a/common/uapi/dispatch.c +++ b/common/uapi/dispatch.c @@ -6,6 +6,7 @@ * Syscall dispatch. */ +#include <apos/canary.h> #include <apos/debug.h> #include <apos/uapi.h> @@ -57,11 +58,23 @@ SYSCALL_DEFINE0(noop)(){ struct sys_ret syscall_dispatch(sys_arg_t syscall, sys_arg_t a, sys_arg_t b, sys_arg_t c, sys_arg_t d) { - /** \todo Add check that syscall is not larger than table */ - sys_t call = syscall_table[syscall]; + struct tcb *t = cur_tcb(); - if (!call) + size_t sc = syscall; + if (sc >= ARRAY_SIZE(syscall_table)) { + error("Syscall %zu outside allowed range [0 - %zu]\n", sc, + ARRAY_SIZE(syscall_table)); return (struct sys_ret){ ERR_INVAL, 0 }; + } - return call(a, b, c, d); + /* the syscall must be a valid number, as they're numbered in a linear + * fashion */ + struct sys_ret r = syscall_table[syscall](a, b, c, d); + + if (check_canary(t)) { + bug("Syscall %zu overwrote stack canary\n", syscall); + return (struct sys_ret){ ERR_INT, 0 }; + } + + return r; } |
