blob: 09967bdd4730e20bbdbf5b684f39169a88902e1d [file] [log] [blame]
Pavel Machek245a6ac2000-02-01 16:12:33 +00001/* This demonstrates races: kernel may actually open other file then
2 * you read at strace output. Create /tmp/delme with 10K of zeros and
3 * 666 mode, then run this under strace. If you see open successfull
4 * open of /etc/shadow, you know you've seen a race.
5 */
6
7#include <stdio.h>
8#include <stdlib.h>
Denys Vlasenko8ed57272009-02-25 14:24:02 +00009#include <string.h>
Pavel Machek245a6ac2000-02-01 16:12:33 +000010#include <unistd.h>
11#include <sys/mman.h>
12#include <sys/types.h>
13#include <sys/stat.h>
14#include <fcntl.h>
15
Denys Vlasenko8ed57272009-02-25 14:24:02 +000016int main(int argc, char *argv[])
Pavel Machek245a6ac2000-02-01 16:12:33 +000017{
Denys Vlasenko8ed57272009-02-25 14:24:02 +000018 /* XXX: x86 specific stuff? */
19 char *c = (char*) 0x94000000;
20 int fd;
21
22 open("/tmp/delme", O_RDWR);
23 mmap(c, 4096, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, 3, 0);
24 *c = 0;
25
26 if (fork()) {
27 while(1) {
28 strcpy(c, "/etc/passwd");
29 strcpy(c, "/etc/shadow");
30 }
31 } else {
32 while (1)
33 if ((fd = open(c, 0)) != -1)
34 close(fd);
35 }
36
37 return 0;
Pavel Machek245a6ac2000-02-01 16:12:33 +000038}