
C 시뮬레이터로, GPU 드라이버 ioctl 경쟁 조건(race condition)으로 인한 use-after-free 및 로컬 권한 상승을 시연하며, 컴파일-후-실행 방식의 익스플로잇 시연을 포함합니다.
// gpu_driver_sim.c - Simulated GPU driver ioctl with race condition
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <string.h>
void *gpu_mmap = NULL;
size_t map_size = 0;
int locked = 0;
void ioctl_map(size_t size) {
// Allocate GPU memory and map to user
gpu_mmap = malloc(size);
map_size = size;
// Simulate race: after mapping, kernel updates metadata
usleep(100); // vulnerable window
// During this window, another thread can change size causing OOB access
memset(gpu_mmap, 0, size);
}
void *attacker_thread(void *arg) {
// While mapping in progress, trigger another ioctl that frees the buffer
free(gpu_mmap);
gpu_mmap = NULL;
return NULL;
}
int main() {
pthread_t t;
pthread_create(&t, NULL, attacker_thread, NULL);
ioctl_map(0x1000);
pthread_join(t, NULL);
// Use after free possible
if (gpu_mmap) memset(gpu_mmap, 'A', 0x1000); // crash
return 0;
}
GPU 커널 드라이버가 메모리 매핑 ioctl을 적절한 잠금 없이 처리하여, 사용자 공간 매핑이 사용 중인 상태에서 해제되는 경쟁 조건이 발생합니다. 이로 인해 use-after-free가 발생하며, 로컬 권한 상승에 악용될 수 있습니다.
시뮬레이션을 컴파일하고 실행합니다:
gcc -o gpu_driver_sim gpu_driver_sim.c -lpthread
./gpu_driver_sim
이 프로그램은 use-after-free로 인해 크래시가 발생합니다.