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

Using read/write on mmap'ed memory ignores the protection flags of the area #1

Open
JustSid opened this issue Jun 16, 2013 · 0 comments
Labels

Comments

@JustSid
Copy link
Owner

JustSid commented Jun 16, 2013

read() and write() are done in the kernel, which maps the buffer passed over into the kernel space losing all information about the page's protection. Example:

int fd = open(file, O_RDONLY);
size_t size = lseek(fd, 0, SEEK_END);

lseek(fd, 0, SEEK_SET);

uint8_t *buffer = mmap(NULL, VM_PAGE_COUNT(size) * VM_PAGE_SIZE, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);

while(size > 0)
{
    size_t bytes = read(fd, buffer, size);

    size -= bytes;
    buffer += bytes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant