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

Removing check SHIFT immediate number from verifier #561

Open
shenghaoyuan opened this issue May 6, 2024 · 2 comments
Open

Removing check SHIFT immediate number from verifier #561

shenghaoyuan opened this issue May 6, 2024 · 2 comments

Comments

@shenghaoyuan
Copy link

Hi,
could we remove all check_imm_shift from the verifier, or do this checking during JIT's emit_shift?

ebpf::LSH32_IMM  => { check_imm_shift(&insn, insn_ptr, 32)?; },

For the interpreter, the wrapping_shl has ensured imm%64 or imm%32.

ebpf::LSH32_IMM  => self.reg[dst] = (self.reg[dst] as u32).wrapping_shl(insn.imm as u32)      as u64,
ebpf::LSH32_REG  => self.reg[dst] = (self.reg[dst] as u32).wrapping_shl(self.reg[src] as u32) as u64,

BTW, I don't find how the JIT emit_shift does src%32 in the X64 code for rbpf shl_reg instruction (sorry, I am not familiar with x86 ISA if this is a stupid question).

@Lichtso
Copy link

Lichtso commented May 18, 2024

Is there a specific need for this?
Generally we can't just remove verification steps and add them to the JIT only, because then the Interpreter and JIT could disagree.

@shenghaoyuan
Copy link
Author

Hello Lichtso,
The interpreter has a wrapping semantics, e.g. LSH32_IMM does imm%32, so rbpf could do the same wrapping operation imm%32 during the JIT process. In this case, the shift verification step could be removed.
The current way is OK: someone may confuse that the shift verification step in verifier and the wrapping semantics in interpreter are overlapping.
Best,
Shenghao

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

No branches or pull requests

2 participants