commoncriteria / operatingsystem

Protection Profile for Operating Systems
The Unlicense
9 stars 6 forks source link

improve AA in FPT_W^X_EXT.1.1 #57

Closed jeffblank closed 9 years ago

jeffblank commented 9 years ago

Needs to say something TSS, maybe a test activity.

kgal commented 9 years ago

Adapt and run this?

#include <sys/stat.h>
#include <sys/mman.h> 
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <stdio.h>

int main (int argc, char *argv[])
{
    /* Information about the file. */
    struct stat fStats;

    printf("Opening %s\n", argv[argc-1]);

    /* Open the file for reading. */
    int fd = open (argv[argc-1], O_RDONLY);

    if(fd<=0){
      fprintf(stderr, "open %s failed: %s", argv[argc-1], strerror (errno));
      return 0;
    }
    /* Get the size of the file. */
    int status = fstat (fd, &fStats);
    if(status<0){
      fprintf(stderr, "stat %s failed: %s", argv[argc-1], strerror (errno));
      return 0;
    }
    /* Memory-map the file. */
    void * mapped = 
      mmap (0, fStats.st_size, PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0);
    if( mapped == MAP_FAILED ){
      fprintf(stderr, "mmap %s failed: %s", argv[argc-1], strerror (errno));
    }
    else{
      printf("Mapping a page Write/Execute succeeded\n");
      munmap(mapped, fStats.st_size);
    }
    close(fd);

}
jeffblank commented 9 years ago

Yes indeed. I wrote generic prose for this in the AA.