mirror of https://lore.kernel.org/lkml/
 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	[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

all inboxes | Powered by JetHome®