eBPF byte code and x64 machine code equivalence #300
Replies: 9 comments 3 replies
-
There is no such guarantee - even if you assume correct compilation to both EBPF and x86, which the eBPF system does not. |
Beta Was this translation helpful? Give feedback.
-
To take an easy example, if the LLVM code has undefined behavior (e.g. illegal memory access) the compiler is allowed to emit anything. Including safe eBPF code and unsafe x86 code. |
Beta Was this translation helpful? Give feedback.
-
Thanks, appreciate the feedback. Two follow up questions:
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Maybe if the original LLVM program is somehow guaranteed to be deterministic on any input, then safety of the eBPF code would also imply safety of the original LLVM code - for some definition of safety. This would require, in particular, absence of UB in the LLVM code. |
Beta Was this translation helpful? Give feedback.
-
Note that eBPF is specifically designed to be easily compiled directly to x86/ARM machine code. If it is compiled to LLVM first, then its design is very far from ideal, from verification perspective. |
Beta Was this translation helpful? Give feedback.
-
Thanks, I appreciate the feedback. Was hoping we could leverage LLVM's code generation, but it sounds like this is would be problematic. |
Beta Was this translation helpful? Give feedback.
-
Hello @elazarg, jumping in here. I want to go back to Alan-Jowett's 2nd question above. The question was, if I understood it correctly, whether in a flow of [verified eBPF bytecode] -> [LLVM IR] -> [x86 machine code] the safety properties demonstrated for the eBPF bytecode could be safely assumed applicable to the x86 output. I believe you answered this should hold in your opinion, so long as the conversion to LLVM IR was done properly. My follow-up question is if this is true in both directions. If the flow were [x86 machine code] -> [LLVM IR] -> [verified eBPF bytecode], in your opinion, could the safety properties demonstrated for the eBPF bytecode be safely assumed applicable to the x86 input? |
Beta Was this translation helpful? Give feedback.
-
Thank you for the feedback, @elazarg. I am currently examining the feasibility of generating C code from the eBPF byte code, with each eBPF instruction translating into the code that the interpreter would have run for that instruction (essentially unwind the loop of the interpreter). I think this should be preserve the safety properties of the eBPF program (as much as an interpreter would have). microsoft/ebpf-for-windows#757 Sample generated C looks like this: |
Beta Was this translation helpful? Give feedback.
-
Prevail folks,
Assuming I have a block of eBPF byte code and a block of x64 machine code, both generated from the same LLVM IR, would it be reasonable to assume safety properties proven using prevail on the eBPF byte code would still hold for the same x64 machine code?
Specifically, given:
Is is reasonable to assume that safety properties that are proven for foo_ebpf.o apply equally to foo_x64.o?
Beta Was this translation helpful? Give feedback.
All reactions