Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

libbpf: Clear map_info before each bpf_obj_get_info_by_fd

xsk_lookup_bpf_maps, based on prog_fd, looks whether current prog has a
reference to XSKMAP. BPF prog can include insns that work on various BPF
maps and this is covered by iterating through map_ids.

The bpf_map_info that is passed to bpf_obj_get_info_by_fd for filling
needs to be cleared at each iteration, so that it doesn't contain any
outdated fields and that is currently missing in the function of
interest.

To fix that, zero-init map_info via memset before each
bpf_obj_get_info_by_fd call.

Also, since the area of this code is touched, in general strcmp is
considered harmful, so let's convert it to strncmp and provide the
size of the array name for current map_info.

While at it, do s/continue/break/ once we have found the xsks_map to
terminate the search.

Fixes: 5750902a6e9b ("libbpf: proper XSKMAP cleanup")
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Björn Töpel <bjorn.topel@intel.com>
Link: https://lore.kernel.org/bpf/20210303185636.18070-4-maciej.fijalkowski@intel.com

authored by

Maciej Fijalkowski and committed by
Daniel Borkmann
2b2aedab 6bc66998

+3 -2
+3 -2
tools/lib/bpf/xsk.c
··· 610 610 if (fd < 0) 611 611 continue; 612 612 613 + memset(&map_info, 0, map_len); 613 614 err = bpf_obj_get_info_by_fd(fd, &map_info, &map_len); 614 615 if (err) { 615 616 close(fd); 616 617 continue; 617 618 } 618 619 619 - if (!strcmp(map_info.name, "xsks_map")) { 620 + if (!strncmp(map_info.name, "xsks_map", sizeof(map_info.name))) { 620 621 ctx->xsks_map_fd = fd; 621 - continue; 622 + break; 622 623 } 623 624 624 625 close(fd);