diff --git a/src/interpreter.rs b/src/interpreter.rs index 13362e80..c854f886 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -183,7 +183,7 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { self.vm.stack_pointer = self.vm.stack_pointer.overflowing_add(insn.imm as u64).0; } - ebpf::LD_DW_IMM => { + ebpf::LD_DW_IMM if self.executable.get_sbpf_version().enable_lddw() => { ebpf::augment_lddw_unchecked(self.program, &mut insn); self.reg[dst] = insn.imm as u64; self.reg[11] += 1; @@ -337,7 +337,7 @@ impl<'a, 'b, C: ContextObject> Interpreter<'a, 'b, C> { ebpf::MOV64_REG => self.reg[dst] = self.reg[src], ebpf::ARSH64_IMM => self.reg[dst] = (self.reg[dst] as i64).wrapping_shr(insn.imm as u32) as u64, ebpf::ARSH64_REG => self.reg[dst] = (self.reg[dst] as i64).wrapping_shr(self.reg[src] as u32) as u64, - ebpf::HOR64_IMM if self.executable.get_sbpf_version().disable_lddw() => { + ebpf::HOR64_IMM if !self.executable.get_sbpf_version().enable_lddw() => { self.reg[dst] |= (insn.imm as u64).wrapping_shl(32); } diff --git a/src/jit.rs b/src/jit.rs index 26c47537..8e3d6e51 100644 --- a/src/jit.rs +++ b/src/jit.rs @@ -329,9 +329,7 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> { // Scan through program to find actual number of instructions let mut pc = 0; - if executable.get_sbpf_version().disable_lddw() { - pc = program.len() / ebpf::INSN_SIZE; - } else { + if executable.get_sbpf_version().enable_lddw() { while (pc + 1) * ebpf::INSN_SIZE <= program.len() { let insn = ebpf::get_insn_unchecked(program, pc); pc += match insn.opc { @@ -339,6 +337,8 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> { _ => 1, }; } + } else { + pc = program.len() / ebpf::INSN_SIZE; } let mut code_length_estimate = MAX_EMPTY_PROGRAM_MACHINE_CODE_LENGTH + MAX_START_PADDING_LENGTH + MAX_MACHINE_CODE_LENGTH_PER_INSTRUCTION * pc; @@ -414,7 +414,7 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> { self.emit_ins(X86Instruction::alu(OperandSize::S64, 0x81, 0, REGISTER_PTR_TO_VM, insn.imm, Some(stack_ptr_access))); } - ebpf::LD_DW_IMM => { + ebpf::LD_DW_IMM if self.executable.get_sbpf_version().enable_lddw() => { self.emit_validate_and_profile_instruction_count(true, Some(self.pc + 2)); self.pc += 1; self.result.pc_section[self.pc] = self.anchors[ANCHOR_CALL_UNSUPPORTED_INSTRUCTION] as usize; @@ -584,7 +584,7 @@ impl<'a, C: ContextObject> JitCompiler<'a, C> { ebpf::MOV64_REG => self.emit_ins(X86Instruction::mov(OperandSize::S64, src, dst)), ebpf::ARSH64_IMM => self.emit_shift(OperandSize::S64, 7, REGISTER_SCRATCH, dst, Some(insn.imm)), ebpf::ARSH64_REG => self.emit_shift(OperandSize::S64, 7, src, dst, None), - ebpf::HOR64_IMM => { + ebpf::HOR64_IMM if !self.executable.get_sbpf_version().enable_lddw() => { self.emit_sanitized_alu(OperandSize::S64, 0x09, 1, dst, (insn.imm as u64).wrapping_shl(32) as i64); } diff --git a/src/program.rs b/src/program.rs index 64752df3..7fce2394 100644 --- a/src/program.rs +++ b/src/program.rs @@ -35,9 +35,9 @@ impl SBPFVersion { self != &SBPFVersion::V1 } - /// Disable the only two slots long instruction: LD_DW_IMM - pub fn disable_lddw(&self) -> bool { - self != &SBPFVersion::V1 + /// Enable the only two slots long instruction: LD_DW_IMM + pub fn enable_lddw(&self) -> bool { + self == &SBPFVersion::V1 } /// Enable the BPF_PQR instruction class diff --git a/src/verifier.rs b/src/verifier.rs index 0f1d5e52..05bef6ff 100644 --- a/src/verifier.rs +++ b/src/verifier.rs @@ -251,7 +251,7 @@ impl Verifier for RequisiteVerifier { } match insn.opc { - ebpf::LD_DW_IMM if !sbpf_version.disable_lddw() => { + ebpf::LD_DW_IMM if sbpf_version.enable_lddw() => { check_load_dw(prog, insn_ptr)?; insn_ptr += 1; }, @@ -329,7 +329,7 @@ impl Verifier for RequisiteVerifier { ebpf::MOV64_REG => {}, ebpf::ARSH64_IMM => { check_imm_shift(&insn, insn_ptr, 64)?; }, ebpf::ARSH64_REG => {}, - ebpf::HOR64_IMM if sbpf_version.disable_lddw() => {}, + ebpf::HOR64_IMM if !sbpf_version.enable_lddw() => {}, // BPF_PQR class ebpf::LMUL32_IMM if sbpf_version.enable_pqr() => {},