Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:BTF (BPF Type Format)

From ReverseEngineering.wiki
Format
On this wiki Facts · Code · Notes · Topics

Compact type-information format of the Linux kernel and eBPF: a .BTF section (and /sys/kernel/btf/vmlinux) starting with the 16-bit magic 0xEB9F, a header with type and string sections, and 20 type kinds (int, ptr, struct, enum, func, datasec) described by a 12-byte btf_type.

Identification

  • Magic 0xEB9F as a 16-bit value in the file's byte order: bytes 9F EB in little-endian files, EB 9F in big-endian. Version byte 1. Fact:BTF (BPF Type Format)/magic/BTF magic.
  • Lives in the ELF section .BTF of vmlinux, kernel modules (Format:Linux kernel module (.ko)) and BPF object files; the running kernel exposes it raw in /sys/kernel/btf/vmlinux (modules: /sys/kernel/btf/<module>).
  • Companion sections: .BTF.ext (func_info, line_info, CO-RE relocations of BPF objects), .BTF_ids (BTF ID lists and sets used inside the kernel), .BTF.base (minimal base types so split BTF of a module survives a rebuilt base).

Header

Fact:BTF (BPF Type Format)/struct/btf header. Read hdr_len instead of assuming a header size. type_off and str_off count from the end of the header.

Types

Types are numbered from 1 in section order (id 0 is void). Each starts with a 12-byte btf_type (Fact:BTF (BPF Type Format)/struct/btf type) followed by vlen kind-specific entries. Names are offsets into the string section (offset 0 is the empty string). Kinds: Fact:BTF (BPF Type Format)/enum/BTF kinds.

Use in reverse engineering

  • A kernel built with CONFIG_DEBUG_INFO_BTF carries full struct layouts (field names, byte and bit offsets) without DWARF; dump with bpftool btf dump file /sys/kernel/btf/vmlinux or parse the section.
  • Function prototypes: BTF_KIND_FUNC points to a FUNC_PROTO. Global variables: VAR entries listed by a DATASEC (one per ELF section, with offset and size of each variable).

Code & repositories

  • https://github.com/torvalds/linux @ 32c52ec87d6245ee2d12ed5dd509e40062939b50 · license: GPL-2.0 WITH Linux-syscall-note (read from COPYING; GitHub's detector did not classify it)
    Linux kernel sources (GPL-2.0): Documentation/arch/x86/boot.rst, include/uapi/linux/btf.h, include/linux/module.h, vermagic.h, export.h, scripts/kallsyms.c, scripts/mod/modpost.c, scripts/extract-vmlinux
    Tested on: source read, not run: not run; source read at the pinned commit · checked 2026-10-18; last activity 2026-10-18

Pitfalls

  • New kinds appeared over time (FLOAT 16, DECL_TAG 17, TYPE_TAG 18, ENUM64 19); a parser must size unknown kinds or fail clearly.
  • For struct/union with kind_flag set, a member's offset packs the bitfield size in the top 8 bits and the bit offset in the low 24.

Sources: Documentation/bpf/btf.rst, include/uapi/linux/btf.h. See Platform:Linux kernel.