diff options
| author | Andrii Nakryiko <[email protected]> | 2022-08-16 00:19:27 +0000 |
|---|---|---|
| committer | Daniel Borkmann <[email protected]> | 2022-08-17 20:42:10 +0000 |
| commit | 813847a31447feba6119df4ee77a7c0c7a77fc72 (patch) | |
| tree | 767299922c7899e6a698bd46f63bcf09c175103c /tools/lib/bpf/netlink.c | |
| parent | libbpf: Fix potential NULL dereference when parsing ELF (diff) | |
| download | kernel-813847a31447feba6119df4ee77a7c0c7a77fc72.tar.gz kernel-813847a31447feba6119df4ee77a7c0c7a77fc72.zip | |
libbpf: Streamline bpf_attr and perf_event_attr initialization
Make sure that entire libbpf code base is initializing bpf_attr and
perf_event_attr with memset(0). Also for bpf_attr make sure we
clear and pass to kernel only relevant parts of bpf_attr. bpf_attr is
a huge union of independent sub-command attributes, so there is no need
to clear and pass entire union bpf_attr, which over time grows quite
a lot and for most commands this growth is completely irrelevant.
Few cases where we were relying on compiler initialization of BPF UAPI
structs (like bpf_prog_info, bpf_map_info, etc) with `= {};` were
switched to memset(0) pattern for future-proofing.
Signed-off-by: Andrii Nakryiko <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Acked-by: Hao Luo <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
Diffstat (limited to 'tools/lib/bpf/netlink.c')
| -rw-r--r-- | tools/lib/bpf/netlink.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/tools/lib/bpf/netlink.c b/tools/lib/bpf/netlink.c index 6c013168032d..35104580870c 100644 --- a/tools/lib/bpf/netlink.c +++ b/tools/lib/bpf/netlink.c @@ -587,11 +587,12 @@ static int get_tc_info(struct nlmsghdr *nh, libbpf_dump_nlmsg_t fn, static int tc_add_fd_and_name(struct libbpf_nla_req *req, int fd) { - struct bpf_prog_info info = {}; + struct bpf_prog_info info; __u32 info_len = sizeof(info); char name[256]; int len, ret; + memset(&info, 0, info_len); ret = bpf_obj_get_info_by_fd(fd, &info, &info_len); if (ret < 0) return ret; |
