Skip to content

Instantly share code, notes, and snippets.

@heatd
Last active September 11, 2023 15:46
Show Gist options
  • Save heatd/85d2971fae1501b55b6ea401fbbe485b to your computer and use it in GitHub Desktop.
Save heatd/85d2971fae1501b55b6ea401fbbe485b to your computer and use it in GitHub Desktop.
#include <unistd.h>
#include <sys/mman.h>
#include <err.h>
#include <stdio.h>
#include <fcntl.h>
int main()
{
int ret = 0;
char old_limit[64];
int limlen = 0;
int fd = open("/proc/sys/vm/mmap_min_addr", O_RDWR);
if (fd < 0)
err(1, "open");
if ((limlen = read(fd, old_limit, sizeof(old_limit))) < 0)
err(1, "read");
lseek(fd, 0, SEEK_SET);
if (write(fd, "0\n", 2) < 0)
err(1, "write");
void *addr = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0);
if (addr == MAP_FAILED)
err(1, "addr");
/* test regression */
if (mprotect(NULL, 0x1000, PROT_READ) < 0)
{
ret = 1;
printf("Regression present!\n");
}
lseek(fd, 0, SEEK_SET);
if (write(fd, old_limit, limlen) < 0)
err(1, "write(old_limit)");
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment