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

Commit 5aab2cd

Browse files
committed
Changes the default text_section_vaddr.
1 parent cbc12d4 commit 5aab2cd

File tree

3 files changed

+31
-63
lines changed

3 files changed

+31
-63
lines changed

src/debugger.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,6 @@ fn get_host_ptr<C: ContextObject>(
153153
interpreter: &mut Interpreter<C>,
154154
mut vm_addr: u64,
155155
) -> Result<*mut u8, EbpfError> {
156-
if vm_addr < ebpf::MM_RODATA_START {
157-
vm_addr += ebpf::MM_RODATA_START;
158-
}
159156
match interpreter.vm.memory_mapping.map(
160157
AccessType::Load,
161158
vm_addr,

src/elf.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,11 @@ impl<C: ContextObject> Executable<C> {
356356
elf_bytes,
357357
sbpf_version,
358358
ro_section: Section::Borrowed(ebpf::MM_RODATA_START as usize, 0..text_bytes.len()),
359-
text_section_vaddr: ebpf::MM_RODATA_START,
359+
text_section_vaddr: if sbpf_version.enable_elf_vaddr() {
360+
ebpf::MM_BYTECODE_START
361+
} else {
362+
ebpf::MM_RODATA_START
363+
},
360364
text_section_range: 0..text_bytes.len(),
361365
entry_pc,
362366
function_registry,

tests/execution.rs

Lines changed: 26 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,17 +2389,15 @@ fn test_callx() {
23892389
test_interpreter_and_jit_asm!(
23902390
"
23912391
mov64 r0, 0x0
2392-
mov64 r8, 0x1
2393-
lsh64 r8, 0x20
2394-
or64 r8, 0x30
2392+
or64 r8, 0x20
23952393
callx r8
23962394
exit
23972395
function_foo:
23982396
mov64 r0, 0x2A
23992397
exit",
24002398
[],
24012399
(),
2402-
TestContextObject::new(8),
2400+
TestContextObject::new(6),
24032401
ProgramResult::Ok(42),
24042402
);
24052403
}
@@ -2409,27 +2407,30 @@ fn test_err_callx_unregistered() {
24092407
test_interpreter_and_jit_asm!(
24102408
"
24112409
mov64 r0, 0x0
2412-
mov64 r8, 0x1
2413-
lsh64 r8, 0x20
2414-
or64 r8, 0x30
2410+
or64 r8, 0x20
24152411
callx r8
24162412
exit
24172413
mov64 r0, 0x2A
24182414
exit",
24192415
[],
24202416
(),
2421-
TestContextObject::new(6),
2417+
TestContextObject::new(4),
24222418
ProgramResult::Err(EbpfError::UnsupportedInstruction),
24232419
);
24242420
}
24252421

24262422
#[test]
24272423
fn test_err_callx_oob_low() {
2424+
let config = Config {
2425+
enabled_sbpf_versions: SBPFVersion::V1..=SBPFVersion::V1,
2426+
..Config::default()
2427+
};
24282428
test_interpreter_and_jit_asm!(
24292429
"
24302430
mov64 r0, 0x3
24312431
callx r0
24322432
exit",
2433+
config,
24332434
[],
24342435
(),
24352436
TestContextObject::new(2),
@@ -2518,14 +2519,12 @@ fn test_err_reg_stack_depth() {
25182519
};
25192520
test_interpreter_and_jit_asm!(
25202521
"
2521-
mov64 r0, 0x1
2522-
lsh64 r0, 0x20
25232522
callx r0
25242523
exit",
25252524
config,
25262525
[],
25272526
(),
2528-
TestContextObject::new(max_call_depth as u64 * 3),
2527+
TestContextObject::new(max_call_depth as u64),
25292528
ProgramResult::Err(EbpfError::CallDepthExceeded),
25302529
);
25312530
}
@@ -2765,9 +2764,7 @@ fn test_tight_infinite_recursion() {
27652764
fn test_tight_infinite_recursion_callx() {
27662765
test_interpreter_and_jit_asm!(
27672766
"
2768-
mov64 r8, 0x1
2769-
lsh64 r8, 0x20
2770-
or64 r8, 0x28
2767+
or64 r8, 0x18
27712768
call function_foo
27722769
exit
27732770
function_foo:
@@ -2776,7 +2773,7 @@ fn test_tight_infinite_recursion_callx() {
27762773
exit",
27772774
[],
27782775
(),
2779-
TestContextObject::new(8),
2776+
TestContextObject::new(6),
27802777
ProgramResult::Err(EbpfError::ExceededMaxInstructions),
27812778
);
27822779
}
@@ -2815,27 +2812,6 @@ fn test_err_instruction_count_syscall_capped() {
28152812
);
28162813
}
28172814

2818-
#[test]
2819-
fn test_non_terminate_early() {
2820-
test_interpreter_and_jit_asm!(
2821-
"
2822-
mov64 r6, 0x0
2823-
mov64 r1, 0x0
2824-
mov64 r2, 0x0
2825-
mov64 r3, 0x0
2826-
mov64 r4, 0x0
2827-
mov64 r5, r6
2828-
callx r6
2829-
add64 r6, 0x1
2830-
ja -0x8
2831-
exit",
2832-
[],
2833-
(),
2834-
TestContextObject::new(7),
2835-
ProgramResult::Err(EbpfError::CallOutsideTextSegment),
2836-
);
2837-
}
2838-
28392815
#[test]
28402816
fn test_err_non_terminate_capped() {
28412817
test_interpreter_and_jit_asm!(
@@ -2882,31 +2858,27 @@ fn test_err_non_terminate_capped() {
28822858
fn test_err_capped_before_exception() {
28832859
test_interpreter_and_jit_asm!(
28842860
"
2885-
mov64 r1, 0x0
2886-
mov64 r2, 0x0
2887-
add64 r0, 0x0
2888-
add64 r0, 0x0
2861+
mov64 r0, 0x0
2862+
add64 r2, 0x0
28892863
udiv64 r1, r2
28902864
add64 r0, 0x0
28912865
exit",
28922866
[],
28932867
(),
2894-
TestContextObject::new(4),
2868+
TestContextObject::new(2),
28952869
ProgramResult::Err(EbpfError::ExceededMaxInstructions),
28962870
);
28972871

28982872
test_interpreter_and_jit_asm!(
28992873
"
2900-
mov64 r1, 0x0
2901-
mov64 r2, 0x0
2902-
add64 r0, 0x0
2903-
add64 r0, 0x0
2874+
mov64 r0, 0x0
2875+
hor64 r2, 0x1
29042876
callx r2
29052877
add64 r0, 0x0
29062878
exit",
29072879
[],
29082880
(),
2909-
TestContextObject::new(4),
2881+
TestContextObject::new(2),
29102882
ProgramResult::Err(EbpfError::ExceededMaxInstructions),
29112883
);
29122884
}
@@ -2915,33 +2887,29 @@ fn test_err_capped_before_exception() {
29152887
fn test_err_exit_capped() {
29162888
test_interpreter_and_jit_asm!(
29172889
"
2918-
mov64 r1, 0x1
2919-
lsh64 r1, 0x20
2920-
or64 r1, 0x28
2921-
callx r1
2890+
or64 r0, 0x18
2891+
callx r0
29222892
exit
29232893
function_foo:
29242894
exit
29252895
",
29262896
[],
29272897
(),
2928-
TestContextObject::new(5),
2898+
TestContextObject::new(3),
29292899
ProgramResult::Err(EbpfError::ExceededMaxInstructions),
29302900
);
29312901
test_interpreter_and_jit_asm!(
29322902
"
2933-
mov64 r1, 0x1
2934-
lsh64 r1, 0x20
2935-
or64 r1, 0x28
2936-
callx r1
2903+
or64 r0, 0x18
2904+
callx r0
29372905
exit
29382906
function_foo:
29392907
mov r0, r0
29402908
exit
29412909
",
29422910
[],
29432911
(),
2944-
TestContextObject::new(6),
2912+
TestContextObject::new(4),
29452913
ProgramResult::Err(EbpfError::ExceededMaxInstructions),
29462914
);
29472915
test_interpreter_and_jit_asm!(
@@ -2970,13 +2938,12 @@ fn test_far_jumps() {
29702938
.fill 1024, 0x0F
29712939
exit
29722940
function_c:
2973-
mov32 r1, 0x00000010
2974-
hor64 r1, 0x00000001
2941+
mov32 r1, 0x10
29752942
callx r1
29762943
exit",
29772944
[],
29782945
(),
2979-
TestContextObject::new(7),
2946+
TestContextObject::new(6),
29802947
ProgramResult::Ok(0),
29812948
);
29822949
}

0 commit comments

Comments
 (0)