Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assembler: register inconsistency #562

Closed
shenghaoyuan opened this issue May 6, 2024 · 3 comments · Fixed by #571
Closed

assembler: register inconsistency #562

shenghaoyuan opened this issue May 6, 2024 · 3 comments · Fixed by #571

Comments

@shenghaoyuan
Copy link

Hi,

The register checking of assembler should be consistent with that of verifier

  • dst should be [0,10] or [0,11] !(0..16).contains(&dst) -> dst < 0 || dst > 11 or ...
  • src should be [0, 9], dst < 0 || src >= 16 -> src < 0 || src > 10
///assembler
    fn insn(opc: u8, dst: i64, src: i64, off: i64, imm: i64) -> Result<Insn, String> {
    if !(0..16).contains(&dst) {
        return Err(format!("Invalid destination register {dst}"));
    }
    if dst < 0 || src >= 16 {
        return Err(format!("Invalid source register {src}"));
    }
///verifier  
    if insn.src > 10 {
        return Err(VerifierError::InvalidSourceRegister(insn_ptr));
    }

    match (insn.dst, store) {
        (0..=9, _) | (10, true) => Ok(()),
        (11, _) if sbpf_version.dynamic_stack_frames() && insn.opc == ebpf::ADD64_IMM => Ok(()),
        (10, false) => Err(VerifierError::CannotWriteR10(insn_ptr)),
        (_, _) => Err(VerifierError::InvalidDestinationRegister(insn_ptr)),
    }
@Lichtso
Copy link

Lichtso commented May 23, 2024

The reason that the disassembler has these limits is because that is what the instruction encoding supports and what a compiler could produce. The verifier then narrows it down to what the vm actually supports.

@Lichtso Lichtso closed this as completed May 23, 2024
@shenghaoyuan
Copy link
Author

shenghaoyuan commented May 23, 2024

@Lichtso THX for your reply. But is there a typo? dst < 0 || src >= 16 should be src < 0 || src >= 16

@Lichtso
Copy link

Lichtso commented May 23, 2024

Ah yes you are right, let me fix that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants