aboutsummaryrefslogtreecommitdiffstats
path: root/tools/bpf/bpftool/common.c
diff options
context:
space:
mode:
authorViktor Malik <[email protected]>2025-01-29 07:18:57 +0000
committerAlexei Starovoitov <[email protected]>2025-02-03 11:33:51 +0000
commit0053f7d39d491b6138d7c526876d13885cbb65f1 (patch)
tree927ece76c07fe08a6f706520f96e30146a37c312 /tools/bpf/bpftool/common.c
parentselftests/bpf: Fix runqslower cross-endian build (diff)
downloadkernel-0053f7d39d491b6138d7c526876d13885cbb65f1.tar.gz
kernel-0053f7d39d491b6138d7c526876d13885cbb65f1.zip
bpftool: Fix readlink usage in get_fd_type
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 <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Reviewed-by: Quentin Monnet <[email protected]> Link: https://lore.kernel.org/bpf/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
Diffstat (limited to 'tools/bpf/bpftool/common.c')
-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 9b75639434b8..0a764426d935 100644
--- a/tools/bpf/bpftool/common.c
+++ b/tools/bpf/bpftool/common.c
@@ -461,10 +461,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;