netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/2] selftests/bpf: ksym_search won't check symbols exists
@ 2019-04-03 22:17 Daniel T. Lee
  2019-04-03 22:17 ` [PATCH v3 2/2] samples, selftests/bpf: add NULL check for ksym_search Daniel T. Lee
  2019-04-04 15:23 ` [PATCH v3 1/2] selftests/bpf: ksym_search won't check symbols exists Daniel Borkmann
  0 siblings, 2 replies; 3+ messages in thread
From: Daniel T. Lee @ 2019-04-03 22:17 UTC (permalink / raw)
  To: Daniel Borkmann, Alexei Starovoitov; +Cc: netdev

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>
---
 tools/testing/selftests/bpf/trace_helpers.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c
index 4cdb63bf0521..9a9fc6c9b70b 100644
--- a/tools/testing/selftests/bpf/trace_helpers.c
+++ b/tools/testing/selftests/bpf/trace_helpers.c
@@ -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;
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-04-04 15:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-03 22:17 [PATCH v3 1/2] selftests/bpf: ksym_search won't check symbols exists Daniel T. Lee
2019-04-03 22:17 ` [PATCH v3 2/2] samples, selftests/bpf: add NULL check for ksym_search Daniel T. Lee
2019-04-04 15:23 ` [PATCH v3 1/2] selftests/bpf: ksym_search won't check symbols exists 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).