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>
This commit is contained in:
parent
0979ff7992
commit
e67b2c7154
|
@ -28,6 +28,11 @@ static void print_ksym(__u64 addr)
|
||||||
if (!addr)
|
if (!addr)
|
||||||
return;
|
return;
|
||||||
sym = ksym_search(addr);
|
sym = ksym_search(addr);
|
||||||
|
if (!sym) {
|
||||||
|
printf("ksym not found. Is kallsyms loaded?\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (PRINT_RAW_ADDR)
|
if (PRINT_RAW_ADDR)
|
||||||
printf("%s/%llx;", sym->name, addr);
|
printf("%s/%llx;", sym->name, addr);
|
||||||
else
|
else
|
||||||
|
|
|
@ -109,6 +109,11 @@ static void print_ip_map(int fd)
|
||||||
for (i = 0; i < max; i++) {
|
for (i = 0; i < max; i++) {
|
||||||
if (counts[i].ip > PAGE_OFFSET) {
|
if (counts[i].ip > PAGE_OFFSET) {
|
||||||
sym = ksym_search(counts[i].ip);
|
sym = ksym_search(counts[i].ip);
|
||||||
|
if (!sym) {
|
||||||
|
printf("ksym not found. Is kallsyms loaded?\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
printf("0x%-17llx %-32s %u\n", counts[i].ip, sym->name,
|
printf("0x%-17llx %-32s %u\n", counts[i].ip, sym->name,
|
||||||
counts[i].count);
|
counts[i].count);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -37,8 +37,13 @@ int main(int ac, char **argv)
|
||||||
bpf_map_lookup_elem(map_fd[0], &next_key, &value);
|
bpf_map_lookup_elem(map_fd[0], &next_key, &value);
|
||||||
assert(next_key == value);
|
assert(next_key == value);
|
||||||
sym = ksym_search(value);
|
sym = ksym_search(value);
|
||||||
printf(" %s", sym->name);
|
|
||||||
key = next_key;
|
key = next_key;
|
||||||
|
if (!sym) {
|
||||||
|
printf("ksym not found. Is kallsyms loaded?\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(" %s", sym->name);
|
||||||
}
|
}
|
||||||
if (key)
|
if (key)
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
|
@ -34,6 +34,11 @@ static void print_ksym(__u64 addr)
|
||||||
if (!addr)
|
if (!addr)
|
||||||
return;
|
return;
|
||||||
sym = ksym_search(addr);
|
sym = ksym_search(addr);
|
||||||
|
if (!sym) {
|
||||||
|
printf("ksym not found. Is kallsyms loaded?\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
printf("%s;", sym->name);
|
printf("%s;", sym->name);
|
||||||
if (!strcmp(sym->name, "sys_read"))
|
if (!strcmp(sym->name, "sys_read"))
|
||||||
sys_read_seen = true;
|
sys_read_seen = true;
|
||||||
|
|
|
@ -39,7 +39,7 @@ static int get_stack_print_output(void *data, int size)
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < num_stack; i++) {
|
for (i = 0; i < num_stack; i++) {
|
||||||
ks = ksym_search(raw_data[i]);
|
ks = ksym_search(raw_data[i]);
|
||||||
if (strcmp(ks->name, nonjit_func) == 0) {
|
if (ks && (strcmp(ks->name, nonjit_func) == 0)) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ static int get_stack_print_output(void *data, int size)
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < num_stack; i++) {
|
for (i = 0; i < num_stack; i++) {
|
||||||
ks = ksym_search(e->kern_stack[i]);
|
ks = ksym_search(e->kern_stack[i]);
|
||||||
if (strcmp(ks->name, nonjit_func) == 0) {
|
if (ks && (strcmp(ks->name, nonjit_func) == 0)) {
|
||||||
good_kern_stack = true;
|
good_kern_stack = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue