From 2491e7d762200520d3ad1da2e89ccccef92b2e66 Mon Sep 17 00:00:00 2001 From: Alan Jowett Date: Tue, 7 May 2024 12:35:06 -0700 Subject: [PATCH] Mark [r1-r5] as invalid on exit Signed-off-by: Alan Jowett --- vm/ubpf_vm.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/vm/ubpf_vm.c b/vm/ubpf_vm.c index 075703b59..3ee959599 100644 --- a/vm/ubpf_vm.c +++ b/vm/ubpf_vm.c @@ -542,13 +542,15 @@ ubpf_validate_shadow_register(const struct ubpf_vm* vm, uint16_t* shadow_registe if (inst.opcode == EBPF_OP_CALL) { // Mark the return address register as initialized. *shadow_registers |= 1 << 0; - // Mark r1-r5 as uninitialized. - *shadow_registers &= ~0x3e; } - if (inst.opcode == EBPF_OP_EXIT && !(*shadow_registers & (1 << 0))) { - vm->error_printf(stderr, "Error: Return address register r0 is not initialized.\n"); - return false; + if (inst.opcode == EBPF_OP_EXIT) { + if (!(*shadow_registers & (1 << 0))) { + vm->error_printf(stderr, "Error: Return address register r0 is not initialized.\n"); + return false; + } + // Mark r1-r5 as uninitialized. + *shadow_registers &= ~0x3e; } return true; @@ -933,7 +935,7 @@ ubpf_exec(const struct ubpf_vm* vm, void* mem, size_t mem_len, uint64_t* bpf_ret } break; case EBPF_OP_JEQ32_REG: - if (u32(reg[inst.dst]) == reg[inst.src]) { + if (u32(reg[inst.dst]) == u32(reg[inst.src])) { pc += inst.offset; } break;