[Zion] Validate that started threads are in user space.

This commit is contained in:
Drew Galbraith 2023-11-02 22:23:32 -07:00
parent f8f839d8e7
commit c63a54d6b1
1 changed files with 11 additions and 1 deletions

View File

@ -4,6 +4,12 @@
#include "debug/debug.h"
#include "scheduler/scheduler.h"
namespace {
bool IsKernel(uint64_t addr) { return (addr & 0xFFFF'FF80'0000'0000); }
} // namespace
glcr::ErrorCode ThreadCreate(ZThreadCreateReq* req) {
auto& curr_proc = gScheduler->CurrentProcess();
auto cap = curr_proc.GetCapability(req->proc_cap);
@ -21,7 +27,11 @@ glcr::ErrorCode ThreadStart(ZThreadStartReq* req) {
RET_ERR(ValidateCapability<Thread>(cap, kZionPerm_Write));
auto thread = cap->obj<Thread>();
// FIXME: validate entry point is in user space.
if (IsKernel(req->entry) || IsKernel(req->arg1) || IsKernel(req->arg2)) {
return glcr::INVALID_ARGUMENT;
}
thread->Start(req->entry, req->arg1, req->arg2);
return glcr::OK;
}