lib: bpf: require BTF data len on bf_bpf_btf_load()#425
lib: bpf: require BTF data len on bf_bpf_btf_load()#425qdeslandes merged 1 commit intofacebook:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the libbpfilter BTF load wrapper to require callers to provide the BTF blob length, and propagates the new function signature across internal call sites and unit tests.
Changes:
- Extend
bf_bpf_btf_load()to accept abtf_data_lenargument and pass it through to the kernel viaattr.btf_size. - Update bpfilter map BTF generation code to pass the raw BTF size when loading.
- Update unit tests to use the new
bf_bpf_btf_load()signature.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/unit/libbpfilter/bpf.c | Updates unit tests to call bf_bpf_btf_load() with the new length parameter. |
| src/libbpfilter/include/bpfilter/bpf.h | Updates the public API signature and adds a doc entry for the new length parameter. |
| src/libbpfilter/bpf.c | Implements the new parameter by setting attr.btf_size from btf_data_len. |
| src/bpfilter/cgen/prog/map.c | Passes the raw BTF blob size to bf_bpf_btf_load() when loading generated BTF. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -185,6 +185,7 @@ int bf_bpf_btf_load(const void *btf_data, int token_fd) | |||
| memset(&attr, 0, sizeof(attr)); | |||
|
|
|||
| attr.btf = bf_ptr_to_u64(btf_data); | |||
| attr.btf_size = btf_data_len; | |||
There was a problem hiding this comment.
btf_data_len is accepted as size_t, but it gets assigned directly into attr.btf_size (a __u32 in linux/bpf.h). On 64-bit this can silently truncate for large BTF blobs and cause the kernel to read an incorrect size. Consider validating btf_data_len (e.g., >0 and <= UINT32_MAX) and either returning a negative errno (like -EINVAL/-E2BIG) or asserting, then cast explicitly when assigning to attr.btf_size.
No description provided.