Closed qmonnet closed 1 year ago
Fixed with https://github.com/qmonnet/rbpf/commit/a339ce81927279f747ee66f6a5b0f15947daba09 from #78, but it would be great to find a solution to re-enable the asserts. Leaving the issue open in the meantime.
It looks to me like the offending code is this: https://github.com/qmonnet/rbpf/blob/196e5375896cc17870f38f6f23b7f7b3c755a16a/src/jit.rs#L81-L82
This could do ptr.write_unaligned($data);
I'm not sure what you mean by
we do support unaligned memory access in rbpf at this time
The checks are inserted as part of compiling the Rust code that is the JIT itself, so I don't think the semantics of BPF here are relevant, right? I feel like I must be misunderstanding something here.
Hi Ben, thanks a lot for helping!
I feel like I must be misunderstanding something here.
This would be entirely possible, my experience with coding with Rust is limited to this project :)
In this case, let me explain more: in rbpf, we have two ways to execute eBPF code, the interpreter (contained in src/lib.rs) and the JIT-compiler (srs/jit.rs). I tested your suggestion to use ptr.write_unaligned($data);
for the JIT-compiler, and it works well indeed for taming the asserts that appear when compiling the JIT itself, and fixes a number of tests :tada:. I'll push a PR with this change [edit: #80, now merged].
Then I've also observed error messages referring to the interpreter, and related to the tests using the interpreter for the eBPF programs, in particular the instructions for loading multiple bytes of memory into registers: ebpf::LD_H_REG
/ebpf::LD_W_REG
/ebpf::LD_DW_REG
, around this line. This is what I was referring to earlier. Maybe there's a similar trick to use here with write_unaligned()
or something else to tell Rust that these are possibly not aligned, I need to look more into it.
Tests consistently fail with recent versions of the toolchain, with messages such as:
Full error message
``` Running tests/misc.rs (target/debug/deps/misc-6f56f75d4e6d43c9) running 20 tests thread 'test_jit_mbuff' panicked at 'misaligned pointer dereference: address must be a multiple of 0x4 but is 0x7f8038001011', src/jit.rs:100:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace thread 'test_jit_mbuff' panicked at 'panic in a function that cannot unwind', library/core/src/panicking.rs:126:5 stack backtrace: 0: 0x562d63bf4351 - std::backtrace_rs::backtrace::libunwind::trace::h28494931c73179b2 at /rustc/2f6bc5d259e7ab25ddfdd33de53b892770218918/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x562d63bf4351 - std::backtrace_rs::backtrace::trace_unsynchronized::h9032c52edccf7bd1 at /rustc/2f6bc5d259e7ab25ddfdd33de53b892770218918/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x562d63bf4351 - std::sys_common::backtrace::_print_fmt::hd90562e967f4e4e1 at /rustc/2f6bc5d259e7ab25ddfdd33de53b892770218918/library/std/src/sys_common/backtrace.rs:65:5 3: 0x562d63bf4351 -This seems to be a consequence of https://github.com/rust-lang/rust/pull/98112.
As an easy “fix”, we can disable debug assertions for the tests, but we risk introducing more bugs. Not sure how to fix it otherwise, given that we do support unaligned memory access in rbpf at this time.