[PATCH bpf-next v4 0/3] Fix unaligned enum values in btf_dump

From: Hungyu Lin

Date: Wed Nov 25 2026 - 20:13:23 EST


btf_dump_get_enum_value() reads unaligned enum values through
btf_dump_get_bitfield_value() with a zero bit size, which shifts a
__u64 by 64. Patch 1 copies unaligned enum data into an aligned buffer
instead, as btf_dump_int_data() does. Patch 2 makes the zero check of
enum bitfields read only the bytes of the bitfield, as Alexei suggested
in the v3 review. Patch 3 adds the tests Alexei posted in the v1 review.

Changes in v4:
- Add patch 2 to fix the zero check of enum bitfields (Alexei).

Changes in v3:
- Do the alignment check before the size check (David).

Changes in v2:
- Describe the undefined shift in the commit log.
- Drop the data_end check, which broke the dump of struct fs_context
without emit_zeroes.
- Add the selftests from the v1 review.

v3: https://lore.kernel.org/bpf/20261116080151.44860-1-dennylin0707@xxxxxxxxx/
v2: https://lore.kernel.org/bpf/20261115084923.53182-1-dennylin0707@xxxxxxxxx/
v1: https://lore.kernel.org/bpf/20261113223449.97604-1-dennylin0707@xxxxxxxxx/

Hungyu Lin (3):
libbpf: Fix sign extension of unaligned enums in
btf_dump_get_enum_value()
libbpf: Fix zero detection of enum bitfields in BTF dumper
selftests/bpf: Dump unaligned enums and a zeroed fs_context

tools/lib/bpf/btf_dump.c | 23 ++++++++-----------
.../selftests/bpf/prog_tests/btf_dump.c | 10 +++++++-
2 files changed, 19 insertions(+), 14 deletions(-)


base-commit: 3cbbebf6819b42008e7ef85b6f0a7254c3074c19
--
2.43.0