Skip to content

eBPF-based security platform

paths: build an upatch's pin paths in one place

Daniel Borkmann942dda44f810
diff --git a/.agents/skills/coding/SKILL.md b/.agents/skills/coding/SKILL.md
index 14789bf0..e0b81d5a 100644
--- a/.agents/skills/coding/SKILL.md
+++ b/.agents/skills/coding/SKILL.md
@@ -100,6 +100,7 @@ extra check left to the caller, and move one found in a builtin into
|---|---|
| Parse a number | `parse_u64()`, `parse_s64()`, `parse_x64()`, `digits()` (`<shirudo/string.h>`) |
| Copy or format a string | `strscpy()`, `strsprintf()`, `vstrsprintf()`, and check `-E2BIG` |
+| An upatch's pin directory or a pin in it | `upatch_pin_path()` (`util/paths.h`) |
| A file name's extension | `name_has_suffix()` (`<shirudo/string.h>`), `upatch_select()` for a scandir of upatches |
| Text from outside on a terminal | `text_sanitize()`; UTF-8 with `utf8_width()` |
| Sizes and lengths | `check_add_overflow()` and kin, `size_add()`, `size_mul()`, `struct_size()` (`<shirudo/overflow.h>`) |
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rst
index 7276f30e..1a635852 100644
--- a/Documentation/contribute/testing/proof-coverage.rst
+++ b/Documentation/contribute/testing/proof-coverage.rst
@@ -73,6 +73,12 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.
- ``lines_len()``
- Up to 8 bytes
- Ends at a newline or is 0, with no newline behind it
+ * - ``paths-bpffs-name``
+ - ``upatch_bpffs_name()``, ``upatch_name_from_bpffs()``
+ - Names up to 4 bytes, pin names up to 8
+ - A name without ``~`` maps to a pin name without a dot and back to
+ itself; a pin name without a dot that decodes is the encoding of
+ what it decodes to
* - ``bpm-upatch-member``
- ``bpm_upatch_member()``, ``bpm_upatch_pair()``
- Lengths 0 to 18
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index f94e4422..932256ad 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -491,11 +491,11 @@ signed config image.
Unit suites and fuzz targets
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-The unit suites in :src:`testing/unit/` cover sixteen of the modules in
+The unit suites in :src:`testing/unit/` cover seventeen of the modules in
:src:`util/`: ``bpm_oci``, ``bpm_package``, ``bpm_tree``,
``bpm_tree_state``, ``chain``, ``eventlog``, ``format``, ``hex``, ``io``,
``json``, ``kernel_abi``, ``kernel_build_id``, ``kernel_release``,
-``string``, ``upatch`` and ``upatch_decode``, and ``overflow`` the arithmetic of
+``paths``, ``string``, ``upatch`` and ``upatch_decode``, and ``overflow`` the arithmetic of
:src:`include/shirudo/overflow.h`. The other modules are reached through
the test helpers, the fuzz targets and the binaries the functional tests
run.
diff --git a/Makefile.shirudo b/Makefile.shirudo
index 3d09ff7e..cb9e8e4a 100644
--- a/Makefile.shirudo
+++ b/Makefile.shirudo
@@ -805,6 +805,7 @@ testing/helper/test-otel-map: testing/helper/test-otel-map.c util/upatch_maps.o
util/config.o util/image_config.o \
util/upatch_decode.o util/upatch_resolve.o \
util/upatch.o util/json.o util/string.o util/log.o \
+ util/paths.o \
util/io.o util/malloc.o $(LIBBPF_A) util/hex.o util/timefmt.o
@printf ' CC $@\n'
$(Q)$(CC) $(CFLAGS) -o $@ $^ $(DYNAMIC_LIBS)
@@ -823,7 +824,7 @@ testing/helper/test-upatch-serializer-pages: testing/helper/test-upatch-serializ
util/serializer.o util/seal.o \
util/json.o util/string.o \
util/config.o util/image_config.o \
- util/malloc.o util/io.o \
+ util/malloc.o util/io.o util/paths.o \
util/log.o util/hex.o util/timefmt.o
@printf ' CC $@\n'
$(Q)$(CC) $(CFLAGS) -o $@ $^ $(STATIC_LIBS) $(DYNAMIC_LIBS)
@@ -1030,7 +1031,7 @@ testing/fuzz/fuzz-elf: FUZZ_CFLAGS += $(LIBELF_CFLAGS)
testing/fuzz/fuzz-elf: FUZZ_LIBS += $(LIBBPF_A) $(LIBELF_LIBS)
testing/fuzz/fuzz-serializer: testing/fuzz/fuzz-serializer.c $(FUZZ_BASE) \
util/upatch_maps.c util/upatch_resolve.c \
- util/serializer.c $(FUZZ_SEAL) util/io.c \
+ util/serializer.c $(FUZZ_SEAL) util/io.c util/paths.c \
util/timefmt.c $(LIBBPF_A)
testing/fuzz/fuzz-serializer: FUZZ_CFLAGS += $(LIBELF_CFLAGS)
testing/fuzz/fuzz-serializer: FUZZ_LIBS += $(LIBBPF_A) $(LIBELF_LIBS)
diff --git a/builtin-upatch.c b/builtin-upatch.c
index d781ef68..e292c9df 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -489,7 +489,6 @@ static int is_not_dot(const struct dirent *e)
static bool upatch_is_loaded(const char *name)
{
char pin[PATH_MAX];
- char bpffs_name[UPATCH_BPFFS_NAME_MAX + 1];
struct stat st;
int fd;
@@ -500,10 +499,7 @@ static bool upatch_is_loaded(const char *name)
return true;
test_pin:
- if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
- return false;
- if (strsprintf(pin, sizeof(pin), "%s/%s/test",
- BPFFS_UPATCHES_DIR, bpffs_name) < 0)
+ if (upatch_pin_path(pin, sizeof(pin), name, "test", NULL))
return false;
return stat(pin, &st) == 0;
}
@@ -1336,7 +1332,6 @@ static int attach_and_pin_progs(const struct loader_ctx *cx,
const struct prog_spec *specs)
{
char dir[PATH_MAX], serializers_dir[PATH_MAX + 16];
- char bpffs_name[UPATCH_BPFFS_NAME_MAX + 1];
__u32 i, attach_count = 0, attach_seen = 0;
bool made_dir = false, made_serializers = false;
char pin[PATH_MAX + 32];
@@ -1348,7 +1343,7 @@ static int attach_and_pin_progs(const struct loader_ctx *cx,
pr_warn("upatch carries no programs to attach");
return 0;
}
- if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
+ if (upatch_pin_path(dir, sizeof(dir), name, NULL))
return -ENAMETOOLONG;
ret = mkdir_if_absent(BPFFS_UPATCHES_DIR, 0700, NULL);
@@ -1357,9 +1352,6 @@ static int attach_and_pin_progs(const struct loader_ctx *cx,
strerror(-ret));
return ret;
}
- if (strsprintf(dir, sizeof(dir), "%s/%s",
- BPFFS_UPATCHES_DIR, bpffs_name) < 0)
- return -ENAMETOOLONG;
if (strsprintf(serializers_dir, sizeof(serializers_dir),
"%s/serializers", dir) < 0)
return -ENAMETOOLONG;
@@ -1529,17 +1521,13 @@ static int pin_upatch_maps(const struct loader_ctx *cx,
const char *name)
{
char dir[PATH_MAX], maps_dir[PATH_MAX + 8];
- char bpffs_name[UPATCH_BPFFS_NAME_MAX + 1];
char pin[PATH_MAX + 32];
__u32 i;
int ret;
if (nr_maps == 0)
return 0;
- if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
- return 0;
- if (strsprintf(dir, sizeof(dir), "%s/%s",
- BPFFS_UPATCHES_DIR, bpffs_name) < 0)
+ if (upatch_pin_path(dir, sizeof(dir), name, NULL))
return -ENAMETOOLONG;
if (strsprintf(maps_dir, sizeof(maps_dir), "%s/maps", dir) < 0)
return -ENAMETOOLONG;
@@ -1635,12 +1623,8 @@ err:
static void set_pin_payload(const char *name, const __u8 payload[32])
{
char dir[PATH_MAX];
- char bpffs_name[UPATCH_BPFFS_NAME_MAX + 1];
- if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
- return;
- if (strsprintf(dir, sizeof(dir), "%s/%s", BPFFS_UPATCHES_DIR,
- bpffs_name) < 0)
+ if (upatch_pin_path(dir, sizeof(dir), name, NULL))
return;
if (setxattr(dir, XATTR_PAYLOAD, payload, 32, 0) != 0)
pr_err("upatch: cannot record payload xattr on %s: %s "
@@ -1651,13 +1635,9 @@ static void set_pin_payload(const char *name, const __u8 payload[32])
static int get_pin_payload(const char *name, __u8 out[32])
{
char dir[PATH_MAX];
- char bpffs_name[UPATCH_BPFFS_NAME_MAX + 1];
ssize_t n;
- if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
- return -ENAMETOOLONG;
- if (strsprintf(dir, sizeof(dir), "%s/%s", BPFFS_UPATCHES_DIR,
- bpffs_name) < 0)
+ if (upatch_pin_path(dir, sizeof(dir), name, NULL))
return -ENAMETOOLONG;
n = getxattr(dir, XATTR_PAYLOAD, out, 32);
if (n < 0)
@@ -2712,13 +2692,9 @@ static int wipe_dir_flat(const char *dir)
static bool upatch_is_pinned(const char *name)
{
char dir[PATH_MAX];
- char bpffs_name[UPATCH_BPFFS_NAME_MAX + 1];
struct stat st;
- if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
- return false;
- if (strsprintf(dir, sizeof(dir), "%s/%s", BPFFS_UPATCHES_DIR,
- bpffs_name) < 0)
+ if (upatch_pin_path(dir, sizeof(dir), name, NULL))
return false;
return stat(dir, &st) == 0;
}
@@ -2728,14 +2704,10 @@ static int remove_pin_dir(const char *name)
{
char dir[PATH_MAX], maps_dir[PATH_MAX + 8];
char serializers_dir[PATH_MAX + 16];
- char bpffs_name[UPATCH_BPFFS_NAME_MAX + 1];
struct stat st;
int ret;
- if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
- return -ENAMETOOLONG;
- if (strsprintf(dir, sizeof(dir), "%s/%s", BPFFS_UPATCHES_DIR,
- bpffs_name) < 0)
+ if (upatch_pin_path(dir, sizeof(dir), name, NULL))
return -ENAMETOOLONG;
if (strsprintf(maps_dir, sizeof(maps_dir), "%s/maps", dir) < 0)
return -ENAMETOOLONG;
diff --git a/include/shirudo/compiler.h b/include/shirudo/compiler.h
index e1e4026d..5dd755fa 100644
--- a/include/shirudo/compiler.h
+++ b/include/shirudo/compiler.h
@@ -11,6 +11,7 @@
#define __printf(a, b) __attribute__((format(printf, a, b)))
#define __must_check __attribute__((warn_unused_result))
#define __noreturn __attribute__((noreturn))
+#define __sentinel __attribute__((sentinel))
#define __cleanup(func) __attribute__((cleanup(func)))
#define noinline __attribute__((noinline))
/* A function with a large frame that inlining would add to its caller's. */
diff --git a/testing/proofs/cbmc/paths-bpffs-name.c b/testing/proofs/cbmc/paths-bpffs-name.c
new file mode 100644
index 00000000..6e13bdb4
--- /dev/null
+++ b/testing/proofs/cbmc/paths-bpffs-name.c
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * upatch_bpffs_name() and upatch_name_from_bpffs() of util/paths.h, which
+ * map an upatch name to its pin directory and back, on every string of up
+ * to LEN_MAX bytes: a name without the ~ no valid name has maps to one
+ * without a dot, which bpffs refuses, and back to itself, and a pin name
+ * without a dot that decodes is the encoding of what it decodes to.
+ */
+
+#include <stdbool.h>
+
+#include "proof.h"
+#include "../../../util/paths.h"
+
+#define LEN_MAX 4
+
+static char *any_string(size_t len)
+{
+ char *s = any_bytes(len + 1);
+
+ __CPROVER_assume(!s[len] && strnlen(s, len) == len);
+ return s;
+}
+
+static bool holds(const char *s, size_t len, char c)
+{
+ return memchr(s, c, len);
+}
+
+static void name_round_trips(void)
+{
+ char bpffs[2 * LEN_MAX + 1], back[LEN_MAX + 1];
+ size_t len;
+ char *name;
+
+ __CPROVER_assume(len <= LEN_MAX);
+ name = any_string(len);
+ __CPROVER_assume(!holds(name, len, '~'));
+ __CPROVER_assert(!upatch_bpffs_name(bpffs, sizeof(bpffs), name),
+ "every name fits twice its length");
+ __CPROVER_assert(!holds(bpffs, strnlen(bpffs, sizeof(bpffs)), '.'),
+ "no dot for bpffs");
+ __CPROVER_assert(!upatch_name_from_bpffs(back, sizeof(back), bpffs) &&
+ strnlen(back, sizeof(back)) == len &&
+ !memcmp(back, name, len),
+ "and back to the name");
+}
+
+static void pin_name_is_an_encoding(void)
+{
+ char name[2 * LEN_MAX + 1], again[4 * LEN_MAX + 1];
+ size_t len;
+ char *pin;
+
+ __CPROVER_assume(len <= 2 * LEN_MAX);
+ pin = any_string(len);
+ __CPROVER_assume(!holds(pin, len, '.'));
+ if (upatch_name_from_bpffs(name, sizeof(name), pin))
+ return;
+ __CPROVER_assert(!upatch_bpffs_name(again, sizeof(again), name) &&
+ strnlen(again, sizeof(again)) == len &&
+ !memcmp(again, pin, len),
+ "the encoding of the name it decodes to");
+}
+
+void harness(void)
+{
+ name_round_trips();
+ pin_name_is_an_encoding();
+}
diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.list
index 94692311..060e4a1b 100644
--- a/testing/proofs/cbmc/proofs.list
+++ b/testing/proofs/cbmc/proofs.list
@@ -7,6 +7,7 @@ string-suffix --unwind 8
string-sanitize --unwind 8 LEN=0-6
hex --unwind 12
io-lines --unwind 10
+paths-bpffs-name --unwind 18
upatch-header --unwind 2 --unwindset memchr.0:257
string-number-model --unwind 6
bpm-upatch-member --unwind 30 LEN=0-18
diff --git a/testing/unit/paths.c b/testing/unit/paths.c
new file mode 100644
index 00000000..cf107974
--- /dev/null
+++ b/testing/unit/paths.c
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/* Copyright (c) 2026 Authors of shirudo */
+
+#include <errno.h>
+#include <string.h>
+
+#include "paths.h"
+#include "unit.h"
+
+static void pin_path_is_the_bpffs_name_and_its_parts(void)
+{
+ char out[256];
+
+ ASSERT_EQ(upatch_pin_path(out, sizeof(out), "kernel.obs", NULL), 0);
+ EXPECT_STREQ(out, BPFFS_UPATCHES_DIR "/kernel~dobs");
+ ASSERT_EQ(upatch_pin_path(out, sizeof(out), "a", "link", NULL), 0);
+ EXPECT_STREQ(out, BPFFS_UPATCHES_DIR "/a/link");
+ ASSERT_EQ(upatch_pin_path(out, sizeof(out), "a.b", "maps", "m.1", NULL),
+ 0);
+ EXPECT_STREQ(out, BPFFS_UPATCHES_DIR "/a~db/maps/m.1");
+}
+
+static void pin_path_too_long_is_empty(void)
+{
+ char out[sizeof(BPFFS_UPATCHES_DIR "/a/link")];
+
+ EXPECT_EQ(upatch_pin_path(out, sizeof(out), "a", "link", NULL), 0);
+ EXPECT_EQ(upatch_pin_path(out, sizeof(out), "ab", "link", NULL),
+ -ENAMETOOLONG);
+ EXPECT_STREQ(out, "");
+ EXPECT_EQ(upatch_pin_path(out, sizeof(out), "a", "links", NULL),
+ -ENAMETOOLONG);
+ EXPECT_STREQ(out, "");
+}
+
+static void bpffs_name_round_trips(void)
+{
+ char bpffs[64], back[32];
+
+ ASSERT_EQ(upatch_bpffs_name(bpffs, sizeof(bpffs), "a.b..c"), 0);
+ EXPECT_STREQ(bpffs, "a~db~d~dc");
+ ASSERT_EQ(upatch_name_from_bpffs(back, sizeof(back), bpffs), 0);
+ EXPECT_STREQ(back, "a.b..c");
+ EXPECT_EQ(upatch_name_from_bpffs(back, sizeof(back), "a~x"), -EINVAL);
+ EXPECT_EQ(upatch_name_from_bpffs(back, sizeof(back), "a~"), -EINVAL);
+ EXPECT_EQ(upatch_bpffs_name(bpffs, 4, "a.b"), -ENAMETOOLONG);
+}
+
+static const struct unit_case cases[] = {
+ UNIT_CASE(pin_path_is_the_bpffs_name_and_its_parts),
+ UNIT_CASE(pin_path_too_long_is_empty),
+ UNIT_CASE(bpffs_name_round_trips),
+ {}
+};
+
+UNIT_SUITE(paths, cases);
diff --git a/util/paths.c b/util/paths.c
index 583bbab2..22bcbd70 100644
--- a/util/paths.c
+++ b/util/paths.c
@@ -6,12 +6,14 @@
*/
#include <errno.h>
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <shirudo/string.h>
+#include <shirudo/upatch.h>
#include "paths.h"
@@ -56,6 +58,38 @@ int key_paths(const char *keys_dir,
CERT_FILE);
}
+int upatch_pin_path(char *out, size_t cap, const char *name, ...)
+{
+ char bpffs_name[UPATCH_BPFFS_NAME_MAX + 1];
+ const char *part;
+ int n, ret = 0;
+ size_t len;
+ va_list ap;
+
+ if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
+ goto too_long;
+ n = strsprintf(out, cap, "%s/%s", BPFFS_UPATCHES_DIR, bpffs_name);
+ if (n < 0)
+ goto too_long;
+ len = n;
+ va_start(ap, name);
+ while ((part = va_arg(ap, const char *))) {
+ n = strsprintf(out + len, cap - len, "/%s", part);
+ if (n < 0) {
+ ret = -ENAMETOOLONG;
+ break;
+ }
+ len += n;
+ }
+ va_end(ap);
+ if (!ret)
+ return 0;
+too_long:
+ if (cap)
+ out[0] = '\0';
+ return -ENAMETOOLONG;
+}
+
bool path_exists(const char *path)
{
struct stat st;
diff --git a/util/paths.h b/util/paths.h
index 8ca3c9b8..113a70bb 100644
--- a/util/paths.h
+++ b/util/paths.h
@@ -205,6 +205,13 @@ static inline int upatch_name_from_bpffs(char *out, size_t out_sz,
return 0;
}
+/*
+ * The pin directory of the upatch name, BPFFS_UPATCHES_DIR and its bpffs
+ * name, and then each path component that follows, up to the NULL that
+ * ends them. 0, or -ENAMETOOLONG with out empty.
+ */
+int upatch_pin_path(char *out, size_t cap, const char *name, ...) __sentinel;
+
bool path_exists(const char *path);
#endif /* SHIRUDO_PATHS_H */
diff --git a/util/upatch_maps.c b/util/upatch_maps.c
index c16646ee..02d8b23e 100644
--- a/util/upatch_maps.c
+++ b/util/upatch_maps.c
@@ -726,14 +726,10 @@ static int open_map_pin(const char *upatch, const char *map_name,
int *fd_out, struct bpf_map_info *info_out)
{
char path[PATH_MAX];
- char bpffs_name[UPATCH_BPFFS_NAME_MAX + 1];
__u32 info_len = sizeof(*info_out);
int fd;
- if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), upatch))
- return -ENAMETOOLONG;
- if (strsprintf(path, sizeof(path), "%s/%s/maps/%s",
- BPFFS_UPATCHES_DIR, bpffs_name, map_name) < 0)
+ if (upatch_pin_path(path, sizeof(path), upatch, "maps", map_name, NULL))
return -ENAMETOOLONG;
fd = bpf_obj_get(path);
if (fd < 0)
@@ -759,13 +755,10 @@ static struct btf *try_load_btf(__u32 btf_id)
static int open_serializer_pin(const char *upatch, const char *map_name)
{
char path[PATH_MAX];
- char bpffs_name[UPATCH_BPFFS_NAME_MAX + 1];
int fd;
- if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), upatch))
- return -ENAMETOOLONG;
- if (strsprintf(path, sizeof(path), "%s/%s/serializers/%s",
- BPFFS_UPATCHES_DIR, bpffs_name, map_name) < 0)
+ if (upatch_pin_path(path, sizeof(path), upatch, "serializers",
+ map_name, NULL))
return -ENAMETOOLONG;
fd = bpf_obj_get(path);
if (fd < 0)
@@ -1230,7 +1223,6 @@ int upatch_maps_read(const char *upatch, const char *map,
{
struct bpf_map_info info = {};
char upatch_dir[PATH_MAX];
- char bpffs_name[UPATCH_BPFFS_NAME_MAX + 1];
struct stat upatch_st;
int fd = -1;
int ret;
@@ -1260,9 +1252,7 @@ int upatch_maps_read(const char *upatch, const char *map,
out->n_cpus = (__u32)n;
}
resolve_map_location(out);
- if (!upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), upatch) &&
- strsprintf(upatch_dir, sizeof(upatch_dir), "%s/%s",
- BPFFS_UPATCHES_DIR, bpffs_name) >= 0 &&
+ if (!upatch_pin_path(upatch_dir, sizeof(upatch_dir), upatch, NULL) &&
stat(upatch_dir, &upatch_st) == 0)
out->lifetime_start_ns =
(__u64)upatch_st.st_ctim.tv_sec * 1000000000ULL +
@@ -1333,14 +1323,10 @@ static void scan_upatch_maps(const char *upatch,
size_t *cap)
{
char dir[PATH_MAX];
- char bpffs_name[UPATCH_BPFFS_NAME_MAX + 1];
struct dirent *e;
DIR *d;
- if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), upatch))
- return;
- if (strsprintf(dir, sizeof(dir), "%s/%s/maps",
- BPFFS_UPATCHES_DIR, bpffs_name) < 0)
+ if (upatch_pin_path(dir, sizeof(dir), upatch, "maps", NULL))
return;
d = opendir(dir);
if (!d)
diff --git a/util/upatch_resolve.c b/util/upatch_resolve.c
index 7fb71e96..9fb647de 100644
--- a/util/upatch_resolve.c
+++ b/util/upatch_resolve.c
@@ -42,21 +42,16 @@
int upatch_open_first_link(const char *name)
{
char pin[PATH_MAX];
- char bpffs_name[UPATCH_BPFFS_NAME_MAX + 1];
int fd, first_errno;
- if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
- return -ENAMETOOLONG;
- if (strsprintf(pin, sizeof(pin), "%s/%s/link",
- BPFFS_UPATCHES_DIR, bpffs_name) < 0)
+ if (upatch_pin_path(pin, sizeof(pin), name, "link", NULL))
return -ENAMETOOLONG;
fd = bpf_obj_get(pin);
if (fd >= 0)
return fd;
first_errno = errno;
- if (strsprintf(pin, sizeof(pin), "%s/%s/link_0",
- BPFFS_UPATCHES_DIR, bpffs_name) < 0)
+ if (upatch_pin_path(pin, sizeof(pin), name, "link_0", NULL))
return -ENAMETOOLONG;
fd = bpf_obj_get(pin);
if (fd >= 0)
@@ -193,14 +188,10 @@ int upatch_resolve_location(struct btf *vbtf, const char *name,
void upatch_loaded_at(const char *name, char *out, size_t cap)
{
char dir[PATH_MAX];
- char bpffs_name[UPATCH_BPFFS_NAME_MAX + 1];
struct stat st;
out[0] = '\0';
- if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
- return;
- if (strsprintf(dir, sizeof(dir), "%s/%s",
- BPFFS_UPATCHES_DIR, bpffs_name) < 0)
+ if (upatch_pin_path(dir, sizeof(dir), name, NULL))
return;
if (stat(dir, &st) != 0)
return;
@@ -210,17 +201,13 @@ void upatch_loaded_at(const char *name, char *out, size_t cap)
void upatch_payload_sha256(const char *name, char *out, size_t cap)
{
char dir[PATH_MAX];
- char bpffs_name[UPATCH_BPFFS_NAME_MAX + 1];
__u8 raw[32];
ssize_t n;
out[0] = '\0';
if (cap < 65)
return;
- if (upatch_bpffs_name(bpffs_name, sizeof(bpffs_name), name))
- return;
- if (strsprintf(dir, sizeof(dir), "%s/%s",
- BPFFS_UPATCHES_DIR, bpffs_name) < 0)
+ if (upatch_pin_path(dir, sizeof(dir), name, NULL))
return;
n = getxattr(dir, XATTR_PAYLOAD, raw, sizeof(raw));
if (n != (ssize_t)sizeof(raw))