From 7a5b71e1dd7b336891c3337308b617bde40296f5 Mon Sep 17 00:00:00 2001 From: Kaushlendra Kumar Date: Mon, 1 Sep 2025 14:52:34 +0530 Subject: [PATCH] tools/bpf/bpftool: fix buffer handling in get_fd_type() The current check "if (n == sizeof(buf))" is incorrect for detecting buffer overflow from readlink(). When readlink() fills the entire buffer, it returns sizeof(buf) but does not null-terminate the string, leading to potential buffer overrun in subsequent string operations. Fix by changing the condition to "n >= sizeof(buf)" to properly detect when the buffer is completely filled, ensuring space is reserved for null termination. Signed-off-by: Kaushlendra Kumar --- tools/bpf/bpftool/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c index e8daf963ecef4..12e2ed8e85b9d 100644 --- a/tools/bpf/bpftool/common.c +++ b/tools/bpf/bpftool/common.c @@ -466,7 +466,7 @@ int get_fd_type(int fd) p_err("can't read link type: %s", strerror(errno)); return -1; } - if (n == sizeof(buf)) { + if (n >= sizeof(buf)) { p_err("can't read link type: path too long!"); return -1; }