summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViktor Malik <vmalik@redhat.com>2025-01-29 08:18:57 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-06-04 14:32:34 +0200
commit8079ba28438806f2d967ac5a08f236bf970feb44 (patch)
tree39978b065b9afa5ba14ad959972d93358d2542bd
parent2d16514e557f5eb3b23968a80771b3e65d2fc89f (diff)
downloadlinux-8079ba28438806f2d967ac5a08f236bf970feb44.tar.gz
linux-8079ba28438806f2d967ac5a08f236bf970feb44.tar.bz2
linux-8079ba28438806f2d967ac5a08f236bf970feb44.zip
bpftool: Fix readlink usage in get_fd_type
[ Upstream commit 0053f7d39d491b6138d7c526876d13885cbb65f1 ] The `readlink(path, buf, sizeof(buf))` call reads at most sizeof(buf) bytes and *does not* append null-terminator to buf. With respect to that, fix two pieces in get_fd_type: 1. Change the truncation check to contain sizeof(buf) rather than sizeof(path). 2. Append null-terminator to buf. Reported by Coverity. Signed-off-by: Viktor Malik <vmalik@redhat.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Reviewed-by: Quentin Monnet <qmo@kernel.org> Link: https://lore.kernel.org/bpf/20250129071857.75182-1-vmalik@redhat.com Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--tools/bpf/bpftool/common.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
index a209f53901b8..91bf7575493b 100644
--- a/tools/bpf/bpftool/common.c
+++ b/tools/bpf/bpftool/common.c
@@ -283,10 +283,11 @@ int get_fd_type(int fd)
p_err("can't read link type: %s", strerror(errno));
return -1;
}
- if (n == sizeof(path)) {
+ if (n == sizeof(buf)) {
p_err("can't read link type: path too long!");
return -1;
}
+ buf[n] = '\0';
if (strstr(buf, "bpf-map"))
return BPF_OBJ_MAP;