* [PATCH bpf] selftests/bpf: fix segfault of test_progs when prog loading failed
@ 2019-03-12 5:21 Yonghong Song
2019-03-12 5:42 ` Song Liu
2019-03-12 21:01 ` Daniel Borkmann
0 siblings, 2 replies; 3+ messages in thread
From: Yonghong Song @ 2019-03-12 5:21 UTC (permalink / raw)
To: netdev; +Cc: Alexei Starovoitov, Daniel Borkmann, kernel-team, Yonghong Song
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: b4d4556c3266 ("selftests/bpf: add bpf_spin_lock verifier tests")
Fixes: ba72a7b4badb ("selftests/bpf: test for BPF_F_LOCK")
Reported-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Yonghong Song <yhs@fb.com>
---
tools/testing/selftests/bpf/prog_tests/map_lock.c | 2 +-
tools/testing/selftests/bpf/prog_tests/spinlock.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/map_lock.c b/tools/testing/selftests/bpf/prog_tests/map_lock.c
index 90f8a206340a..ee99368c595c 100644
--- a/tools/testing/selftests/bpf/prog_tests/map_lock.c
+++ b/tools/testing/selftests/bpf/prog_tests/map_lock.c
@@ -37,7 +37,7 @@ void test_map_lock(void)
const char *file = "./test_map_lock.o";
int prog_fd, map_fd[2], vars[17] = {};
pthread_t thread_id[6];
- struct bpf_object *obj;
+ struct bpf_object *obj = NULL;
int err = 0, key = 0, i;
void *ret;
diff --git a/tools/testing/selftests/bpf/prog_tests/spinlock.c b/tools/testing/selftests/bpf/prog_tests/spinlock.c
index 9a573a9675d7..114ebe6a438e 100644
--- a/tools/testing/selftests/bpf/prog_tests/spinlock.c
+++ b/tools/testing/selftests/bpf/prog_tests/spinlock.c
@@ -5,7 +5,7 @@ void test_spinlock(void)
{
const char *file = "./test_spin_lock.o";
pthread_t thread_id[4];
- struct bpf_object *obj;
+ struct bpf_object *obj = NULL;
int prog_fd;
int err = 0, i;
void *ret;
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf] selftests/bpf: fix segfault of test_progs when prog loading failed
2019-03-12 5:21 [PATCH bpf] selftests/bpf: fix segfault of test_progs when prog loading failed Yonghong Song
@ 2019-03-12 5:42 ` Song Liu
2019-03-12 21:01 ` Daniel Borkmann
1 sibling, 0 replies; 3+ messages in thread
From: Song Liu @ 2019-03-12 5:42 UTC (permalink / raw)
To: Yonghong Song
Cc: Networking, Alexei Starovoitov, Daniel Borkmann, Kernel Team
> On Mar 11, 2019, at 10:21 PM, Yonghong Song <yhs@fb.com> wrote:
>
> 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: b4d4556c3266 ("selftests/bpf: add bpf_spin_lock verifier tests")
> Fixes: ba72a7b4badb ("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>
> ---
> tools/testing/selftests/bpf/prog_tests/map_lock.c | 2 +-
> tools/testing/selftests/bpf/prog_tests/spinlock.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/map_lock.c b/tools/testing/selftests/bpf/prog_tests/map_lock.c
> index 90f8a206340a..ee99368c595c 100644
> --- a/tools/testing/selftests/bpf/prog_tests/map_lock.c
> +++ b/tools/testing/selftests/bpf/prog_tests/map_lock.c
> @@ -37,7 +37,7 @@ void test_map_lock(void)
> const char *file = "./test_map_lock.o";
> int prog_fd, map_fd[2], vars[17] = {};
> pthread_t thread_id[6];
> - struct bpf_object *obj;
> + struct bpf_object *obj = NULL;
> int err = 0, key = 0, i;
> void *ret;
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/spinlock.c b/tools/testing/selftests/bpf/prog_tests/spinlock.c
> index 9a573a9675d7..114ebe6a438e 100644
> --- a/tools/testing/selftests/bpf/prog_tests/spinlock.c
> +++ b/tools/testing/selftests/bpf/prog_tests/spinlock.c
> @@ -5,7 +5,7 @@ void test_spinlock(void)
> {
> const char *file = "./test_spin_lock.o";
> pthread_t thread_id[4];
> - struct bpf_object *obj;
> + struct bpf_object *obj = NULL;
> int prog_fd;
> int err = 0, i;
> void *ret;
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf] selftests/bpf: fix segfault of test_progs when prog loading failed
2019-03-12 5:21 [PATCH bpf] selftests/bpf: fix segfault of test_progs when prog loading failed Yonghong Song
2019-03-12 5:42 ` Song Liu
@ 2019-03-12 21:01 ` Daniel Borkmann
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2019-03-12 21:01 UTC (permalink / raw)
To: Yonghong Song, netdev; +Cc: Alexei Starovoitov, kernel-team
On 03/12/2019 06:21 AM, Yonghong Song wrote:
> 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: b4d4556c3266 ("selftests/bpf: add bpf_spin_lock verifier tests")
> Fixes: ba72a7b4badb ("selftests/bpf: test for BPF_F_LOCK")
> Reported-by: Daniel Borkmann <daniel@iogearbox.net>
> Signed-off-by: Yonghong Song <yhs@fb.com>
Applied, thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-03-12 21:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-12 5:21 [PATCH bpf] selftests/bpf: fix segfault of test_progs when prog loading failed Yonghong Song
2019-03-12 5:42 ` Song Liu
2019-03-12 21:01 ` Daniel Borkmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).