Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <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>

authored by

Viktor Malik and committed by
Alexei Starovoitov
0053f7d3 cb3ade56

+2 -1
+2 -1
tools/bpf/bpftool/common.c
··· 461 461 p_err("can't read link type: %s", strerror(errno)); 462 462 return -1; 463 463 } 464 - if (n == sizeof(path)) { 464 + if (n == sizeof(buf)) { 465 465 p_err("can't read link type: path too long!"); 466 466 return -1; 467 467 } 468 + buf[n] = '\0'; 468 469 469 470 if (strstr(buf, "bpf-map")) 470 471 return BPF_OBJ_MAP;