selftests/bpf: ksym_search won't check symbols exists
authorDaniel T. Lee <danieltimlee@gmail.com>
Wed, 3 Apr 2019 22:17:55 +0000 (07:17 +0900)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 4 Apr 2019 14:43:46 +0000 (16:43 +0200)
Currently, ksym_search located at trace_helpers won't check symbols are
existing or not.

In ksym_search, when symbol is not found, it will return &syms[0](_stext).
But when the kernel symbols are not loaded, it will return NULL, which is
not a desired action.

This commit will add verification logic whether symbols are loaded prior
to the symbol search.

Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/testing/selftests/bpf/trace_helpers.c

index 4cdb63bf0521d546c65802cd7567a46a12e6769d..9a9fc6c9b70b5660ee83bca010b98b4af704dd2f 100644 (file)
@@ -52,6 +52,10 @@ struct ksym *ksym_search(long key)
        int start = 0, end = sym_cnt;
        int result;
 
+       /* kallsyms not loaded. return NULL */
+       if (sym_cnt <= 0)
+               return NULL;
+
        while (start < end) {
                size_t mid = start + (end - start) / 2;