netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: Bump and validate MAX_SYMS
@ 2023-07-06 14:22 Björn Töpel
  2023-07-06 17:46 ` Stanislav Fomichev
  2023-07-06 21:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Björn Töpel @ 2023-07-06 14:22 UTC (permalink / raw)
  To: Andrii Nakryiko, Mykola Lysenko, bpf, netdev
  Cc: Björn Töpel, Alexei Starovoitov, Daniel Borkmann,
	linux-kselftest, linux-kernel

From: Björn Töpel <bjorn@rivosinc.com>

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

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

base-commit: fd283ab196a867f8f65f36913e0fadd031fcb823
-- 
2.39.2


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

* Re: [PATCH bpf-next] selftests/bpf: Bump and validate MAX_SYMS
  2023-07-06 14:22 [PATCH bpf-next] selftests/bpf: Bump and validate MAX_SYMS Björn Töpel
@ 2023-07-06 17:46 ` Stanislav Fomichev
  2023-07-06 21:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Stanislav Fomichev @ 2023-07-06 17:46 UTC (permalink / raw)
  To: Björn Töpel
  Cc: Andrii Nakryiko, Mykola Lysenko, bpf, netdev,
	Björn Töpel, Alexei Starovoitov, Daniel Borkmann,
	linux-kselftest, linux-kernel

On 07/06, Björn Töpel wrote:
> From: Björn Töpel <bjorn@rivosinc.com>
> 
> 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>

Acked-by: Stanislav Fomichev <sdf@google.com>

OTOH, should be easy to convert this to malloc/realloc? That should fix
it once and for all and avoid future need to bump the limit?

> ---
>  tools/testing/selftests/bpf/trace_helpers.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c
> index 9b070cdf44ac..f83d9f65c65b 100644
> --- a/tools/testing/selftests/bpf/trace_helpers.c
> +++ b/tools/testing/selftests/bpf/trace_helpers.c
> @@ -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++;
> 
> base-commit: fd283ab196a867f8f65f36913e0fadd031fcb823
> -- 
> 2.39.2
> 

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

* Re: [PATCH bpf-next] selftests/bpf: Bump and validate MAX_SYMS
  2023-07-06 14:22 [PATCH bpf-next] selftests/bpf: Bump and validate MAX_SYMS Björn Töpel
  2023-07-06 17:46 ` Stanislav Fomichev
@ 2023-07-06 21:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-07-06 21:10 UTC (permalink / raw)
  To: =?utf-8?b?QmrDtnJuIFTDtnBlbCA8Ympvcm5Aa2VybmVsLm9yZz4=?=
  Cc: andrii, mykolal, bpf, netdev, bjorn, ast, daniel, linux-kselftest,
	linux-kernel

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Thu,  6 Jul 2023 16:22:28 +0200 you wrote:
> From: Björn Töpel <bjorn@rivosinc.com>
> 
> 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.
> 
> [...]

Here is the summary with links:
  - [bpf-next] selftests/bpf: Bump and validate MAX_SYMS
    https://git.kernel.org/bpf/bpf-next/c/e76a014334a6

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2023-07-06 21:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-06 14:22 [PATCH bpf-next] selftests/bpf: Bump and validate MAX_SYMS Björn Töpel
2023-07-06 17:46 ` Stanislav Fomichev
2023-07-06 21:10 ` patchwork-bot+netdevbpf

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).