diff options
| author | Daniel T. Lee <danieltimlee@gmail.com> | 2019-04-03 18:17:56 -0400 |
|---|---|---|
| committer | Daniel Borkmann <daniel@iogearbox.net> | 2019-04-04 10:43:47 -0400 |
| commit | e67b2c715415b121339049b630f0b4e1ede888dc (patch) | |
| tree | ead14552f2199aca864d04cdff0afcd23222eaf9 /samples | |
| parent | 0979ff7992fb6f4eb837995b12f4071dcafebd2d (diff) | |
samples, selftests/bpf: add NULL check for ksym_search
Since, ksym_search added with verification logic for symbols existence,
it could return NULL when the kernel symbols are not loaded.
This commit will add NULL check logic after ksym_search.
Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'samples')
| -rw-r--r-- | samples/bpf/offwaketime_user.c | 5 | ||||
| -rw-r--r-- | samples/bpf/sampleip_user.c | 5 | ||||
| -rw-r--r-- | samples/bpf/spintest_user.c | 7 | ||||
| -rw-r--r-- | samples/bpf/trace_event_user.c | 5 |
4 files changed, 21 insertions, 1 deletions
diff --git a/samples/bpf/offwaketime_user.c b/samples/bpf/offwaketime_user.c index f06063af9fcb..bb315ce1b866 100644 --- a/samples/bpf/offwaketime_user.c +++ b/samples/bpf/offwaketime_user.c | |||
| @@ -28,6 +28,11 @@ static void print_ksym(__u64 addr) | |||
| 28 | if (!addr) | 28 | if (!addr) |
| 29 | return; | 29 | return; |
| 30 | sym = ksym_search(addr); | 30 | sym = ksym_search(addr); |
| 31 | if (!sym) { | ||
| 32 | printf("ksym not found. Is kallsyms loaded?\n"); | ||
| 33 | return; | ||
| 34 | } | ||
| 35 | |||
| 31 | if (PRINT_RAW_ADDR) | 36 | if (PRINT_RAW_ADDR) |
| 32 | printf("%s/%llx;", sym->name, addr); | 37 | printf("%s/%llx;", sym->name, addr); |
| 33 | else | 38 | else |
diff --git a/samples/bpf/sampleip_user.c b/samples/bpf/sampleip_user.c index 216c7ecbbbe9..23b90a45c802 100644 --- a/samples/bpf/sampleip_user.c +++ b/samples/bpf/sampleip_user.c | |||
| @@ -109,6 +109,11 @@ static void print_ip_map(int fd) | |||
| 109 | for (i = 0; i < max; i++) { | 109 | for (i = 0; i < max; i++) { |
| 110 | if (counts[i].ip > PAGE_OFFSET) { | 110 | if (counts[i].ip > PAGE_OFFSET) { |
| 111 | sym = ksym_search(counts[i].ip); | 111 | sym = ksym_search(counts[i].ip); |
| 112 | if (!sym) { | ||
| 113 | printf("ksym not found. Is kallsyms loaded?\n"); | ||
| 114 | continue; | ||
| 115 | } | ||
| 116 | |||
| 112 | printf("0x%-17llx %-32s %u\n", counts[i].ip, sym->name, | 117 | printf("0x%-17llx %-32s %u\n", counts[i].ip, sym->name, |
| 113 | counts[i].count); | 118 | counts[i].count); |
| 114 | } else { | 119 | } else { |
diff --git a/samples/bpf/spintest_user.c b/samples/bpf/spintest_user.c index 8d3e9cfa1909..2556af2d9b3e 100644 --- a/samples/bpf/spintest_user.c +++ b/samples/bpf/spintest_user.c | |||
| @@ -37,8 +37,13 @@ int main(int ac, char **argv) | |||
| 37 | bpf_map_lookup_elem(map_fd[0], &next_key, &value); | 37 | bpf_map_lookup_elem(map_fd[0], &next_key, &value); |
| 38 | assert(next_key == value); | 38 | assert(next_key == value); |
| 39 | sym = ksym_search(value); | 39 | sym = ksym_search(value); |
| 40 | printf(" %s", sym->name); | ||
| 41 | key = next_key; | 40 | key = next_key; |
| 41 | if (!sym) { | ||
| 42 | printf("ksym not found. Is kallsyms loaded?\n"); | ||
| 43 | continue; | ||
| 44 | } | ||
| 45 | |||
| 46 | printf(" %s", sym->name); | ||
| 42 | } | 47 | } |
| 43 | if (key) | 48 | if (key) |
| 44 | printf("\n"); | 49 | printf("\n"); |
diff --git a/samples/bpf/trace_event_user.c b/samples/bpf/trace_event_user.c index d08046ab81f0..d4178f60e075 100644 --- a/samples/bpf/trace_event_user.c +++ b/samples/bpf/trace_event_user.c | |||
| @@ -34,6 +34,11 @@ static void print_ksym(__u64 addr) | |||
| 34 | if (!addr) | 34 | if (!addr) |
| 35 | return; | 35 | return; |
| 36 | sym = ksym_search(addr); | 36 | sym = ksym_search(addr); |
| 37 | if (!sym) { | ||
| 38 | printf("ksym not found. Is kallsyms loaded?\n"); | ||
| 39 | return; | ||
| 40 | } | ||
| 41 | |||
| 37 | printf("%s;", sym->name); | 42 | printf("%s;", sym->name); |
| 38 | if (!strcmp(sym->name, "sys_read")) | 43 | if (!strcmp(sym->name, "sys_read")) |
| 39 | sys_read_seen = true; | 44 | sys_read_seen = true; |
