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

NULL pointer access behaviour #272

Open
qhuo opened this issue Sep 28, 2024 · 2 comments
Open

NULL pointer access behaviour #272

qhuo opened this issue Sep 28, 2024 · 2 comments

Comments

@qhuo
Copy link

qhuo commented Sep 28, 2024

It seems that NULL pointer is mapped into user space pagetable, such that the below code works!

// Test NULL pointer access.
// FIXME: this shouldn't pass.
void
nullptr(char *s)
{
  const char* const pz = (const char*) 0;

  const char c = *pz;

  printf("*(const char*)0 == %x\n", (int) c);
}

Would it be better to prevent this? Ideally we shall map a guard map at virtual address 0.

I can make a change if there are no objections.

@jrmenzel
Copy link

Yes, you would have to map the apps one page higher. Right now page 0 is read only, so writing to a NULL pointer will cause an exception. To also case an exception on read you should have nothing mapped there (an empty mapped page with no access rights works too but is wasted memory).

Note that a few places in the code assume that the apps starts at 0, the linker script, the processes size, how a processes memory gets copied in fork etc.

This fix would also make a nice programming assignment, so it could be intentional to have apps at page 0.

@qhuo
Copy link
Author

qhuo commented Oct 1, 2024

Hi, thanks for your reply.

Yes, I agree it would be a good exercise. I would be interested to implement this.

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