Skip to content

Commit d0445d7

Browse files
mykyta5anakryiko
authored andcommitted
libbpf: Check bpf_map_skeleton link for NULL
Avoid dereferencing bpf_map_skeleton's link field if it's NULL. If BPF map skeleton is created with the size, that indicates containing link field, but the field was not actually initialized with valid bpf_link pointer, libbpf crashes. This may happen when using libbpf-rs skeleton. Skeleton loading may still progress, but user needs to attach struct_ops map separately. Signed-off-by: Mykyta Yatsenko <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent bc04938 commit d0445d7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14102,6 +14102,12 @@ int bpf_object__attach_skeleton(struct bpf_object_skeleton *s)
1410214102
}
1410314103

1410414104
link = map_skel->link;
14105+
if (!link) {
14106+
pr_warn("map '%s': BPF map skeleton link is uninitialized\n",
14107+
bpf_map__name(map));
14108+
continue;
14109+
}
14110+
1410514111
if (*link)
1410614112
continue;
1410714113

0 commit comments

Comments
 (0)