]> git.baikalelectronics.ru Git - kernel.git/commit
libbpf: Clear map_info before each bpf_obj_get_info_by_fd
authorMaciej Fijalkowski <maciej.fijalkowski@intel.com>
Wed, 3 Mar 2021 18:56:36 +0000 (19:56 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 4 Mar 2021 14:53:37 +0000 (15:53 +0100)
commitfa1591591d196bcb4bac784685d04c4ba00313e4
treed5e637cb85bcd4da39a6e5abf534a20c2663c523
parent0bbc48c4a05838a3b54d30b4d40bf1139a58759c
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: 6fd152d6aaa1 ("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
tools/lib/bpf/xsk.c