-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stack-heap collision check to BrkSyscall execution (#346)
Implemented additional checking in the `execute()` method of the brk syscall, defined in the `BrkSyscall` class, to ensure that memory allocation does not overflow stack space. The System Call has as its argument the new "program break", which is now compared with the current "stack pointer" before being set to avoid overlaps. Added unit tests to verify that when the `brk` syscall is called with illegal arguments (causing a stack-heap collision), the syscall returns a non-zero value, indicating that it was not executed successfully.
- Loading branch information
1 parent
f6627af
commit d0c71e8
Showing
3 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.text | ||
.globl _start | ||
_start: nop | ||
|
||
#------------------------------------------------------------- | ||
# Stack-Heap Collision brk syscall Test | ||
#------------------------------------------------------------- | ||
|
||
test_0: # Test Ecall Return Value | ||
mv a0, sp # Assign the ecall parameter to the stack pointer value | ||
lw a7, BRK # Load the brk syscall immediate value | ||
ecall | ||
|
||
# If the return value of the ecall is zero, then the ecall | ||
# was executed successfully and therefore the test failed | ||
beqz a0, fail | ||
|
||
bne x0, gp, pass | ||
|
||
pass: | ||
li a0, 42 | ||
li a7, 93 | ||
ecall | ||
|
||
|
||
fail: | ||
li a0, 0 | ||
li a7, 93 | ||
ecall | ||
|
||
.data | ||
.align 4 | ||
|
||
# Syscall immediate value | ||
BRK: .word 214 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.text | ||
|
||
#------------------------------------------------------------- | ||
# Stack-Heap Collision brk syscall Test | ||
#------------------------------------------------------------- | ||
|
||
test_0: # Test Ecall Return Value | ||
mv a0, sp # Assign the ecall parameter to the stack pointer value | ||
li a7, 214 # Load the brk syscall immediate value | ||
ecall | ||
|
||
# If the return value of the ecall is zero, then the ecall | ||
# was executed successfully and therefore the test failed | ||
beqz a0, fail | ||
|
||
bne x0, gp, pass | ||
|
||
pass: | ||
li a0, 42 | ||
li a7, 93 | ||
ecall | ||
|
||
|
||
fail: | ||
li a0, 0 | ||
li a7, 93 | ||
ecall |