bpf_get_work_dir() returns NULL when it cannot provide a usable work directory. It does so even after finding a valid bpffs mount, because bpf_gen_hierarchy() fails if the tc/ subdirectory cannot be created: running unprivileged against the default mode=700 mount, or as root against a read-only one. iproute2_get_root_path() passed that NULL straight to snprintf("%s"), which glibc renders as "(null)": $ tc filter add dev lo parent ffff: bpf obj prog.o sec egress mkdir /sys/fs/bpf/tc/ failed: Permission denied Continuing without mounted eBPF fs. Too old kernel? mkdir (null)/globals failed: No such file or directory Unable to load program Check for NULL and report it instead. Also check the snprintf() return, since root_path is handed to libbpf as pin_root_path and a silently truncated pin root is worse than a hard failure. The "Continuing without mounted eBPF fs" warning in bpf_init_env() goes away with it. The legacy loader could carry on without bpffs, which is what that message described, but the only remaining caller needs the pin root and now fails, so the warning no longer matched what happens next. The "Too old kernel?" guess was misleading as well: the mount is usually present and simply not writable. Fixes: 6d61a2b55799 ("lib: add libbpf support") Signed-off-by: Stephen Hemminger --- lib/bpf_util.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/bpf_util.c b/lib/bpf_util.c index e58e54be..20609339 100644 --- a/lib/bpf_util.c +++ b/lib/bpf_util.c @@ -1068,20 +1068,27 @@ static void bpf_init_env(void) /* Don't bother in case we fail! */ setrlimit(RLIMIT_MEMLOCK, &limit); - - if (!bpf_get_work_dir(BPF_PROG_TYPE_UNSPEC)) - fprintf(stderr, "Continuing without mounted eBPF fs. Too old kernel?\n"); } int iproute2_get_root_path(enum bpf_prog_type type, char *root_path, size_t len) { + const char *wrk_dir; int ret; bpf_init_env(); - snprintf(root_path, len, "%s/%s", - bpf_get_work_dir(type), BPF_DIR_GLOBALS); + wrk_dir = bpf_get_work_dir(type); + if (!wrk_dir) { + fprintf(stderr, "No mounted eBPF fs to pin maps under\n"); + return -1; + } + + if ((size_t)snprintf(root_path, len, "%s/%s", + wrk_dir, BPF_DIR_GLOBALS) >= len) { + fprintf(stderr, "Pin root path for %s too long\n", wrk_dir); + return -1; + } ret = mkdir(root_path, S_IRWXU); if (ret && errno != EEXIST) { -- 2.53.0