[PATCH v3 2/3] libbpf: zero out btf_key_type_id for STRUCT_OPS maps

From: Siddharth Nayyar

Date: Tue May 26 2026 - 10:20:52 EST


For BPF `STRUCT_OPS` maps (such as `sched_ext_ops` maps), the kernel BPF
subsystem enforces strict map-creation safety validations inside
`map_create()`. That is, if `btf_vmlinux_value_type_id` is set, the
kernel forbids passing any userspace `btf_key_type_id` or
`btf_value_type_id` (they must both be `0`).

However, inside libbpf's map-creation options initialization
(`bpf_object__create_map()`), libbpf zeroed out
`create_attr.btf_value_type_id` but does not zero out
`create_attr.btf_key_type_id`.

Fix this by explicitly zeroing out `create_attr.btf_key_type_id`.

Signed-off-by: Siddharth Nayyar <sidnayyar@xxxxxxxxxx>
---
tools/lib/bpf/libbpf.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index cb1b7ea884a7..9969de42da41 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -5439,6 +5439,7 @@ static int bpf_object__create_map(struct bpf_object *obj, struct bpf_map *map, b
map->btf_value_type_id = 0;
break;
case BPF_MAP_TYPE_STRUCT_OPS:
+ create_attr.btf_key_type_id = 0;
create_attr.btf_value_type_id = 0;
break;
default:

--
2.54.0.746.g67dd491aae-goog