Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Tests - Increases Config::max_call_depth default from 20 to 64 #574

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Config {
impl Default for Config {
fn default() -> Self {
Self {
max_call_depth: 20,
max_call_depth: 64,
stack_frame_size: 4_096,
enable_address_translation: true,
enable_stack_frame_gaps: true,
Expand Down
108 changes: 60 additions & 48 deletions tests/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1987,8 +1987,6 @@ fn test_err_dynamic_stack_out_of_bound() {

#[test]
fn test_err_dynamic_stack_ptr_overflow() {
let config = Config::default();

// See the comment in CallFrames::resize_stack() for the reason why it's
// safe to let the stack pointer overflow

Expand All @@ -1999,13 +1997,12 @@ fn test_err_dynamic_stack_ptr_overflow() {
add r11, -0x7FFFFFFF
add r11, -0x7FFFFFFF
add r11, -0x7FFFFFFF
add r11, -0x14005
add r11, -0x40005
call function_foo
exit
function_foo:
stb [r10], 0
exit",
config,
[],
(),
TestContextObject::new(7),
Expand Down Expand Up @@ -2325,54 +2322,69 @@ fn test_err_callx_oob_high() {

#[test]
fn test_bpf_to_bpf_depth() {
test_interpreter_and_jit_asm!(
"
ldxb r1, [r1]
add64 r1, -2
call function_foo
exit
function_foo:
jeq r1, 0, +2
add64 r1, -1
call function_foo
exit",
[Config::default().max_call_depth as u8],
(),
TestContextObject::new(78),
ProgramResult::Ok(0),
);
// The instruction count is lower here because all the `exit`s never run
test_interpreter_and_jit_asm!(
"
ldxb r1, [r1]
add64 r1, -2
call function_foo
exit
function_foo:
jeq r1, 0, +2
add64 r1, -1
call function_foo
exit",
[Config::default().max_call_depth as u8 + 1],
(),
TestContextObject::new(60),
ProgramResult::Err(EbpfError::CallDepthExceeded),
);
for max_call_depth in [20usize, Config::default().max_call_depth] {
let config = Config {
max_call_depth,
..Config::default()
};
test_interpreter_and_jit_asm!(
"
ldxb r1, [r1]
add64 r1, -2
call function_foo
exit
function_foo:
jeq r1, 0, +2
add64 r1, -1
call function_foo
exit",
config,
[max_call_depth as u8],
(),
TestContextObject::new(max_call_depth as u64 * 4 - 2),
ProgramResult::Ok(0),
);
// The instruction count is lower here because all the `exit`s never run
test_interpreter_and_jit_asm!(
"
ldxb r1, [r1]
add64 r1, -2
call function_foo
exit
function_foo:
jeq r1, 0, +2
add64 r1, -1
call function_foo
exit",
config,
[max_call_depth as u8 + 1],
(),
TestContextObject::new(max_call_depth as u64 * 3),
ProgramResult::Err(EbpfError::CallDepthExceeded),
);
}
}

#[test]
fn test_err_reg_stack_depth() {
test_interpreter_and_jit_asm!(
"
mov64 r0, 0x1
lsh64 r0, 0x20
callx r0
exit",
[],
(),
TestContextObject::new(60),
ProgramResult::Err(EbpfError::CallDepthExceeded),
);
for max_call_depth in [20usize, Config::default().max_call_depth] {
let config = Config {
max_call_depth,
..Config::default()
};
test_interpreter_and_jit_asm!(
"
mov64 r0, 0x1
lsh64 r0, 0x20
callx r0
exit",
config,
[],
(),
TestContextObject::new(max_call_depth as u64 * 3),
ProgramResult::Err(EbpfError::CallDepthExceeded),
);
}
}

// CALL_IMM : Syscalls
Expand Down