Add more tests for system calls to deal with bad buffers given to read and write
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
17
src/tests/userprog/overflow-stack.c
Normal file
17
src/tests/userprog/overflow-stack.c
Normal file
@@ -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 <string.h>
|
||||
#include <syscall.h>
|
||||
#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);
|
||||
}
|
||||
14
src/tests/userprog/overflow-stack.ck
Normal file
14
src/tests/userprog/overflow-stack.ck
Normal file
@@ -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;
|
||||
17
src/tests/userprog/read-bad-buf.c
Normal file
17
src/tests/userprog/read-bad-buf.c
Normal file
@@ -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 <syscall.h>
|
||||
#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()");
|
||||
}
|
||||
10
src/tests/userprog/read-bad-buf.ck
Normal file
10
src/tests/userprog/read-bad-buf.ck
Normal file
@@ -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;
|
||||
@@ -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)
|
||||
|
||||
17
src/tests/userprog/write-bad-buf.c
Normal file
17
src/tests/userprog/write-bad-buf.c
Normal file
@@ -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 <syscall.h>
|
||||
#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");
|
||||
}
|
||||
10
src/tests/userprog/write-bad-buf.ck
Normal file
10
src/tests/userprog/write-bad-buf.ck
Normal file
@@ -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;
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user