From 1f197c6861841bc0c27327c20b85e7b43b65affe Mon Sep 17 00:00:00 2001 From: Godmar Back Date: Wed, 7 Jun 2006 22:09:19 +0000 Subject: [PATCH] added bad-jump/read/write bad-jump2/read2/write2 to check that process that attempt to execute/read/write NULL or a kernel address, resp., are properly terminated. --- src/tests/userprog/Make.tests | 9 ++++++++- src/tests/userprog/Rubric.robustness | 7 +++++++ src/tests/userprog/bad-jump.c | 13 +++++++++++++ src/tests/userprog/bad-jump.ck | 8 ++++++++ src/tests/userprog/bad-jump2.c | 13 +++++++++++++ src/tests/userprog/bad-jump2.ck | 8 ++++++++ src/tests/userprog/bad-read.c | 13 +++++++++++++ src/tests/userprog/bad-read.ck | 8 ++++++++ src/tests/userprog/bad-read2.c | 13 +++++++++++++ src/tests/userprog/bad-read2.ck | 8 ++++++++ src/tests/userprog/bad-write.c | 12 ++++++++++++ src/tests/userprog/bad-write.ck | 8 ++++++++ src/tests/userprog/bad-write2.c | 12 ++++++++++++ src/tests/userprog/bad-write2.ck | 8 ++++++++ 14 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 src/tests/userprog/bad-jump.c create mode 100644 src/tests/userprog/bad-jump.ck create mode 100644 src/tests/userprog/bad-jump2.c create mode 100644 src/tests/userprog/bad-jump2.ck create mode 100644 src/tests/userprog/bad-read.c create mode 100644 src/tests/userprog/bad-read.ck create mode 100644 src/tests/userprog/bad-read2.c create mode 100644 src/tests/userprog/bad-read2.ck create mode 100644 src/tests/userprog/bad-write.c create mode 100644 src/tests/userprog/bad-write.ck create mode 100644 src/tests/userprog/bad-write2.c create mode 100644 src/tests/userprog/bad-write2.ck diff --git a/src/tests/userprog/Make.tests b/src/tests/userprog/Make.tests index 9a5869f..8d64c05 100644 --- a/src/tests/userprog/Make.tests +++ b/src/tests/userprog/Make.tests @@ -14,7 +14,8 @@ read-zero read-stdout read-bad-fd write-normal write-bad-ptr \ write-boundary write-zero write-stdin write-bad-fd exec-once exec-arg \ exec-multiple exec-missing exec-bad-ptr wait-simple wait-twice \ wait-killed wait-bad-pid multi-recurse multi-child-fd rox-simple \ -rox-child rox-multichild) +rox-child rox-multichild bad-read bad-write bad-read2 bad-write2 \ +bad-jump bad-jump2) tests/userprog_PROGS = $(tests/userprog_TESTS) $(addprefix \ tests/userprog/,child-simple child-args child-bad child-close child-rox) @@ -26,6 +27,12 @@ tests/userprog/args-many_SRC = tests/userprog/args.c tests/userprog/args-dbl-space_SRC = tests/userprog/args.c tests/userprog/sc-bad-sp_SRC = tests/userprog/sc-bad-sp.c tests/main.c tests/userprog/sc-bad-arg_SRC = tests/userprog/sc-bad-arg.c tests/main.c +tests/userprog/bad-read_SRC = tests/userprog/bad-read.c tests/main.c +tests/userprog/bad-write_SRC = tests/userprog/bad-write.c tests/main.c +tests/userprog/bad-jump_SRC = tests/userprog/bad-jump.c tests/main.c +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/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 \ diff --git a/src/tests/userprog/Rubric.robustness b/src/tests/userprog/Rubric.robustness index 0a5690a..5696156 100644 --- a/src/tests/userprog/Rubric.robustness +++ b/src/tests/userprog/Rubric.robustness @@ -39,3 +39,10 @@ Robustness of system calls: 5 wait-bad-pid 5 wait-killed +- Test robustness of exception handling. +1 bad-read +1 bad-write +1 bad-jump +1 bad-read2 +1 bad-write2 +1 bad-jump2 diff --git a/src/tests/userprog/bad-jump.c b/src/tests/userprog/bad-jump.c new file mode 100644 index 0000000..51b7c9f --- /dev/null +++ b/src/tests/userprog/bad-jump.c @@ -0,0 +1,13 @@ +/* This program attempts to execute code at address 0, which is not mapped. + This should terminate the process with a -1 exit code. */ + +#include "tests/lib.h" +#include "tests/main.h" + +void +test_main (void) +{ + msg ("Congratulations - you have successfully called NULL: %d", + ((int (*)(void))NULL)()); + fail ("should have exited with -1"); +} diff --git a/src/tests/userprog/bad-jump.ck b/src/tests/userprog/bad-jump.ck new file mode 100644 index 0000000..71662e8 --- /dev/null +++ b/src/tests/userprog/bad-jump.ck @@ -0,0 +1,8 @@ +# -*- perl -*- +use strict; +use warnings; +use tests::tests; +check_expected ([<<'EOF']); +(bad-jump) begin +bad-jump: exit(-1) +EOF diff --git a/src/tests/userprog/bad-jump2.c b/src/tests/userprog/bad-jump2.c new file mode 100644 index 0000000..dc7c2a7 --- /dev/null +++ b/src/tests/userprog/bad-jump2.c @@ -0,0 +1,13 @@ +/* This program attempts to execute code at a kernel virtual address. + This should terminate the process with a -1 exit code. */ + +#include "tests/lib.h" +#include "tests/main.h" + +void +test_main (void) +{ + msg ("Congratulations - you have successfully called kernel code: %d", + ((int (*)(void))0xC0000000)()); + fail ("should have exited with -1"); +} diff --git a/src/tests/userprog/bad-jump2.ck b/src/tests/userprog/bad-jump2.ck new file mode 100644 index 0000000..8226115 --- /dev/null +++ b/src/tests/userprog/bad-jump2.ck @@ -0,0 +1,8 @@ +# -*- perl -*- +use strict; +use warnings; +use tests::tests; +check_expected ([<<'EOF']); +(bad-jump2) begin +bad-jump2: exit(-1) +EOF diff --git a/src/tests/userprog/bad-read.c b/src/tests/userprog/bad-read.c new file mode 100644 index 0000000..904c278 --- /dev/null +++ b/src/tests/userprog/bad-read.c @@ -0,0 +1,13 @@ +/* This program attempts to read memory at an address that is not mapped. + This should terminate the process with a -1 exit code. */ + +#include "tests/lib.h" +#include "tests/main.h" + +void +test_main (void) +{ + msg ("Congratulations - you have successfully dereferenced NULL: %d", + *(int *)NULL); + fail ("should have exited with -1"); +} diff --git a/src/tests/userprog/bad-read.ck b/src/tests/userprog/bad-read.ck new file mode 100644 index 0000000..8a531d9 --- /dev/null +++ b/src/tests/userprog/bad-read.ck @@ -0,0 +1,8 @@ +# -*- perl -*- +use strict; +use warnings; +use tests::tests; +check_expected ([<<'EOF']); +(bad-read) begin +bad-read: exit(-1) +EOF diff --git a/src/tests/userprog/bad-read2.c b/src/tests/userprog/bad-read2.c new file mode 100644 index 0000000..a2fc237 --- /dev/null +++ b/src/tests/userprog/bad-read2.c @@ -0,0 +1,13 @@ +/* This program attempts to read kernel memory. + This should terminate the process with a -1 exit code. */ + +#include "tests/lib.h" +#include "tests/main.h" + +void +test_main (void) +{ + msg ("Congratulations - you have successfully read kernel memory: %d", + *(int *)0xC0000000); + fail ("should have exited with -1"); +} diff --git a/src/tests/userprog/bad-read2.ck b/src/tests/userprog/bad-read2.ck new file mode 100644 index 0000000..cabe862 --- /dev/null +++ b/src/tests/userprog/bad-read2.ck @@ -0,0 +1,8 @@ +# -*- perl -*- +use strict; +use warnings; +use tests::tests; +check_expected ([<<'EOF']); +(bad-read2) begin +bad-read2: exit(-1) +EOF diff --git a/src/tests/userprog/bad-write.c b/src/tests/userprog/bad-write.c new file mode 100644 index 0000000..000c26b --- /dev/null +++ b/src/tests/userprog/bad-write.c @@ -0,0 +1,12 @@ +/* This program attempts to write to memory at an address that is not mapped. + This should terminate the process with a -1 exit code. */ + +#include "tests/lib.h" +#include "tests/main.h" + +void +test_main (void) +{ + *(int *)NULL = 42; + fail ("should have exited with -1"); +} diff --git a/src/tests/userprog/bad-write.ck b/src/tests/userprog/bad-write.ck new file mode 100644 index 0000000..7b2e2d7 --- /dev/null +++ b/src/tests/userprog/bad-write.ck @@ -0,0 +1,8 @@ +# -*- perl -*- +use strict; +use warnings; +use tests::tests; +check_expected ([<<'EOF']); +(bad-write) begin +bad-write: exit(-1) +EOF diff --git a/src/tests/userprog/bad-write2.c b/src/tests/userprog/bad-write2.c new file mode 100644 index 0000000..753da1e --- /dev/null +++ b/src/tests/userprog/bad-write2.c @@ -0,0 +1,12 @@ +/* This program attempts to write to kernel memory. + This should terminate the process with a -1 exit code. */ + +#include "tests/lib.h" +#include "tests/main.h" + +void +test_main (void) +{ + *(int *)0xC0000000 = 42; + fail ("should have exited with -1"); +} diff --git a/src/tests/userprog/bad-write2.ck b/src/tests/userprog/bad-write2.ck new file mode 100644 index 0000000..c94a10f --- /dev/null +++ b/src/tests/userprog/bad-write2.ck @@ -0,0 +1,8 @@ +# -*- perl -*- +use strict; +use warnings; +use tests::tests; +check_expected ([<<'EOF']); +(bad-write2) begin +bad-write2: exit(-1) +EOF -- 2.30.2