~ubuntu-branches/ubuntu/saucy/strace/saucy-proposed

« back to all changes in this revision

Viewing changes to test/skodic.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2009-05-05 10:21:37 UTC
  • mfrom: (0.1.6 upstream) (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090505102137-ransgzeynrwa2yww
Tags: 4.5.18-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Add lpia as supported architecture

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 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>
9
 
#include <unistd.h>
10
 
#include <sys/mman.h>
11
 
#include <sys/types.h>
12
 
#include <sys/stat.h>
13
 
#include <fcntl.h>
14
 
 
15
 
int
16
 
main(void)
17
 
{
18
 
  char *c = (char*)0x94000000;
19
 
  int fd;
20
 
  open( "/tmp/delme", O_RDWR );
21
 
  mmap( c, 4096, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, 3, 0 );
22
 
  *c = 0;
23
 
  if (fork()) {
24
 
    while(1) {
25
 
      strcpy( c, "/etc/passwd" );    
26
 
      strcpy( c, "/etc/shadow" );
27
 
    }
28
 
  } else
29
 
    while (1)
30
 
      if ((fd=open( c, 0 ))!=-1)
31
 
          close(fd);
32
 
  return 0;
33
 
}