diff --git a/src/tests/userprog/Make.tests b/src/tests/userprog/Make.tests index 02c73fe..542ea0b 100644 --- a/src/tests/userprog/Make.tests +++ b/src/tests/userprog/Make.tests @@ -9,14 +9,14 @@ sc-bad-arg sc-bad-num sc-boundary sc-boundary-2 halt exit create-normal \ create-empty create-null create-bad-ptr create-long create-exists \ create-bound open-normal open-missing open-boundary open-empty \ open-null open-bad-ptr open-twice close-normal close-twice close-stdin \ -close-stdout close-bad-fd read-normal read-bad-ptr read-boundary \ -read-zero read-stdout read-bad-fd write-normal write-bad-ptr \ +close-stdout close-bad-fd read-normal read-bad-ptr read-bad-buf read-boundary \ +read-zero read-stdout read-bad-fd write-normal write-bad-ptr write-bad-buf \ write-boundary write-zero write-stdin write-bad-fd exec-once exec-arg \ exec-large-arg exec-multiple exec-missing exec-over-arg exec-over-args \ exec-bad-ptr wait-simple wait-twice wait-killed wait-load-kill \ wait-bad-pid wait-bad-child multi-recurse multi-child-fd rox-simple \ rox-child rox-multichild bad-read bad-write bad-read2 bad-write2 \ -bad-jump bad-jump2 bad-maths) +bad-jump bad-jump2 bad-maths overflow-stack) tests/userprog_PROGS = $(tests/userprog_TESTS) $(addprefix \ tests/userprog/,child-simple child-args child-bad child-close child-rox exec-exit) @@ -36,6 +36,7 @@ tests/userprog/bad-read2_SRC = tests/userprog/bad-read2.c tests/main.c tests/userprog/bad-write2_SRC = tests/userprog/bad-write2.c tests/main.c tests/userprog/bad-jump2_SRC = tests/userprog/bad-jump2.c tests/main.c tests/userprog/bad-maths_SRC = tests/userprog/bad-maths.c tests/main.c +tests/userprog/overflow-stack_SRC = tests/userprog/overflow-stack.c tests/main.c tests/userprog/sc-boundary_SRC = tests/userprog/sc-boundary.c \ tests/userprog/boundary.c tests/main.c tests/userprog/sc-boundary-2_SRC = tests/userprog/sc-boundary-2.c \ @@ -66,6 +67,7 @@ tests/userprog/close-stdout_SRC = tests/userprog/close-stdout.c tests/main.c tests/userprog/close-bad-fd_SRC = tests/userprog/close-bad-fd.c tests/main.c tests/userprog/read-normal_SRC = tests/userprog/read-normal.c tests/main.c tests/userprog/read-bad-ptr_SRC = tests/userprog/read-bad-ptr.c tests/main.c +tests/userprog/read-bad-buf_SRC = tests/userprog/read-bad-buf.c tests/main.c tests/userprog/read-boundary_SRC = tests/userprog/read-boundary.c \ tests/userprog/boundary.c tests/main.c tests/userprog/read-zero_SRC = tests/userprog/read-zero.c tests/main.c @@ -73,6 +75,7 @@ tests/userprog/read-stdout_SRC = tests/userprog/read-stdout.c tests/main.c tests/userprog/read-bad-fd_SRC = tests/userprog/read-bad-fd.c tests/main.c tests/userprog/write-normal_SRC = tests/userprog/write-normal.c tests/main.c tests/userprog/write-bad-ptr_SRC = tests/userprog/write-bad-ptr.c tests/main.c +tests/userprog/write-bad-buf_SRC = tests/userprog/write-bad-buf.c tests/main.c tests/userprog/write-boundary_SRC = tests/userprog/write-boundary.c \ tests/userprog/boundary.c tests/main.c tests/userprog/write-zero_SRC = tests/userprog/write-zero.c tests/main.c @@ -122,10 +125,12 @@ tests/userprog/close-normal_PUTFILES += tests/userprog/sample.txt tests/userprog/close-twice_PUTFILES += tests/userprog/sample.txt tests/userprog/read-normal_PUTFILES += tests/userprog/sample.txt tests/userprog/read-bad-ptr_PUTFILES += tests/userprog/sample.txt +tests/userprog/read-bad-buf_PUTFILES += tests/userprog/sample.txt tests/userprog/read-boundary_PUTFILES += tests/userprog/sample.txt tests/userprog/read-zero_PUTFILES += tests/userprog/sample.txt tests/userprog/write-normal_PUTFILES += tests/userprog/sample.txt tests/userprog/write-bad-ptr_PUTFILES += tests/userprog/sample.txt +tests/userprog/write-bad-buf_PUTFILES += tests/userprog/sample.txt tests/userprog/write-boundary_PUTFILES += tests/userprog/sample.txt tests/userprog/write-zero_PUTFILES += tests/userprog/sample.txt tests/userprog/multi-child-fd_PUTFILES += tests/userprog/sample.txt diff --git a/src/tests/userprog/Rubric.robustnessCR b/src/tests/userprog/Rubric.robustnessCR index 9784817..256caed 100644 --- a/src/tests/userprog/Rubric.robustnessCR +++ b/src/tests/userprog/Rubric.robustnessCR @@ -1,5 +1,9 @@ -Full robustness of argument passing code: -- Test user stack overflow robustness of "exec" system calls. +Full robustness of argument passing and syscall handling code: +- Test user stack overflow robustness of "exec" system calls and user code. 5 exec-over-arg 5 exec-over-args +5 overflow-stack +- Test syscall user provided buffer validity checks. +5 read-bad-buf +5 write-bad-buf diff --git a/src/tests/userprog/exec-bad-ptr.ck b/src/tests/userprog/exec-bad-ptr.ck index 63f5f78..7f2604c 100644 --- a/src/tests/userprog/exec-bad-ptr.ck +++ b/src/tests/userprog/exec-bad-ptr.ck @@ -2,11 +2,7 @@ use strict; use warnings; use tests::tests; -check_expected ([<<'EOF', <<'EOF']); -(exec-bad-ptr) begin -(exec-bad-ptr) end -exec-bad-ptr: exit(0) -EOF +check_expected ([<<'EOF']); (exec-bad-ptr) begin exec-bad-ptr: exit(-1) EOF diff --git a/src/tests/userprog/open-bad-ptr.ck b/src/tests/userprog/open-bad-ptr.ck index 45349e2..fa686d0 100644 --- a/src/tests/userprog/open-bad-ptr.ck +++ b/src/tests/userprog/open-bad-ptr.ck @@ -2,11 +2,7 @@ use strict; use warnings; use tests::tests; -check_expected ([<<'EOF', <<'EOF']); -(open-bad-ptr) begin -(open-bad-ptr) end -open-bad-ptr: exit(0) -EOF +check_expected ([<<'EOF']); (open-bad-ptr) begin open-bad-ptr: exit(-1) EOF diff --git a/src/tests/userprog/overflow-stack.c b/src/tests/userprog/overflow-stack.c new file mode 100644 index 0000000..d7c9c85 --- /dev/null +++ b/src/tests/userprog/overflow-stack.c @@ -0,0 +1,17 @@ +/* Attempt to overflow the user stack by allocating a 4kB buffer and writing into it. + The process must be terminated with -1 exit code until stack growth has been implemented in Task 3 +*/ + +#include +#include +#include "tests/lib.h" +#include "tests/main.h" + +void +test_main (void) +{ + char stack_obj[4096]; + memset (stack_obj, 'a', sizeof stack_obj); + memset (stack_obj+10, '\0', 1); + msg ("buffer: %s", stack_obj); +} diff --git a/src/tests/userprog/overflow-stack.ck b/src/tests/userprog/overflow-stack.ck new file mode 100644 index 0000000..8998230 --- /dev/null +++ b/src/tests/userprog/overflow-stack.ck @@ -0,0 +1,14 @@ +# -*- perl -*- +use strict; +use warnings; +use tests::tests; +check_expected (IGNORE_USER_FAULTS => 1, [<<'EOF',<<'EOF']); +(overflow-stack) begin +overflow-stack: exit(-1) +EOF +(overflow-stack) begin +(overflow-stack) buffer: aaaaaaaaaa +(overflow-stack) end +overflow-stack: exit(0) +EOF +pass; diff --git a/src/tests/userprog/read-bad-buf.c b/src/tests/userprog/read-bad-buf.c new file mode 100644 index 0000000..d2dc613 --- /dev/null +++ b/src/tests/userprog/read-bad-buf.c @@ -0,0 +1,17 @@ +/* Passes a buffer to the read system call that starts in valid memory, but runs into kernel space. + The process must be terminated with -1 exit code. +*/ + +#include +#include "tests/lib.h" +#include "tests/main.h" + +void +test_main (void) +{ + int handle; + CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\""); + + read (handle, (char *) 0xbfffffe0, 100); + fail ("should not have survived read()"); +} diff --git a/src/tests/userprog/read-bad-buf.ck b/src/tests/userprog/read-bad-buf.ck new file mode 100644 index 0000000..703b633 --- /dev/null +++ b/src/tests/userprog/read-bad-buf.ck @@ -0,0 +1,10 @@ +# -*- perl -*- +use strict; +use warnings; +use tests::tests; +check_expected (IGNORE_KERNEL_FAULTS => 1, [<<'EOF']); +(read-bad-buf) begin +(read-bad-buf) open "sample.txt" +read-bad-buf: exit(-1) +EOF +pass; diff --git a/src/tests/userprog/read-bad-ptr.ck b/src/tests/userprog/read-bad-ptr.ck index d10accf..abd67f7 100644 --- a/src/tests/userprog/read-bad-ptr.ck +++ b/src/tests/userprog/read-bad-ptr.ck @@ -2,12 +2,7 @@ use strict; use warnings; use tests::tests; -check_expected ([<<'EOF', <<'EOF']); -(read-bad-ptr) begin -(read-bad-ptr) open "sample.txt" -(read-bad-ptr) end -read-bad-ptr: exit(0) -EOF +check_expected ([<<'EOF']); (read-bad-ptr) begin (read-bad-ptr) open "sample.txt" read-bad-ptr: exit(-1) diff --git a/src/tests/userprog/write-bad-buf.c b/src/tests/userprog/write-bad-buf.c new file mode 100644 index 0000000..589499c --- /dev/null +++ b/src/tests/userprog/write-bad-buf.c @@ -0,0 +1,17 @@ +/* Passes a buffer to the write system call that starts in valid memory, but runs into kernel space. + The process must be terminated with -1 exit code. +*/ + +#include +#include "tests/lib.h" +#include "tests/main.h" + +void +test_main (void) +{ + int handle; + CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\""); + + write (handle, (char *) 0xbffffff0, 32); + fail ("should have exited with -1"); +} diff --git a/src/tests/userprog/write-bad-buf.ck b/src/tests/userprog/write-bad-buf.ck new file mode 100644 index 0000000..b0678cb --- /dev/null +++ b/src/tests/userprog/write-bad-buf.ck @@ -0,0 +1,10 @@ +# -*- perl -*- +use strict; +use warnings; +use tests::tests; +check_expected (IGNORE_KERNEL_FAULTS => 1, [<<'EOF']); +(write-bad-buf) begin +(write-bad-buf) open "sample.txt" +write-bad-buf: exit(-1) +EOF +pass; diff --git a/src/tests/userprog/write-bad-ptr.ck b/src/tests/userprog/write-bad-ptr.ck index ad9f399..3014879 100644 --- a/src/tests/userprog/write-bad-ptr.ck +++ b/src/tests/userprog/write-bad-ptr.ck @@ -2,12 +2,7 @@ use strict; use warnings; use tests::tests; -check_expected ([<<'EOF', <<'EOF']); -(write-bad-ptr) begin -(write-bad-ptr) open "sample.txt" -(write-bad-ptr) end -write-bad-ptr: exit(0) -EOF +check_expected ([<<'EOF']); (write-bad-ptr) begin (write-bad-ptr) open "sample.txt" write-bad-ptr: exit(-1)