Skip to content

lib: bpf: require BTF data len on bf_bpf_btf_load()#425

Merged
qdeslandes merged 1 commit intofacebook:mainfrom
qdeslandes:load_btf_data
Feb 18, 2026
Merged

lib: bpf: require BTF data len on bf_bpf_btf_load()#425
qdeslandes merged 1 commit intofacebook:mainfrom
qdeslandes:load_btf_data

Conversation

@qdeslandes
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings February 18, 2026 11:35
@meta-cla meta-cla bot added the cla signed label Feb 18, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 a btf_data_len argument and pass it through to the kernel via attr.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.

Comment on lines 179 to 188
@@ -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;
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@qdeslandes qdeslandes merged commit 72ad857 into facebook:main Feb 18, 2026
35 checks passed
@qdeslandes qdeslandes deleted the load_btf_data branch February 18, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments