Skip to content

Conversation

@kernel-patches-daemon-bpf
Copy link

Pull request for series with
subject: Multi-split BTF fixes and test
version: 3
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1016942

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 54c134f
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1016942
version: 3

@kernel-patches-review-bot
Copy link

commit 9da54f1ee8589391857dcb28c0dbc65a8e6632ea
Author: Alan Maguire <[email protected]>

selftests/bpf: Test parsing of (multi-)split BTF

This patch adds a test that writes raw BTF data to files, parses it
back, and compares the parsed BTF to the original to verify correctness
of the BTF parsing code.

> diff --git a/tools/testing/selftests/bpf/prog_tests/btf_split.c b/tools/testing/selftests/bpf/prog_tests/btf_split.c
> index 3696fb9a0..b07a91ff2 100644
> --- a/tools/testing/selftests/bpf/prog_tests/btf_split.c
> +++ b/tools/testing/selftests/bpf/prog_tests/btf_split.c

[ ... ]

> @@ -123,6 +157,38 @@ static void __test_btf_split(bool multi)
>  "	int uf2;\n"
>  "};\n\n", "c_dump");
>
> +	/* write base, split BTFs to files and ensure parsing succeeds */
> +	base_btf_sz = btf_raw_write(btf1, base_btf_file);
> +	if (base_btf_sz < 0)
> +		goto cleanup;
> +	split_btf_sz = btf_raw_write(btf2, split_btf_file);
> +	if (split_btf_sz < 0)
> +		goto cleanup;
> +	btf4 = btf__parse(base_btf_file, NULL);
> +	if (!ASSERT_OK_PTR(btf4, "parse_base"))
> +		goto cleanup;
> +	btf5 = btf__parse_split(split_btf_file, btf4);
> +	if (!ASSERT_OK_PTR(btf5, "parse_split"))
> +		goto cleanup;
> +	if (multi) {
> +		multisplit_btf_sz = btf_raw_write(btf3, multisplit_btf_file);
> +		if (multisplit_btf_sz < 0)
> +			goto cleanup;
> +		btf6 = btf__parse_split(multisplit_btf_file, btf5);
> +		if (!ASSERT_OK_PTR(btf6, "parse_multisplit"))
> +			goto cleanup;
> +	} else {
> +		btf6 = btf5;
> +	}
> +
> +	/* compare parsed to original BTF */
> +	for (i = 1; i < btf__type_cnt(btf6); i++) {
> +		t = btf__type_by_id(btf6, i);
> +		ot = btf__type_by_id(btf3, i);
> +		if (!ASSERT_EQ(memcmp(t, ot, sizeof(*ot)), 0, "cmp_parsed_orig_btf"))
> +			goto cleanup;
> +	}
> +

Can btf__type_by_id return NULL here in the comparison loop? The loop
iterates based on btf6's type count, but accesses types in both btf6
and btf3. If btf6 has more types than btf3 (indicating a parsing bug),
then btf__type_by_id(btf3, i) will return NULL when i exceeds btf3's
type count, leading to a NULL dereference in memcmp.

Other btf__type_by_id calls in this function (see earlier uses) check
the return value with ASSERT_OK_PTR before dereferencing. Should this
code either verify the type counts match first, or check these return
values to maintain consistency with the rest of the function?

>  cleanup:
> 	if (dump_buf_file)
> 		fclose(dump_buf_file);

[ ... ]



AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

In-Reply-To-Subject: selftests/bpf: Test parsing of (multi-)split BTF
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/18891682588

@kernel-patches-daemon-bpf
Copy link
Author

Forwarding comment 3458953736 via email
In-Reply-To: [email protected]
Patch: https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: e2e668b
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1016942
version: 3

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 5701d5a
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1016942
version: 3

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: ab01bfa
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1016942
version: 3

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: e6e10c5
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1016942
version: 3

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 5dae745
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1016942
version: 3

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 11369e6
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1016942
version: 3

When creating multi-split BTF we correctly set the start string offset
to be the size of the base string section plus the base BTF start
string offset; the latter is needed for multi-split BTF since the
offset is non-zero there.

Unfortunately the BTF parsing case needed that logic and it was
missed.

Fixes: 4e29128 ("libbpf/btf: Fix string handling to support multi-split BTF")
Signed-off-by: Alan Maguire <[email protected]>
Write raw BTF to files, parse it and compare to original;
this allows us to test parsing of (multi-)split BTF code.

Signed-off-by: Alan Maguire <[email protected]>
@kernel-patches-daemon-bpf
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=1016942 expired. Closing PR.

@kernel-patches-daemon-bpf kernel-patches-daemon-bpf bot deleted the series/1016942=>bpf-next branch November 7, 2025 01:01
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.

2 participants