solana-labs / rbpf

Rust virtual machine and JIT compiler for eBPF programs
Apache License 2.0
277 stars 169 forks source link

Interpreter LD_DW_IMM: add `!sbpf_version.disable_lddw()` checking #563

Closed shenghaoyuan closed 5 months ago

shenghaoyuan commented 5 months ago

Hi, I wonder if the interpreter could add a checking before executing LD_DW_IMM if SBF enables or disables the LD_DW_IMM instruction.

//interpreter.rs
            ebpf::LD_DW_IMM  => {
                ebpf::augment_lddw_unchecked(self.program, &mut insn);
                self.reg[dst] = insn.imm as u64;
                self.reg[11] += 1;
                next_pc += 1;
            },

The new code may be:

//interpreter.rs
            ebpf::LD_DW_IMM  if !self.executable.get_sbpf_version().disable_lddw() => {
                ebpf::augment_lddw_unchecked(self.program, &mut insn);
                self.reg[dst] = insn.imm as u64;
                self.reg[11] += 1;
                next_pc += 1;
            },