Skip to content

usermem / security: no user pointer sanitization #1251

Open
@shrik3

Description

@shrik3

this simple user program could panic the kernel

#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <syscall.h>

int main(int argc, char *argv[])
{
	int res = syscall(SYS_clock_gettime, CLOCK_MONOTONIC, 0);
	printf("ret %d\n", res);
	return 0;
}

log:

[Print] [1/45400c0000|0] unhandle EXCEPTION: page_fault FAULT

This is because the syscall handler SysClockGetTime (among many others) copies to user buffer without sanity check.

    let clock = GetClock(task, clockID)?;
    let ts = clock.Now().Timespec();
    task.CopyOutObj(&ts, addr)?;

In this case I'm passing a null ptr. This causes a pagefault in kernel.

Actually, any illegal user pointer will cause a kernel panic. Because the Memcpy is called upon the user pointer in kernel space.

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions