Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sched: fix null pointer access in user space stack #20

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/platform/x86_64/sched/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,17 @@ int platformSetContext(Thread *t, uintptr_t entry, uintptr_t highest, const char
while(base % PAGE_SIZE) {
base++;
}
uintptr_t limit = base + PAGE_SIZE + PLATFORM_THREAD_STACK;
size_t pages = (PLATFORM_THREAD_STACK+PAGE_SIZE-1)/PAGE_SIZE;
pages++;

uintptr_t stack = vmmAllocate(base, limit, pages, VMM_WRITE | VMM_USER);
uintptr_t stack = vmmAllocate(base, USER_LIMIT_ADDRESS, pages, VMM_WRITE | VMM_USER);
if(!stack) return -1;
memset((void *)stack, 0, PLATFORM_THREAD_STACK + PAGE_SIZE);

stack += PLATFORM_THREAD_STACK;
ctx->regs.rsp = stack;

t->highest = stack; // requisite to sbrk() someday
t->highest = stack + PAGE_SIZE; // requisite to sbrk() someday
return 0;
}

Expand Down
11 changes: 10 additions & 1 deletion src/sched/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,16 @@ pid_t execveMemory(const void *ptr, const char **argv, const char **envp) {
uint64_t highest;
uint64_t entry = loadELF(ptr, &highest);

platformSetContext(process->threads[0], entry, highest, argv, envp);
if(platformSetContext(process->threads[0], entry, highest, argv, envp)) {
threadUseContext(getTid());
free(process->threads[0]->context);
free(process->threads[0]);
free(process->threads);
free(process);
setScheduling(true);
schedRelease();
return 0;
}

KDEBUG("created new process with pid %d\n", pid);

Expand Down
Loading