]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
bpftool: Fix readlink usage in get_fd_type
authorViktor Malik <vmalik@redhat.com>
Wed, 29 Jan 2025 07:18:57 +0000 (08:18 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 May 2025 09:13:42 +0000 (11:13 +0200)
commit8c3648ca60eb5321d345a71838e537d26254e243
tree7087d57f4d73b7196a9d6a3c90c5a75e3cca5b1a
parentc9d4ea2cc1c9f0249490259590979570de4f6428
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>
tools/bpf/bpftool/common.c