rust-bpf / rust-bcc

user-friendly rust bindings for the bpf compiler collection
MIT License
475 stars 54 forks source link

ptr::read on possible misaligned ptr #169

Closed Connor1996 closed 3 years ago

Connor1996 commented 3 years ago

The key and value are from on-stack Vec<u8>. Maybe the Vec isn't aligned with the type of key and value. https://github.com/rust-bpf/rust-bcc/blob/c4e5ef83568b220c8bf271a6f80e9579b2df1e5e/src/table.rs#L160

Using std::ptr::read on these misaligned ptrs may cause trouble. Should it use std::ptr::read_unalign instead? https://github.com/rust-bpf/rust-bcc/blob/f28fa173f8b9e6cac28924105049dc8c37e8e780/examples/contextswitch.rs#L160

brayniac commented 3 years ago

I think you're right. Would accept a PR that changes these to read_unaligned in the examples.