]> git.baikalelectronics.ru Git - kernel.git/commit
selftests/bpf: fix segfault of test_progs when prog loading failed
authorYonghong Song <yhs@fb.com>
Tue, 12 Mar 2019 05:21:09 +0000 (22:21 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 12 Mar 2019 20:55:54 +0000 (21:55 +0100)
commit755dec8e14abe889af8214aa01520c48cc2ef7b9
treeff0507cdc1d93d0da8b2ef971ffdfbc84c1fa363
parentc52cad9c4e6da4a3ebeb4eb6e6d4796631eee1be
selftests/bpf: fix segfault of test_progs when prog loading failed

The test_progs subtests, test_spin_lock() and test_map_lock(),
requires BTF present to run successfully.
Currently, when BTF failed to load, test_progs will segfault,
  $ ./test_progs
  ...
  12: (bf) r1 = r8
  13: (85) call bpf_spin_lock#93
  map 'hash_map' has to have BTF in order to use bpf_spin_lock

  libbpf: -- END LOG --
  libbpf: failed to load program 'map_lock_demo'
  libbpf: failed to load object './test_map_lock.o'
  test_map_lock:bpf_prog_load errno 13
  Segmentation fault

The segfault is caused by uninitialized variable "obj", which
is used in bpf_object__close(obj), when bpf prog failed to load.

Initializing variable "obj" to NULL in two occasions fixed the problem.
  $ ./test_progs
  ...
  Summary: 219 PASSED, 2 FAILED

Fixes: 7b0ba7a02bd0 ("selftests/bpf: add bpf_spin_lock verifier tests")
Fixes: 544b028ffe74 ("selftests/bpf: test for BPF_F_LOCK")
Reported-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Yonghong Song <yhs@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/testing/selftests/bpf/prog_tests/map_lock.c
tools/testing/selftests/bpf/prog_tests/spinlock.c