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.

selftests/bpf: Bump path and command buffer sizes in bpftool_helpers.c

The path length of 64 is way too low in some envirnoments, which leads
to subtle failures due to truncation [1].

Replace BPFTOOL_PATH_MAX_LEN with PATH_MAX, and set
BPFTOOL_FULL_CMD_MAX_LEN to double of PATH_MAX.

[1] https://github.com/libbpf/libbpf/actions/runs/22980753016/job/66719800527

Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20260312234820.439720-1-ihor.solodrai@linux.dev

authored by

Ihor Solodrai and committed by
Andrii Nakryiko
7e2f40ef c73a2443

+7 -8
+7 -8
tools/testing/selftests/bpf/bpftool_helpers.c
··· 2 2 #include <unistd.h> 3 3 #include <string.h> 4 4 #include <stdbool.h> 5 + #include <limits.h> 5 6 6 7 #include "bpf_util.h" 7 8 #include "bpftool_helpers.h" 8 9 9 - #define BPFTOOL_PATH_MAX_LEN 64 10 - #define BPFTOOL_FULL_CMD_MAX_LEN 512 10 + #define BPFTOOL_FULL_CMD_MAX_LEN (PATH_MAX * 2) 11 11 12 12 #define BPFTOOL_DEFAULT_PATH "tools/sbin/bpftool" 13 13 14 14 static int detect_bpftool_path(char *buffer, size_t size) 15 15 { 16 - char tmp[BPFTOOL_PATH_MAX_LEN]; 16 + char tmp[PATH_MAX]; 17 17 const char *env_path; 18 18 19 19 /* First, check if BPFTOOL environment variable is set */ ··· 29 29 /* Check default bpftool location (will work if we are running the 30 30 * default flavor of test_progs) 31 31 */ 32 - snprintf(tmp, BPFTOOL_PATH_MAX_LEN, "./%s", BPFTOOL_DEFAULT_PATH); 32 + snprintf(tmp, sizeof(tmp), "./%s", BPFTOOL_DEFAULT_PATH); 33 33 if (access(tmp, X_OK) == 0) { 34 34 strscpy(buffer, tmp, size); 35 35 return 0; ··· 38 38 /* Check alternate bpftool location (will work if we are running a 39 39 * specific flavor of test_progs, e.g. cpuv4 or no_alu32) 40 40 */ 41 - snprintf(tmp, BPFTOOL_PATH_MAX_LEN, "../%s", BPFTOOL_DEFAULT_PATH); 41 + snprintf(tmp, sizeof(tmp), "../%s", BPFTOOL_DEFAULT_PATH); 42 42 if (access(tmp, X_OK) == 0) { 43 43 strscpy(buffer, tmp, size); 44 44 return 0; ··· 50 50 51 51 static int run_command(char *args, char *output_buf, size_t output_max_len) 52 52 { 53 - static char bpftool_path[BPFTOOL_PATH_MAX_LEN] = {0}; 53 + static char bpftool_path[PATH_MAX] = {}; 54 54 bool suppress_output = !(output_buf && output_max_len); 55 55 char command[BPFTOOL_FULL_CMD_MAX_LEN]; 56 56 FILE *f; ··· 60 60 if (bpftool_path[0] == 0 && detect_bpftool_path(bpftool_path, sizeof(bpftool_path))) 61 61 return 1; 62 62 63 - ret = snprintf(command, BPFTOOL_FULL_CMD_MAX_LEN, "%s %s%s", 63 + ret = snprintf(command, sizeof(command), "%s %s%s", 64 64 bpftool_path, args, 65 65 suppress_output ? " > /dev/null 2>&1" : ""); 66 66 ··· 84 84 { 85 85 return run_command(args, output_buf, output_max_len); 86 86 } 87 -