Closed mat-1 closed 2 weeks ago
I may have made this issue a bit too early, I realized libbpf-sys does vendor libbpf so the system's libbpf version is irrelevant.
It seems like the actual reason it was linking with libbpf 1.4 instead of 1.5 is because my program also depends on xsk-rs which depends on libxdp-sys which links xdp-tools's version of libbpf which is still 1.4.
Yeah, vendoring is the default and then there should not be any issue (well, in the usual case). But given that we support usage of the system libbpf
, we should see if we can fix the code. I think this is pretty much the libbpf-rs
equivalent of https://github.com/libbpf/libbpf/commit/bf7ddbef99d0c1e597c12b8b64ccd0c4d0c70282 on the libbpf
side (at least from a quick glance)... :-(
I no longer believe there is an issue in libbpf-rs
. The segfault is happening in libbpf
and as per my experimentation it's caused by a lack of https://github.com/libbpf/libbpf/commit/bf7ddbef99d0c1e597c12b8b64ccd0c4d0c70282. Please update your system library to a version that includes this patch. It has been backported to various lower minor versions. There is nothing else we can do.
I'm making this issue as reference for anyone else that ran into the same issue since it took me several hours to figure out what was going on, I'm not sure if there's a good solution that this library should take. :sweat_smile:
libbpf-rs
currently depends onlibbpf-sys
1.4.1, but the Rust dependency resolver just matches2.0.0 > version >= 1.4.1
for that, so it uses 1.5.0 instead.libbpf 1.4.x has a struct that looks like:
In libbpf 1.5.0 (which released a few days ago), the struct was updated with an additional field:
The
bpf_map_skeleton
s are stored in an array. This means if your program has more than one map, and your system is using libbpf 1.4.x, and your libbpf-sys version is 1.5.x, it'll write the 4 fields for each map but then only read 3, resulting in a null dereference when reading the second map's name (since bpf_link is left as a null pointer).My solution ended up being to force libbpf-sys to version 1.4.1 in the Cargo.toml: