From: Stephen Hemminger <stephen@networkplumber.org>
To: netdev@vger.kernel.org
Cc: dsahern@kernel.org,
"Stephen Hemminger" <stephen@networkplumber.org>,
"Hangbin Liu" <haliu@redhat.com>,
"Toke Høiland-Jørgensen" <toke@redhat.com>
Subject: [PATCH iproute2-next 5/5] lib/bpf: check for missing bpf fs mount point
Date: Wed, 18 Nov 2026 16:15:09 -0800 [thread overview]
Message-ID: <20261119001539.2868072-6-stephen@networkplumber.org> (raw)
In-Reply-To: <20261119001539.2868072-1-stephen@networkplumber.org>
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 <stephen@networkplumber.org>
---
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
prev parent reply other threads:[~2026-11-19 0:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 0:15 [PATCH iproute2-next 0/5] bpf: fix mount point parsing and drop the legacy loader Stephen Hemminger
2026-11-19 0:15 ` [PATCH iproute2-next 1/5] lib/bpf: parse /proc/mounts with getmntent and check fs magic Stephen Hemminger
2026-11-19 0:15 ` [PATCH iproute2-next 2/5] lib/fs: " Stephen Hemminger
2026-11-19 0:15 ` [PATCH iproute2-next 3/5] tc: remove eBPF map export and exec bpf import Stephen Hemminger
2026-11-19 0:15 ` [PATCH iproute2-next 4/5] lib/bpf: require libbpf and remove legacy ELF loader Stephen Hemminger
2026-11-19 0:15 ` Stephen Hemminger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119001539.2868072-6-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dsahern@kernel.org \
--cc=haliu@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=toke@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox