2 * This demonstrates races: kernel may actually open other file
3 * than you read in the strace output.
4 * If you see a successfull open of /etc/shadow,
5 * you know you've seen a race.
7 * $ gcc -Wall -O0 skodic.c -o skodic
8 * $ timeout 0.1 ../strace -yeopen -o'|grep "shadow.*= [0-9]"' ./skodic
12 # define _GNU_SOURCE 1
29 error(1, errno, "tmpfile");
32 size_t size = sysconf(_SC_PAGESIZE);
34 if (ftruncate(fd, size))
35 error(1, errno, "ftruncate");
37 char *p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
39 error(1, errno, "mmap");
44 strcpy(p, "/etc/shadow");
50 error(1, errno, "fork");
54 strcpy(p, "/etc/passwd");
55 strcpy(p, "/etc/shadow");
59 if ((fd = open(p, 0)) >= 0)