strace/test/skodic.c
James Hogan 5cf23c53b8 test/skodic: make a bit more portable
* test/skodic.c (main): Don't use MAP_FIXED since valid virtual addresses
vary between architectures (as far as I can tell the use of MAP_FIXED is
not relevant to the test).  Also don't assume the file desriptor returned
by open call is 3 when passing it to mmap.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
2013-05-01 14:54:05 +00:00

38 lines
771 B
C

/* This demonstrates races: kernel may actually open other file then
* you read at strace output. Create /tmp/delme with 10K of zeros and
* 666 mode, then run this under strace. If you see open successfull
* open of /etc/shadow, you know you've seen a race.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
char *c;
int fd;
fd = open("/tmp/delme", O_RDWR);
c = mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
*c = 0;
if (fork()) {
while (1) {
strcpy(c, "/etc/passwd");
strcpy(c, "/etc/shadow");
}
} else {
while (1)
if ((fd = open(c, 0)) != -1)
close(fd);
}
return 0;
}