]> git.ipfire.org Git - thirdparty/linux.git/commit
selftests/bpf: Fix tld_get_data() returning garbage data
authorAmery Hung <ameryhung@gmail.com>
Mon, 13 Apr 2026 19:02:58 +0000 (12:02 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 15 Apr 2026 19:10:20 +0000 (12:10 -0700)
commit615e55a2418405b628921e0596ac50317fd04474
treebbec609bc0bfa1fb557cf59f04e712af2ced0ff8
parent36bf7beb9d23bfe7feba6f376a0c13ed7b670cf8
selftests/bpf: Fix tld_get_data() returning garbage data

BPF side tld_get_data() currently may return garbage when tld_data_u is
not aligned to page_size. This can happen when small amount of memory
is allocated for tld_data_u. The misalignment is supposed to be allowed
and the BPF side will use tld_data_u->start to reference the tld_data_u
in a page. However, since "start" is within tld_data_u, there is no way
to know the correct "start" in the first place. As a result, BPF
programs will see garbage data. The selftest did not catch this since
it tries to allocate the maximum amount of data possible (i.e., a page)
such that tld_data_u->start is always correct.

Fix it by moving tld_data_u->start to tld_data_map->start. The original
field is now renamed as unused instead of removing it because BPF side
tld_get_data() views off = 0 returned from tld_fetch_key() as
uninitialized.

Signed-off-by: Amery Hung <ameryhung@gmail.com>
Link: https://lore.kernel.org/r/20260413190259.358442-3-ameryhung@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/task_local_data.h
tools/testing/selftests/bpf/progs/task_local_data.bpf.h