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

usermem / security: no user pointer sanitization #1251

Open
shrik3 opened this issue May 17, 2024 · 3 comments
Open

usermem / security: no user pointer sanitization #1251

shrik3 opened this issue May 17, 2024 · 3 comments
Assignees

Comments

@shrik3
Copy link
Collaborator

shrik3 commented May 17, 2024

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.

@QuarkContainer
Copy link
Owner

@shrik3 Thank you very much for the bug.

@QuarkContainer
Copy link
Owner

The issue is because we enable the "CopyDataWithPf" in config.json as debug. The feature will do the user/kernel memory copy based on page fault. When there is invalid address in user request, as the page fault has no good way to pass the error message to the caller api. The system will crash. The feature could get a little better performance than disable this. So I will disable this feature by default. And will create a PR after more test.

@shrik3
Copy link
Collaborator Author

shrik3 commented May 23, 2024

can confirm. The issue is gone with the CopyDataWithPf option turned off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants