diff options
| author | Filip Strömbäck <filip.stromback@liu.se> | 2019-05-07 11:59:30 +0200 |
|---|---|---|
| committer | Filip Strömbäck <filip.stromback@liu.se> | 2019-05-07 11:59:30 +0200 |
| commit | acbcfc8bd44604147275942c880c82e69318fcde (patch) | |
| tree | 844a15e5ed08be9ae4df4ba26a10ffb7e9797b14 /src/tests/filst | |
| parent | c3ce00fe7d5a88560864167d769a559c578115f4 (diff) | |
| download | pintos-rs-acbcfc8bd44604147275942c880c82e69318fcde.tar.gz | |
Added 'close' test for better testing of syscall parameter validation.
Signed-off-by: Filip Strömbäck <filip.stromback@liu.se>
Diffstat (limited to 'src/tests/filst')
| -rw-r--r-- | src/tests/filst/Make.tests | 8 | ||||
| -rw-r--r-- | src/tests/filst/sc-bad-close.c | 67 | ||||
| -rw-r--r-- | src/tests/filst/sc-bad-close.ck | 10 |
3 files changed, 80 insertions, 5 deletions
diff --git a/src/tests/filst/Make.tests b/src/tests/filst/Make.tests index 68bffb1..4c59dc5 100644 --- a/src/tests/filst/Make.tests +++ b/src/tests/filst/Make.tests @@ -3,14 +3,12 @@ tests/%.output: FSDISK = 2 tests/%.output: PUTFILES = $(filter-out os.dsk, $^) -tests/filst_TESTS = $(addprefix tests/filst/,sc-bad-write) +tests/filst_TESTS = $(addprefix tests/filst/,sc-bad-write sc-bad-close) -tests/filst_PROGS = $(tests/filst_TESTS) # $(addprefix tests/filst/,child-simple) +tests/filst_PROGS = $(tests/filst_TESTS) tests/filst/sc-bad-write_SRC = tests/filst/sc-bad-write.c tests/main.c +tests/filst/sc-bad-close_SRC = tests/filst/sc-bad-close.c tests/main.c $(foreach prog,$(tests/filst_PROGS),$(eval $(prog)_SRC += tests/lib.c)) -tests/filst/read-bad-buf_PUTFILES += tests/filst/sample.txt -tests/filst/low-mem_PUTFILES += tests/filst/child-simple -tests/filst/exec-corrupt_PUTFILES += tests/filst/corrupt-elf diff --git a/src/tests/filst/sc-bad-close.c b/src/tests/filst/sc-bad-close.c new file mode 100644 index 0000000..8331817 --- /dev/null +++ b/src/tests/filst/sc-bad-close.c @@ -0,0 +1,67 @@ +#include <syscall-nr.h> +#include <stdio.h> +#include <stdint.h> +#include "tests/lib.h" +#include "tests/main.h" + +/** + * From threads/vaddr.h: + */ +#define BITMASK(SHIFT, CNT) (((1ul << (CNT)) - 1) << (SHIFT)) + +#define PGSHIFT 0 /* Index of first offset bit. */ +#define PGBITS 12 /* Number of offset bits. */ +#define PGSIZE (1 << PGBITS) /* Bytes in a page. */ +#define PGMASK BITMASK(PGSHIFT, PGBITS) /* Page offset bits (0:12). */ + +static inline void *pg_round_up (const void *va) { + return (void *) (((uintptr_t) va + PGSIZE - 1) & ~PGMASK); +} + +/** + * External symbol which address is the first address after all data in the BSS segment. + */ +extern int _end_bss; + +void test_main(void) +{ + // Get the addres of the first unmapped page in the system. + unsigned page = (unsigned)pg_round_up(&_end_bss); + + // Reserve space for 2 parameters. + unsigned base = page - sizeof(int) * 2; + + // Call write() with space for 4 parameters (should be fine). + asm volatile ( + "movl %%esp, %%edi;" + "movl %0, %%esp;" // Set stack pointer to right below page boundary. + "movl %1, (%%esp);" // Try to call SYS_CLOSE + "movl $8, 4(%%esp);" // Close fileno #8 + "int $0x30;" + "movl %%edi, %%esp;" // Restore esp. + : + : "r" (base), + "i" (SYS_CLOSE) + : "%esp", "%eax", "%edi"); + + + write(STDOUT_FILENO, "OK\n", 3); + + // Reserve space for 1 parameter (open requires 2). + base = page - sizeof(int) * 1; + + // Call write() with space for 3 parameters (the kernel should kill us for doing this). + asm volatile ( + "movl %%esp, %%edi;" + "movl %0, %%esp;" // Set stack pointer to right below page boundary. + "movl %1, (%%esp);" // Try to call SYS_CLOSE + // "movl $8, 4(%%esp);" // Close fileno #8 + "int $0x30;" + "movl %%edi, %%esp;" // Restore esp in case we do not crash (as we should). + : + : "r" (base), + "i" (SYS_CLOSE) + : "%esp", "%eax", "%edi"); + + fail("should have died."); +} diff --git a/src/tests/filst/sc-bad-close.ck b/src/tests/filst/sc-bad-close.ck new file mode 100644 index 0000000..013e503 --- /dev/null +++ b/src/tests/filst/sc-bad-close.ck @@ -0,0 +1,10 @@ +# -*- perl -*- +use strict; +use warnings; +use tests::tests; +check_expected ([<<'EOF']); +(sc-bad-close) begin +OK +sc-bad-close: exit(-1) +EOF +pass; |
