]> git.baikalelectronics.ru Git - kernel.git/commitdiff
libbpf: Fix passing uninitialized bytes to setsockopt
authorIlya Maximets <i.maximets@ovn.org>
Wed, 9 Oct 2019 16:49:29 +0000 (18:49 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 9 Oct 2019 22:45:37 +0000 (15:45 -0700)
'struct xdp_umem_reg' has 4 bytes of padding at the end that makes
valgrind complain about passing uninitialized stack memory to the
syscall:

  Syscall param socketcall.setsockopt() points to uninitialised byte(s)
    at 0x4E7AB7E: setsockopt (in /usr/lib64/libc-2.29.so)
    by 0x4BDE035: xsk_umem__create@@LIBBPF_0.0.4 (xsk.c:172)
  Uninitialised value was created by a stack allocation
    at 0x4BDDEBA: xsk_umem__create@@LIBBPF_0.0.4 (xsk.c:140)

Padding bytes appeared after introducing of a new 'flags' field.
memset() is required to clear them.

Fixes: 4128156a9b72 ("libbpf: add flags to umem config")
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20191009164929.17242-1-i.maximets@ovn.org
tools/lib/bpf/xsk.c

index 24fa313524fb216fa9390725c99fc4d0766c1564..b0f532544c91f462aa0fd5abda1a8b8aea477c27 100644 (file)
@@ -163,6 +163,7 @@ int xsk_umem__create_v0_0_4(struct xsk_umem **umem_ptr, void *umem_area,
        umem->umem_area = umem_area;
        xsk_set_umem_config(&umem->config, usr_config);
 
+       memset(&mr, 0, sizeof(mr));
        mr.addr = (uintptr_t)umem_area;
        mr.len = size;
        mr.chunk_size = umem->config.frame_size;