Skip to content

eBPF-based security platform

upatch: name an fentry, fexit or lsm program by its kind in the load

Daniel Borkmanna227d6b3f100
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index cb605f93..10e0f13a 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -329,12 +329,12 @@ signed config image.
copying failing decrypt moves only ``activity``; the unload removes it
* - ``t3118-fentry-fexit``
- Live ``fentry`` and ``fexit`` links attach to ``vfs_fallocate()``
- from one upatch and report their kinds. The ``fentry`` program
- sees a call with its arguments and follows a pointer among them
- to the file's inode number. The ``fexit`` program sees a call
- that succeeds and a call the kernel refuses, each with the
- arguments as passed and the value returned. The unload detaches
- both
+ from one upatch, and the load and ``get`` name each kind. The
+ ``fentry`` program sees a call with its arguments and follows a
+ pointer among them to the file's inode number. The ``fexit``
+ program sees a call that succeeds and a call the kernel refuses,
+ each with the arguments as passed and the value returned. The
+ unload detaches both
* - ``t3119-fmod-ret``
- Live ``fmod_ret`` links. On ``security_task_setnice()``, a target
on every kernel, the program fails the one call it is written
diff --git a/Documentation/reference/cli/upatch-load.rst b/Documentation/reference/cli/upatch-load.rst
index 562f3ce0..1785080e 100644
--- a/Documentation/reference/cli/upatch-load.rst
+++ b/Documentation/reference/cli/upatch-load.rst
@@ -238,7 +238,7 @@ Load an artifact and print the report:
target# shirudo upatch load --report=- shirudo-test-basic.upatch
upatch load: signed loader accepted, keyring 272801410, 124 instructions
upatch load: loader ran, 0 maps and 1 programs
- upatch load: program 0 (raw_tracepoint) pinned at /run/shirudo/bpffs/upatches/shirudo-test-basic/link
+ upatch load: program 0 (fentry) pinned at /run/shirudo/bpffs/upatches/shirudo-test-basic/link
upatch load: shirudo-test-basic loaded, 1 programs, keyring 272801410
upatch load: shirudo-test-basic measured, register 7f63313a31ac8ddd3a6a16fce2038322c9c782d5787155d2dc18dfa582dff548
diff --git a/Documentation/start/guides/first-upatch.rst b/Documentation/start/guides/first-upatch.rst
index 33669d3c..f8f95114 100644
--- a/Documentation/start/guides/first-upatch.rst
+++ b/Documentation/start/guides/first-upatch.rst
@@ -136,7 +136,7 @@ Load it and read the map
target# shirudo upatch load /workspace/shirudo/build/tutorial/sleep-count.upatch
upatch load: signed loader accepted, keyring 272801410, 148 instructions
upatch load: loader ran, 1 maps and 1 programs
- upatch load: program 0 (raw_tracepoint) pinned at /run/shirudo/bpffs/upatches/sleep-count/link
+ upatch load: program 0 (fentry) pinned at /run/shirudo/bpffs/upatches/sleep-count/link
upatch load: map 0 (calls) pinned at /run/shirudo/bpffs/upatches/sleep-count/maps/calls
upatch load: sleep-count loaded, 1 programs, keyring 272801410
upatch load: sleep-count measured, register 88e45b0c80b0ffe83d471b6372402082a5dcf82173adc5c4bdd631039fe4609c
diff --git a/Documentation/start/guides/publish-package.rst b/Documentation/start/guides/publish-package.rst
index c3ff92e9..9cd0bf46 100644
--- a/Documentation/start/guides/publish-package.rst
+++ b/Documentation/start/guides/publish-package.rst
@@ -151,7 +151,7 @@ none, so here the target installs by direct reference.
upatch load: --no-precheck, pre-flight state check skipped
upatch load: signed loader accepted, keyring 272801410, 124 instructions
upatch load: loader ran, 0 maps and 1 programs
- upatch load: program 0 (raw_tracepoint) pinned at /run/shirudo/bpffs/upatches/hello/link
+ upatch load: program 0 (fentry) pinned at /run/shirudo/bpffs/upatches/hello/link
upatch load: hello loaded, 1 programs, keyring 272801410
upatch load: hello measured, register 55a8c670eb10d9bc6a9dc7475e3fc94407066016798dddbc59870138525f61b6
diff --git a/Documentation/start/quickstart.rst b/Documentation/start/quickstart.rst
index 782d623e..22b19b5f 100644
--- a/Documentation/start/quickstart.rst
+++ b/Documentation/start/quickstart.rst
@@ -398,7 +398,7 @@ Load it
target# shirudo upatch load basic.upatch
upatch load: signed loader accepted, keyring 1025034781, 124 instructions
upatch load: loader ran, 0 maps and 1 programs
- upatch load: program 0 (raw_tracepoint) pinned at /run/shirudo/bpffs/upatches/basic/link
+ upatch load: program 0 (fentry) pinned at /run/shirudo/bpffs/upatches/basic/link
upatch load: basic loaded, 1 programs, keyring 1025034781
upatch load: basic measured, register 2705e01ee2dbc5b81b7ba45749aa06251a32b535142788ef24a40be985b78bf7
diff --git a/Documentation/upatches/learn/kernel-fix-tutorial.rst b/Documentation/upatches/learn/kernel-fix-tutorial.rst
index cddea175..0ac5d333 100644
--- a/Documentation/upatches/learn/kernel-fix-tutorial.rst
+++ b/Documentation/upatches/learn/kernel-fix-tutorial.rst
@@ -259,7 +259,7 @@ runtime image. Load the upatch and print the report:
/mnt/shirudo-src/build/rpl-shield/cve-2026-63984-rpl.upatch
upatch load: signed loader accepted, keyring 531121468, 172 instructions
upatch load: loader ran, 2 maps and 1 programs
- upatch load: program 0 (raw_tracepoint) pinned at /run/shirudo/bpffs/upatches/cve-2026-63984-rpl/link
+ upatch load: program 0 (fentry) pinned at /run/shirudo/bpffs/upatches/cve-2026-63984-rpl/link
upatch load: map 0 (hits) pinned at /run/shirudo/bpffs/upatches/cve-2026-63984-rpl/maps/hits
upatch load: map 1 (activity) pinned at /run/shirudo/bpffs/upatches/cve-2026-63984-rpl/maps/activity
upatch load: cve-2026-63984-rpl loaded, 1 programs, keyring 531121468
@@ -269,9 +269,9 @@ runtime image. Load the upatch and print the report:
The log lines go to standard error and the JSON report to standard
output. The report has ``"result":"ok"``, phase ``done`` and category
``ok``, and its ``tpm.chain_after`` is the measurement register after the
-load. ``program 0 (raw_tracepoint) pinned at ...`` means that shirudo
-attached the fentry program through ``BPF_RAW_TRACEPOINT_OPEN`` at the
-function the verifier bound, and pinned the link.
+load. ``program 0 (fentry) pinned at ...`` means that shirudo attached
+the fentry program at the function the verifier bound, and pinned the
+link.
:doc:`/upatches/test/debugging` explains the report when a load fails.
Check where the kernel attached it and read the counters:
diff --git a/builtin-upatch.c b/builtin-upatch.c
index 96012369..0fbc377a 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -1283,6 +1283,22 @@ static const char *attach_kind_name(__u32 kind)
}
}
+/*
+ * UPATCH_ATTACH_RAW_TRACEPOINT is the kind of every program the builder
+ * gave none of its own: fentry, fexit, lsm and tp_btf. The link says which.
+ */
+static const char *link_kind_name(const struct prog_spec *spec, int link_fd)
+{
+ struct bpf_link_info info = {};
+ __u32 len = sizeof(info);
+ const char *kind = NULL;
+
+ if (spec->kind == UPATCH_ATTACH_RAW_TRACEPOINT &&
+ !bpf_link_get_info_by_fd(link_fd, &info, &len))
+ kind = upatch_tracing_link_kind(&info);
+ return kind ? kind : attach_kind_name(spec->kind);
+}
+
static int prepare_uprobe_targets(struct prog_spec *specs,
__u32 nr_progs)
{
@@ -1785,6 +1801,7 @@ static int attach_and_pin_progs(const struct loader_ctx *cx,
(size_t)i * sizeof(*pd));
int inner_fd = pd->prog_fd;
const struct prog_spec *spec = &specs[i];
+ const char *kind;
int link_fd;
if (inner_fd <= 0) {
@@ -1888,6 +1905,7 @@ static int attach_and_pin_progs(const struct loader_ctx *cx,
close(link_fd);
goto out;
}
+ kind = link_kind_name(spec, link_fd);
ret = obj_pin(link_fd, pin);
close(link_fd);
if (ret) {
@@ -1898,7 +1916,7 @@ static int attach_and_pin_progs(const struct loader_ctx *cx,
if (has_xdp)
pinned_links++;
pr_info("upatch load: program %u (%s) pinned at %s",
- i, attach_kind_name(spec->kind), pin);
+ i, kind, pin);
}
if (test_fd >= 0) {
__u64 init_ctx[2] = {};
diff --git a/testing/functional/upatch/t3118-fentry-fexit.sh b/testing/functional/upatch/t3118-fentry-fexit.sh
index 01266815..9f898bc6 100755
--- a/testing/functional/upatch/t3118-fentry-fexit.sh
+++ b/testing/functional/upatch/t3118-fentry-fexit.sh
@@ -3,9 +3,9 @@
# Copyright (c) 2026 Authors of shirudo
#
# t3118 -- live fentry and fexit programs on one function: both links
-# attach and get names them, the fentry program sees a call with its
-# arguments and follows a pointer among them, the fexit program sees a
-# call that succeeded and a call the kernel refused, each with the
+# attach, the load and get name each kind, the fentry program sees a call
+# with its arguments and follows a pointer among them, the fexit program
+# sees a call that succeeded and a call the kernel refused, each with the
# arguments as passed and the value returned, and an unload detaches
# both.
@@ -26,9 +26,11 @@ for fixture in "$LOAD" "$UNLOAD"; do
[ -s "$fixture" ] || test_skip_all "missing fentry and fexit fixture: $fixture"
done
-test_expect_success 'both links are pinned' '
- "$SHIRUDO_BIN" upatch load "$LOAD" --no-precheck >/dev/null 2>&1 &&
- [ -e "$DIR/link_0" ] && [ -e "$DIR/link_1" ]
+test_expect_success 'both links are pinned, and the load names each kind' '
+ "$SHIRUDO_BIN" upatch load "$LOAD" --no-precheck >"$WORK/load.log" 2>&1 &&
+ [ -e "$DIR/link_0" ] && [ -e "$DIR/link_1" ] &&
+ grep -q "program 0 (fentry) pinned at $DIR/link_0" "$WORK/load.log" &&
+ grep -q "program 1 (fexit) pinned at $DIR/link_1" "$WORK/load.log"
'
test_expect_success 'get reports both kinds and the function' '
diff --git a/testing/unit/upatch_resolve.c b/testing/unit/upatch_resolve.c
index cb0fb115..a8e450fb 100644
--- a/testing/unit/upatch_resolve.c
+++ b/testing/unit/upatch_resolve.c
@@ -103,11 +103,30 @@ static void a_kprobe_link_adds_what_it_counts_itself(void)
EXPECT_UEQ(upatch_link_missed(&info), 0);
}
+static void a_tracing_link_names_the_kind_of_its_program(void)
+{
+ struct bpf_link_info info = tracing_link(BPF_TRACE_FENTRY);
+
+ EXPECT_STREQ(upatch_tracing_link_kind(&info), "fentry");
+ info = tracing_link(BPF_TRACE_FEXIT);
+ EXPECT_STREQ(upatch_tracing_link_kind(&info), "fexit");
+ info = tracing_link(BPF_MODIFY_RETURN);
+ EXPECT_STREQ(upatch_tracing_link_kind(&info), "fmod_ret");
+ info = tracing_link(BPF_LSM_MAC);
+ EXPECT_STREQ(upatch_tracing_link_kind(&info), "lsm");
+
+ info = perf_link(BPF_PERF_EVENT_KPROBE);
+ EXPECT_TRUE(!upatch_tracing_link_kind(&info));
+ info = (struct bpf_link_info){ .type = BPF_LINK_TYPE_RAW_TRACEPOINT };
+ EXPECT_TRUE(!upatch_tracing_link_kind(&info));
+}
+
static const struct unit_case cases[] = {
UNIT_CASE(links_of_an_absent_upatch_are_not_read),
UNIT_CASE(the_kinds_the_kernel_counts_skipped_runs_of_count),
UNIT_CASE(the_kinds_it_never_skips_or_never_counts_do_not),
UNIT_CASE(a_kprobe_link_adds_what_it_counts_itself),
+ UNIT_CASE(a_tracing_link_names_the_kind_of_its_program),
{}
};
diff --git a/util/upatch_resolve.c b/util/upatch_resolve.c
index e27437ac..42be6c52 100644
--- a/util/upatch_resolve.c
+++ b/util/upatch_resolve.c
@@ -85,6 +85,16 @@ static const char *loc_prefix(__u32 prog_type, __u32 attach_type)
return NULL;
}
+const char *upatch_tracing_link_kind(const struct bpf_link_info *info)
+{
+ __u32 attach_type = info->tracing.attach_type;
+
+ if (info->type != BPF_LINK_TYPE_TRACING)
+ return NULL;
+ return loc_prefix(attach_type == BPF_LSM_MAC ? BPF_PROG_TYPE_LSM :
+ BPF_PROG_TYPE_TRACING, attach_type);
+}
+
int upatch_first_prog_id(const char *name, __u32 *out)
{
struct bpf_link_info linfo = {};
diff --git a/util/upatch_resolve.h b/util/upatch_resolve.h
index 8d067a12..618a3691 100644
--- a/util/upatch_resolve.h
+++ b/util/upatch_resolve.h
@@ -53,6 +53,12 @@ struct upatch_link_misses {
__u64 missed;
};
+/*
+ * The kind of the program behind a tracing link as a location names it:
+ * "fentry", "fexit", "fmod_ret" or "lsm". NULL for a link of another type.
+ */
+const char *upatch_tracing_link_kind(const struct bpf_link_info *info);
+
/*
* Whether the runs the kernel skips of the program behind this link are
* reported: kprobe, kretprobe, their multi forms, fentry, fexit, fmod_ret