Professional Documents
Culture Documents
Race Conditions 4 - Races in Memory
Race Conditions 4 - Races in Memory
Races in Memory
Yan Shoshitaishvili
Arizona State University
#
Can there be races outside of the filesystem?
The filesystem is a common race condition battleground because it is a shared
resources between processes.
Memory is a shared resource between threads...
Of course, race conditions in memory are rampant in multi-threaded programs!
#
Motivating Example
Consider the following:
unsigned int size = 42;
void read_data() {
char buffer[16];
if (size < 16) {
printf("Valid size! Enter payload up to %d bytes.\n", size);
printf("Read %d bytes!\n", read(0, buffer, size));
}
else printf("Invalid size %d!\n", size);
}
main() {
pthread_t allocator;
pthread_create(&allocator, NULL, thread_allocator, 0);
while (size != 0) read(0, &size, 1);
exit(0);
}
static long device_ioctl(struct file *file, unsigned int cmd, unsigned long user_buffer) {
int size;
char buffer[16];
if (!check_safety(user_buffer, 16)) return;
copy_from_user(&size, user_buffer, sizeof(size));
copy_from_user(buffer, user_buffer+sizeof(size), size);
}
main() {
pthread_t t1, t2;
pthread_create(&t1, NULL, thread_main, 0);
pthread_create(&t2, NULL, thread_main, 0);
getchar();
exit(0);
}