Skip to content

eBPF-based security platform

testing: add tests for sleepable uprobe.multi attachment

Jiri Olsaace33cfadb2e
diff --git a/testing/fixtures/uprobe-multi-sleepable.bpf.c b/testing/fixtures/uprobe-multi-sleepable.bpf.c
new file mode 100644
index 00000000..fc2ff1b6
--- /dev/null
+++ b/testing/fixtures/uprobe-multi-sleepable.bpf.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+
+struct {
+ __uint(type, BPF_MAP_TYPE_ARRAY);
+ __uint(max_entries, 1);
+ __type(key, __u32);
+ __type(value, __u64);
+} hits SEC(".maps");
+
+char _license[] SEC("license") = "Dual BSD/GPL";
+
+/*
+ * The verifier offers bpf_copy_from_user() to sleepable programs alone,
+ * so a load proves the loader set BPF_F_SLEEPABLE.
+ */
+SEC("uprobe.multi.s//tmp/shirudo-test-uprobe-target:*Func")
+int probe_sleepable(struct pt_regs *ctx)
+{
+ struct task_struct *task = bpf_get_current_task_btf();
+ __u32 key = 0;
+ __u64 *value;
+ char c;
+
+ if (bpf_copy_from_user(&c, sizeof(c), (void *)task->mm->arg_start))
+ return 0;
+ value = bpf_map_lookup_elem(&hits, &key);
+ if (value)
+ __sync_fetch_and_add(value, 1);
+ return 0;
+}
diff --git a/testing/functional/upatch/t3007-uprobe-multi-metadata.sh b/testing/functional/upatch/t3007-uprobe-multi-metadata.sh
index a773522b..e3b4ad67 100644
--- a/testing/functional/upatch/t3007-uprobe-multi-metadata.sh
+++ b/testing/functional/upatch/t3007-uprobe-multi-metadata.sh
@@ -2,9 +2,10 @@
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2026 Authors of shirudo
#
-# t3007 -- uprobe.multi and uretprobe.multi SEC metadata resolves a
-# standard libbpf glob to sorted ELF file offsets and records the target's
-# GNU build ID; a uprobe section without a binary is refused.
+# t3007 -- uprobe.multi and uretprobe.multi SEC metadata, sleepable forms
+# included, resolves a standard libbpf glob to sorted ELF file offsets and
+# records the target's GNU build ID; a uprobe section without a binary is
+# refused.
cd "$(dirname "$0")/../.."
. ./test-lib.sh
@@ -112,4 +113,28 @@ test_expect_success 'a uprobe without a binary is refused' '
refused "uprobe"
'
+test_expect_success 'a sleepable uprobe.multi.s glob records the entry kind' '
+ write_probe "*Func" "uprobe.multi.s/$WORK/target:*Func" &&
+ ( cd .. && "$B" "$WORK/probe.bpf.c" \
+ -o "$WORK/uprobe-s.upatch" --vmlinux vendor/linux/vmlinux.h \
+ --name uprobe-multi-s-test --key "$WORK/k.pem" \
+ --cert "$WORK/c.der" ) >/dev/null 2>&1 &&
+ "$CHECK" "$WORK/uprobe-s.upatch" uprobe-multi \
+ "$WORK/target" "*Func" 2
+'
+
+test_expect_success 'a sleepable uretprobe.multi.s glob records the return kind' '
+ write_probe "*Func" "uretprobe.multi.s/$WORK/target:*Func" &&
+ ( cd .. && "$B" "$WORK/probe.bpf.c" \
+ -o "$WORK/uretprobe-s.upatch" --vmlinux vendor/linux/vmlinux.h \
+ --name uretprobe-multi-s-test --key "$WORK/k.pem" \
+ --cert "$WORK/c.der" ) >/dev/null 2>&1 &&
+ "$CHECK" "$WORK/uretprobe-s.upatch" uretprobe-multi \
+ "$WORK/target" "*Func" 2
+'
+
+test_expect_success 'a sleepable uprobe.session.s is refused' '
+ refused "uprobe.session.s/$WORK/target:*Func"
+'
+
test_done
diff --git a/testing/functional/upatch/t3107-uprobe-multi.sh b/testing/functional/upatch/t3107-uprobe-multi.sh
index 0003eaf6..b7013ff8 100644
--- a/testing/functional/upatch/t3107-uprobe-multi.sh
+++ b/testing/functional/upatch/t3107-uprobe-multi.sh
@@ -2,8 +2,8 @@
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2026 Authors of shirudo
#
-# t3107 -- live uprobe.multi and uretprobe.multi coverage using host-built
-# target fixtures.
+# t3107 -- live uprobe.multi, uretprobe.multi and sleepable uprobe.multi.s
+# coverage using host-built target fixtures.
cd "$(dirname "$0")/../.."
. ./integration-lib.sh
@@ -17,10 +17,14 @@ UNLOAD="$FIXTURES/$NAME.unload.upatch"
RET_NAME=shirudo-test-uretprobe-multi
RET_LOAD="$FIXTURES/$RET_NAME.upatch"
RET_UNLOAD="$FIXTURES/$RET_NAME.unload.upatch"
+SLEEP_NAME=shirudo-test-uprobe-multi-sleepable
+SLEEP_LOAD="$FIXTURES/$SLEEP_NAME.upatch"
+SLEEP_UNLOAD="$FIXTURES/$SLEEP_NAME.unload.upatch"
TARGET="$FIXTURES/shirudo-test-uprobe-target"
RUNTIME=/tmp/shirudo-test-uprobe-target
PIN="/run/shirudo/bpffs/upatches/$NAME/link"
RET_PIN="/run/shirudo/bpffs/upatches/$RET_NAME/link"
+SLEEP_PIN="/run/shirudo/bpffs/upatches/$SLEEP_NAME/link"
WORK=$(mktemp -d)
cleanup() {
if [ -e "$PIN" ]; then
@@ -29,11 +33,15 @@ cleanup() {
if [ -e "$RET_PIN" ]; then
"$SHIRUDO_BIN" upatch unload "$RET_UNLOAD" --no-precheck >/dev/null 2>&1 || true
fi
+ if [ -e "$SLEEP_PIN" ]; then
+ "$SHIRUDO_BIN" upatch unload "$SLEEP_UNLOAD" --no-precheck >/dev/null 2>&1 || true
+ fi
rm -rf "$WORK"
}
trap cleanup EXIT
-for fixture in "$LOAD" "$UNLOAD" "$RET_LOAD" "$RET_UNLOAD" "$TARGET"; do
+for fixture in "$LOAD" "$UNLOAD" "$RET_LOAD" "$RET_UNLOAD" "$SLEEP_LOAD" \
+ "$SLEEP_UNLOAD" "$TARGET"; do
[ -s "$fixture" ] || test_skip_all "missing uprobe fixture: $fixture"
done
@@ -92,4 +100,22 @@ PY
[ ! -e "$RET_PIN" ]
'
+test_expect_success 'a sleepable uprobe.multi.s reads user memory on both calls and unloads' '
+ "$SHIRUDO_BIN" upatch load "$SLEEP_LOAD" --no-precheck >/dev/null 2>&1 &&
+ [ -e "$SLEEP_PIN" ] &&
+ "$RUNTIME" &&
+ "$SHIRUDO_BIN" upatch get "$SLEEP_NAME" --json >"$WORK/sleep.json" &&
+ python3 - "$WORK/sleep.json" <<'PY' &&
+import json
+import sys
+doc = json.load(open(sys.argv[1], encoding="utf-8"))
+assert doc["upatch"]["location"] == \
+ "uprobe.multi//tmp/shirudo-test-uprobe-target (2 funcs)", doc
+hits = next(m for m in doc["upatch"]["maps"] if m["name"] == "hits")
+assert int(hits["entries"][0]["value"], 0) == 2, doc
+PY
+ "$SHIRUDO_BIN" upatch unload "$SLEEP_UNLOAD" --no-precheck >/dev/null 2>&1 &&
+ [ ! -e "$SLEEP_PIN" ]
+'
+
test_done
diff --git a/testing/vm/build-bundle.sh b/testing/vm/build-bundle.sh
index 7adfb66b..b79cc0d5 100755
--- a/testing/vm/build-bundle.sh
+++ b/testing/vm/build-bundle.sh
@@ -742,6 +742,7 @@ queue_fixture build_fixture serialized-metric.bpf.c shirudo-test-serialized-metr
queue_fixture build_fixture arena-tree-serializer.bpf.c shirudo-test-arena-tree "$FIXTURE_WORK/trusted"
queue_fixture build_fixture uprobe-multi.bpf.c shirudo-test-uprobe-multi "$FIXTURE_WORK/trusted"
queue_fixture build_fixture uretprobe-multi.bpf.c shirudo-test-uretprobe-multi "$FIXTURE_WORK/trusted"
+queue_fixture build_fixture uprobe-multi-sleepable.bpf.c shirudo-test-uprobe-multi-sleepable "$FIXTURE_WORK/trusted"
queue_fixture build_fixture scope-netfilter.bpf.c shirudo-test-scope-netfilter "$FIXTURE_WORK/trusted"
queue_fixture build_fixture scope-cgroup.bpf.c shirudo-test-scope-cgroup "$FIXTURE_WORK/trusted"
queue_fixture build_fixture scope-kprobe.bpf.c shirudo-test-scope-kprobe "$FIXTURE_WORK/trusted"
@@ -779,6 +780,9 @@ uprobe_payload="$($REPO_ROOT/shirudo upatch info \
uretprobe_payload="$($REPO_ROOT/shirudo upatch info \
"$TMP_DIR/fixtures/shirudo-test-uretprobe-multi.upatch" --json |
python3 -c 'import json,sys; print(json.load(sys.stdin)["payload_sha256"])')"
+uprobe_sleepable_payload="$($REPO_ROOT/shirudo upatch info \
+ "$TMP_DIR/fixtures/shirudo-test-uprobe-multi-sleepable.upatch" --json |
+ python3 -c 'import json,sys; print(json.load(sys.stdin)["payload_sha256"])')"
otel_backend_payload="$($REPO_ROOT/shirudo upatch info \
"$TMP_DIR/fixtures/shirudo-test-otel-backend.upatch" --json |
python3 -c 'import json,sys; print(json.load(sys.stdin)["payload_sha256"])')"
@@ -846,6 +850,7 @@ kernel-obs $observability_payload kernel-obs.unload.upatch
kernel-obs $observability_anomaly_payload kernel-obs-cred-anomaly.unload.upatch
shirudo-test-uprobe-multi $uprobe_payload shirudo-test-uprobe-multi.unload.upatch
shirudo-test-uretprobe-multi $uretprobe_payload shirudo-test-uretprobe-multi.unload.upatch
+shirudo-test-uprobe-multi-sleepable $uprobe_sleepable_payload shirudo-test-uprobe-multi-sleepable.unload.upatch
EOF
wait_fixture_jobs