Skip to content

Commit

Permalink
selftests/bpf: Bump and validate MAX_SYMS
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Björn Töpel authored and Andrii Nakryiko committed Jul 6, 2023
1 parent b625030 commit e76a014
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tools/testing/selftests/bpf/trace_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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++;
Expand Down

0 comments on commit e76a014

Please sign in to comment.