linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] potential negative index dereference fix in get_exec_path()
@ 2025-06-12 13:18 Ruslan Semchenko
  2025-06-12 14:24 ` Daniel Borkmann
  2025-06-13  2:20 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Ruslan Semchenko @ 2025-06-12 13:18 UTC (permalink / raw)
  To: bpf; +Cc: linux-kernel, ast, daniel, Ruslan Semchenko

If readlink() fails, len will be -1, which can cause negative indexing
and undefined behavior. This patch ensures that len is set to 0 on
readlink failure, preventing such issues.

Signed-off-by: Ruslan Semchenko <uncleruc2075@gmail.com>
---
 tools/bpf/bpf_jit_disasm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/bpf/bpf_jit_disasm.c b/tools/bpf/bpf_jit_disasm.c
index 1baee9e2aba9..5ab8f80e2834 100644
--- a/tools/bpf/bpf_jit_disasm.c
+++ b/tools/bpf/bpf_jit_disasm.c
@@ -45,6 +45,8 @@ static void get_exec_path(char *tpath, size_t size)
 	assert(path);
 
 	len = readlink(path, tpath, size);
+	if (len < 0)
+		len = 0;
 	tpath[len] = 0;
 
 	free(path);
-- 
2.49.0


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

* Re: [PATCH] potential negative index dereference fix in get_exec_path()
  2025-06-12 13:18 [PATCH] potential negative index dereference fix in get_exec_path() Ruslan Semchenko
@ 2025-06-12 14:24 ` Daniel Borkmann
  2025-06-13  2:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2025-06-12 14:24 UTC (permalink / raw)
  To: Ruslan Semchenko, bpf; +Cc: linux-kernel, ast

On 6/12/25 3:18 PM, Ruslan Semchenko wrote:
> If readlink() fails, len will be -1, which can cause negative indexing
> and undefined behavior. This patch ensures that len is set to 0 on
> readlink failure, preventing such issues.
> 
> Signed-off-by: Ruslan Semchenko <uncleruc2075@gmail.com>

Looks reasonable, thanks! When applying patch $subj can be tweaked into:

   "tools/bpf_jit_disasm: Fix potential negative tpath index in get_exec_path()"

(bpf-next tree is fine)

Acked-by: Daniel Borkmann <daniel@iogearbox.net>

> ---
>   tools/bpf/bpf_jit_disasm.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/tools/bpf/bpf_jit_disasm.c b/tools/bpf/bpf_jit_disasm.c
> index 1baee9e2aba9..5ab8f80e2834 100644
> --- a/tools/bpf/bpf_jit_disasm.c
> +++ b/tools/bpf/bpf_jit_disasm.c
> @@ -45,6 +45,8 @@ static void get_exec_path(char *tpath, size_t size)
>   	assert(path);
>   
>   	len = readlink(path, tpath, size);
> +	if (len < 0)
> +		len = 0;
>   	tpath[len] = 0;
>   
>   	free(path);


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

* Re: [PATCH] potential negative index dereference fix in get_exec_path()
  2025-06-12 13:18 [PATCH] potential negative index dereference fix in get_exec_path() Ruslan Semchenko
  2025-06-12 14:24 ` Daniel Borkmann
@ 2025-06-13  2:20 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-06-13  2:20 UTC (permalink / raw)
  To: Ruslan Semchenko; +Cc: bpf, linux-kernel, ast, daniel

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:

On Thu, 12 Jun 2025 16:18:16 +0300 you wrote:
> If readlink() fails, len will be -1, which can cause negative indexing
> and undefined behavior. This patch ensures that len is set to 0 on
> readlink failure, preventing such issues.
> 
> Signed-off-by: Ruslan Semchenko <uncleruc2075@gmail.com>
> ---
>  tools/bpf/bpf_jit_disasm.c | 2 ++
>  1 file changed, 2 insertions(+)

Here is the summary with links:
  - potential negative index dereference fix in get_exec_path()
    https://git.kernel.org/bpf/bpf-next/c/af91af33c168

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:[~2025-06-13  2:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-12 13:18 [PATCH] potential negative index dereference fix in get_exec_path() Ruslan Semchenko
2025-06-12 14:24 ` Daniel Borkmann
2025-06-13  2:20 ` 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).