From 7e828ec1e1479ff9a8afe845539d08ca0dfada5f Mon Sep 17 00:00:00 2001 From: Kimplul Date: Mon, 8 Jul 2024 17:38:59 +0300 Subject: add orphan checking to timer and irq handling --- src/uapi/irq.c | 2 +- src/uapi/proc.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'src/uapi') diff --git a/src/uapi/irq.c b/src/uapi/irq.c index 29da614..9f3931c 100644 --- a/src/uapi/irq.c +++ b/src/uapi/irq.c @@ -22,7 +22,7 @@ SYSCALL_DEFINE1(irq_req)(struct tcb *t, sys_arg_t id) if (!has_cap(t->caps, CAP_IRQ)) return_args1(t, ERR_PERM); - if (!t->callback) + if (!t->callback || !t->notify_id) return_args1(t, ERR_NF); return_args1(t, register_irq(t, id)); diff --git a/src/uapi/proc.c b/src/uapi/proc.c index 293a01f..eddbab8 100644 --- a/src/uapi/proc.c +++ b/src/uapi/proc.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -127,7 +128,18 @@ SYSCALL_DEFINE2(exec)(struct tcb *t, sys_arg_t bin, sys_arg_t interp) if (interp) clear_bit(b->flags, MR_KEEP); - return_args1(t, prepare_proc(t, bin, interp)); + /* should hopefully never actually fail, but if it does, we don't really + * have any choice but to kill the thread. */ + if (prepare_proc(t, bin, interp)) { + /* this kills the thread */ + orphanize(t); + unorphanize(t); + /* should never be reached as we control the thread so we should + * be able to directly jump to pid 1 */ + assert(false); + } + + return_args4(t, 0, t->tid, SYS_USER_SPAWNED, t->pid); } /** -- cgit v1.3