
Demonstrates CVE-2026-11108 integer overflow in kmalloc simulation, causing heap overflow and potential arbitrary code execution from crafted allocation size.
// alloc_sim.c - Vulnerable memory allocator
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_BLOCK 1024
void *my_malloc(size_t size) {
size_t total = size + sizeof(size_t); // header
if (total > MAX_BLOCK) return NULL;
void *ptr = malloc(total);
if (!ptr) return NULL;
*(size_t *)ptr = size;
return ptr + sizeof(size_t);
}
void my_free(void *p) {
if (!p) return;
size_t *header = (size_t *)(p - sizeof(size_t));
free(header);
}
int main() {
// Craft size that causes integer overflow: 0xFFFFFFFF - sizeof(size_t) + 1 wraps to small number
size_t huge = 0xFFFFFFFF; // 4GB - 1
char *buf = my_malloc(huge - sizeof(size_t) + 1); // overflow: total becomes 0?
if (buf) {
// Write far beyond allocated buffer, heap overflow
memset(buf, 'A', 1000);
printf("Wrote 1000 bytes to tiny buffer\n");
my_free(buf);
}
return 0;
}
A custom memory allocator incorrectly calculates the total allocation size by adding a header size without overflow checks. By passing a size near UINT_MAX, the total wraps to a small value, allocating a tiny buffer but allowing a large write, causing a heap overflow.
Compile and run:
gcc -o alloc_sim alloc_sim.c -fno-stack-protector
./alloc_sim
The program writes far more bytes than the allocated buffer, corrupting heap metadata and likely crashing.