Skip to content

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

@JustSid

Description

@JustSid

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions