Message ID | 20190315064210.18735-2-danieltimlee@gmail.com |
---|---|
State | Changes Requested |
Delegated to: | BPF Maintainers |
Headers | show |
Series | [1/2] selftests/bpf: ksym_search won't check symbols exists | expand |
On 03/15/2019 07:42 AM, Daniel T. Lee wrote: > 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> > --- > samples/bpf/offwaketime_user.c | 5 +++++ > samples/bpf/sampleip_user.c | 5 +++++ > samples/bpf/trace_event_user.c | 5 +++++ > 3 files changed, 15 insertions(+) This would also need fixing to check for NULL in: tools/testing/selftests/bpf/prog_tests/get_stack_raw_tp.c > diff --git a/samples/bpf/offwaketime_user.c b/samples/bpf/offwaketime_user.c > index f06063af9fcb..52e29467a509 100644 > --- a/samples/bpf/offwaketime_user.c > +++ b/samples/bpf/offwaketime_user.c > @@ -28,6 +28,11 @@ static void print_ksym(__u64 addr) > if (!addr) > return; > sym = ksym_search(addr); > + if (!sym){ > + printf("ksym not found. Is kallsyms loaded?\n"); > + return; > + } > + > if (PRINT_RAW_ADDR) > printf("%s/%llx;", sym->name, addr); > 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) > for (i = 0; i < max; i++) { > if (counts[i].ip > PAGE_OFFSET) { > 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, > counts[i].count); > } else { > diff --git a/samples/bpf/trace_event_user.c b/samples/bpf/trace_event_user.c > index d08046ab81f0..bc8e6afdae6d 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) > if (!addr) > return; > sym = ksym_search(addr); > + if (!sym){ > + printf("ksym not found. Is kallsyms loaded?\n"); > + return; > + } > + > printf("%s;", sym->name); > if (!strcmp(sym->name, "sys_read")) > sys_read_seen = true; >
diff --git a/samples/bpf/offwaketime_user.c b/samples/bpf/offwaketime_user.c index f06063af9fcb..52e29467a509 100644 --- a/samples/bpf/offwaketime_user.c +++ b/samples/bpf/offwaketime_user.c @@ -28,6 +28,11 @@ static void print_ksym(__u64 addr) if (!addr) return; sym = ksym_search(addr); + if (!sym){ + printf("ksym not found. Is kallsyms loaded?\n"); + return; + } + if (PRINT_RAW_ADDR) printf("%s/%llx;", sym->name, addr); 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) for (i = 0; i < max; i++) { if (counts[i].ip > PAGE_OFFSET) { 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, counts[i].count); } else { diff --git a/samples/bpf/trace_event_user.c b/samples/bpf/trace_event_user.c index d08046ab81f0..bc8e6afdae6d 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) if (!addr) return; sym = ksym_search(addr); + if (!sym){ + printf("ksym not found. Is kallsyms loaded?\n"); + return; + } + printf("%s;", sym->name); if (!strcmp(sym->name, "sys_read")) sys_read_seen = true;
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> --- samples/bpf/offwaketime_user.c | 5 +++++ samples/bpf/sampleip_user.c | 5 +++++ samples/bpf/trace_event_user.c | 5 +++++ 3 files changed, 15 insertions(+)