From 185f7189362e632f6b8dd17df683c8fca0ebbc54 Mon Sep 17 00:00:00 2001 From: Ryan Voots Date: Tue, 2 May 2017 13:11:19 -0700 Subject: [PATCH] Moving this to a VM for saner handling --- Makefile | 4 +++- main.c | 23 +++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d6f4bd9..06a642a 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ all: program test +.PHONY: test + test: program - sudo ./program foo + sudo ./program tmp program: main.c gcc main.c -o program diff --git a/main.c b/main.c index 2bafbff..9cf1005 100644 --- a/main.c +++ b/main.c @@ -3,8 +3,8 @@ #include #include #include - #define _GNU_SOURCE - #include +#define _GNU_SOURCE +#include #include #include @@ -15,12 +15,21 @@ struct args { uint8_t CSTACK[8192]; +int setup_jail() { + mount("tmpfs", "jail/tmp", "tmpfs", MS_PRIVATE, NULL); // TODO this needs to also have a tmpfs data to limit size + mount("foo", "jail/foo", NULL, MS_PRIVATE|MS_BIND|MS_RDONLY, NULL); + chdir("jail"); + chroot("."); +} + int myreaddir(void *fooargs) { int len; struct dirent *pDirent; DIR *pDir; struct args *myargs = (struct args *) fooargs; + setup_jail(); + if (myargs->c < 2) { printf ("Usage: testprog \n"); return 1; @@ -30,12 +39,22 @@ int myreaddir(void *fooargs) { mount(NULL, ".", NULL, MS_PRIVATE, NULL); umount(myargs->v[1]); +// sleep(100); + pDir = opendir (myargs->v[1]); if (pDir == NULL) { printf ("Cannot open directory '%s'\n", myargs->v[1]); return 1; } + char file[32]; + snprintf(file, 32, "/tmp/%08d", rand()); + + FILE *foo=fopen(file, "w"); + fclose(file); + + sleep(100); + while ((pDirent = readdir(pDir)) != NULL) { printf ("[%s]\n", pDirent->d_name); }