selftests/bpf: Bump and validate MAX_SYMS
authorBjörn Töpel <bjorn@rivosinc.com>
Thu, 6 Jul 2023 14:22:28 +0000 (16:22 +0200)
committerAndrii Nakryiko <andrii@kernel.org>
Thu, 6 Jul 2023 20:39:40 +0000 (13:39 -0700)
BPF tests that load /proc/kallsyms, e.g. bpf_cookie, will perform a
buffer overrun if the number of syms on the system is larger than
MAX_SYMS.

Bump the MAX_SYMS to 400000, and add a runtime check that bails out if
the maximum is reached.

Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/bpf/20230706142228.1128452-1-bjorn@kernel.org
tools/testing/selftests/bpf/trace_helpers.c

index 9b070cd..f83d9f6 100644 (file)
@@ -18,7 +18,7 @@
 #define TRACEFS_PIPE   "/sys/kernel/tracing/trace_pipe"
 #define DEBUGFS_PIPE   "/sys/kernel/debug/tracing/trace_pipe"
 
-#define MAX_SYMS 300000
+#define MAX_SYMS 400000
 static struct ksym syms[MAX_SYMS];
 static int sym_cnt;
 
@@ -46,6 +46,9 @@ int load_kallsyms_refresh(void)
                        break;
                if (!addr)
                        continue;
+               if (i >= MAX_SYMS)
+                       return -EFBIG;
+
                syms[i].addr = (long) addr;
                syms[i].name = strdup(func);
                i++;