Require unused syscall args to be zero
All checks were successful
Build / build (push) Successful in 2m51s
All checks were successful
Build / build (push) Successful in 2m51s
This commit is contained in:
parent
7db94e628e
commit
c8eea7d45b
2 changed files with 51 additions and 15 deletions
14
Cargo.lock
generated
14
Cargo.lock
generated
|
@ -70,7 +70,7 @@ dependencies = [
|
|||
"regex",
|
||||
"rustc-hash",
|
||||
"shlex",
|
||||
"syn 2.0.92",
|
||||
"syn 2.0.93",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -205,9 +205,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
|
|||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.1"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
||||
checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2"
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
|
@ -347,7 +347,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"syn 2.0.92",
|
||||
"syn 2.0.93",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -472,9 +472,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.92"
|
||||
version = "2.0.93"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70ae51629bf965c5c098cc9e87908a3df5301051a9e087d6f9bef5c9771ed126"
|
||||
checksum = "9c786062daee0d6db1132800e623df74274a0a87322d8e183338e01b3d98d058"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -520,7 +520,7 @@ checksum = "9b24e77d3fc1e617051e630f99da24bcae6328abab37b8f9216bb68d06804f9a"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.92",
|
||||
"syn 2.0.93",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -16,12 +16,27 @@ use super::{
|
|||
struct SyscallArgs {
|
||||
arg1: usize,
|
||||
arg2: usize,
|
||||
_arg3: usize,
|
||||
_arg4: usize,
|
||||
_arg5: usize,
|
||||
arg3: usize,
|
||||
arg4: usize,
|
||||
arg5: usize,
|
||||
}
|
||||
struct Syscall {
|
||||
func: fn(SyscallArgs) -> Result<usize, Box<dyn Error>>,
|
||||
num_args: usize,
|
||||
}
|
||||
|
||||
const SYSCALL_TABLE: [fn(SyscallArgs) -> Result<usize, Box<dyn Error>>; 4] = [syscall_get_kernel_version, syscall_exit, syscall_debug_print, syscall_get_pid];
|
||||
const SYSCALL_TABLE: [Syscall; 4] = [
|
||||
Syscall {
|
||||
func: syscall_get_kernel_version,
|
||||
num_args: 0,
|
||||
},
|
||||
Syscall { func: syscall_exit, num_args: 1 },
|
||||
Syscall {
|
||||
func: syscall_debug_print,
|
||||
num_args: 2,
|
||||
},
|
||||
Syscall { func: syscall_get_pid, num_args: 0 },
|
||||
];
|
||||
|
||||
fn copy_from_user(start: u64, size: usize) -> Result<Vec<u8>, Box<dyn Error>> {
|
||||
if size > 16 * 1024 * 1024 {
|
||||
|
@ -78,11 +93,32 @@ extern "C" fn syscall_handler(syscall: u64, arg1: u64, arg2: u64, arg3: u64, arg
|
|||
let args = SyscallArgs {
|
||||
arg1: arg1 as usize,
|
||||
arg2: arg2 as usize,
|
||||
_arg3: arg3 as usize,
|
||||
_arg4: arg4 as usize,
|
||||
_arg5: arg5 as usize,
|
||||
arg3: arg3 as usize,
|
||||
arg4: arg4 as usize,
|
||||
arg5: arg5 as usize,
|
||||
};
|
||||
let result = SYSCALL_TABLE[syscall as usize](args);
|
||||
let syscall = &SYSCALL_TABLE[syscall as usize];
|
||||
let mut error = false;
|
||||
if syscall.num_args < 5 && args.arg5 != 0 {
|
||||
error = true;
|
||||
}
|
||||
if syscall.num_args < 4 && args.arg4 != 0 {
|
||||
error = true;
|
||||
}
|
||||
if syscall.num_args < 3 && args.arg3 != 0 {
|
||||
error = true;
|
||||
}
|
||||
if syscall.num_args < 2 && args.arg2 != 0 {
|
||||
error = true;
|
||||
}
|
||||
if syscall.num_args < 1 && args.arg1 != 0 {
|
||||
error = true;
|
||||
}
|
||||
if error {
|
||||
debug!("Process passed invalid syscall arguments");
|
||||
terminate_current_task();
|
||||
}
|
||||
let result = (syscall.func)(args);
|
||||
if result.is_err() {
|
||||
debug!("Error during syscall: {}", result.err().unwrap());
|
||||
terminate_current_task();
|
||||
|
|
Loading…
Add table
Reference in a new issue