Skip to content

eBPF-based security platform

upatch: accept sleepable uprobe.multi and uretprobe.multi

Jiri Olsa2392ca245218
diff --git a/Documentation/upatches/write/memory-consistency/hazards.rst b/Documentation/upatches/write/memory-consistency/hazards.rst
index a7dab76f..8af7d4d2 100644
--- a/Documentation/upatches/write/memory-consistency/hazards.rst
+++ b/Documentation/upatches/write/memory-consistency/hazards.rst
@@ -57,7 +57,8 @@ program types against a second run and not others:
* - ``syscall``
- Run with only migration disabled on any kernel and are not
guarded: another task can preempt a run.
- * - ``lsm.s``, ``fentry.s``, ``fexit.s``, ``fmod_ret.s``
+ * - ``lsm.s``, ``fentry.s``, ``fexit.s``, ``fmod_ret.s``,
+ ``uprobe.multi.s``, ``uretprobe.multi.s``
- Can be preempted and sleep on any kernel. Another run can take the
CPU at any sleeping call.
* - ``cgroup_skb``, ``netfilter``
diff --git a/Documentation/upatches/write/pitfalls.rst b/Documentation/upatches/write/pitfalls.rst
index 871eb637..8a7fc5a9 100644
--- a/Documentation/upatches/write/pitfalls.rst
+++ b/Documentation/upatches/write/pitfalls.rst
@@ -33,11 +33,11 @@ program's ``recursion_misses``, which ``struct bpf_prog_info`` reports:
- The return of a function a ``kretprobe`` watches, when more calls of
it are in flight than the probe has instances for: the larger of 10
and twice the number of CPUs.
-- The return of a function a ``uretprobe.multi`` watches, when the task
- already waits on the returns of 64 calls that return probes watch, and
- the return of a function that leaves by ``longjmp()`` or ends the
- thread. The kernel logs the first case, rate-limited, and counts
- neither.
+- The return of a function a ``uretprobe.multi`` or ``uretprobe.multi.s``
+ watches, when the task already waits on the returns of 64 calls that
+ return probes watch, and the return of a function that leaves by
+ ``longjmp()`` or ends the thread. The kernel logs the first case,
+ rate-limited, and counts neither.
A detector built on these kinds can therefore miss the event it looks
for, and a count it keeps is a lower bound. ``lsm`` and ``xdp`` programs
diff --git a/tools/shirudo-build/package.c b/tools/shirudo-build/package.c
index 8bc6b533..ca970995 100644
--- a/tools/shirudo-build/package.c
+++ b/tools/shirudo-build/package.c
@@ -544,14 +544,42 @@ static bool unsupported_kprobe_section(const char *sec)
strncmp(sec, "kretprobe.multi", 15) == 0);
}
+/*
+ * The sleepable forms take the same attach kinds: BPF_F_SLEEPABLE is a
+ * load flag, which the signed loader carries, not part of the link.
+ */
+static const char *uprobe_multi_section_target(const char *sec, __u32 *kind)
+{
+ static const struct {
+ const char *prefix;
+ __u32 kind;
+ } forms[] = {
+ { "uprobe.multi/", UPATCH_ATTACH_UPROBE_MULTI },
+ { "uprobe.multi.s/", UPATCH_ATTACH_UPROBE_MULTI },
+ { "uretprobe.multi/", UPATCH_ATTACH_URETPROBE_MULTI },
+ { "uretprobe.multi.s/", UPATCH_ATTACH_URETPROBE_MULTI },
+ };
+ size_t i, n;
+
+ for (i = 0; i < ARRAY_SIZE(forms); i++) {
+ n = strlen(forms[i].prefix);
+ if (!strncmp(sec, forms[i].prefix, n) && sec[n]) {
+ *kind = forms[i].kind;
+ return sec + n;
+ }
+ }
+ return NULL;
+}
+
static bool unsupported_uprobe_section(const char *sec)
{
+ __u32 kind;
+
if (sec && sec[0] == '?')
sec++;
if (!sec)
return false;
- if ((strncmp(sec, "uprobe.multi/", 13) == 0 && sec[13]) ||
- (strncmp(sec, "uretprobe.multi/", 16) == 0 && sec[16]))
+ if (uprobe_multi_section_target(sec, &kind))
return false;
return strcmp(sec, "uprobe") == 0 ||
strncmp(sec, "uprobe/", 7) == 0 ||
@@ -633,6 +661,8 @@ static bool default_attach_section(const char *sec)
static __u32 attach_kind_from_section(const char *sec,
const char **target)
{
+ __u32 kind;
+
*target = NULL;
if (!sec)
return UPATCH_ATTACH_RAW_TRACEPOINT;
@@ -646,14 +676,9 @@ static __u32 attach_kind_from_section(const char *sec,
*target = sec + 10;
return UPATCH_ATTACH_KRETPROBE;
}
- if (strncmp(sec, "uprobe.multi/", 13) == 0 && sec[13]) {
- *target = sec + 13;
- return UPATCH_ATTACH_UPROBE_MULTI;
- }
- if (strncmp(sec, "uretprobe.multi/", 16) == 0 && sec[16]) {
- *target = sec + 16;
- return UPATCH_ATTACH_URETPROBE_MULTI;
- }
+ *target = uprobe_multi_section_target(sec, &kind);
+ if (*target)
+ return kind;
if (strcmp(sec, "cgroup_skb/ingress") == 0)
return UPATCH_ATTACH_CGROUP_SKB_INGRESS;
if (strcmp(sec, "cgroup_skb/egress") == 0)
@@ -1287,7 +1312,7 @@ static int build_prog_metadata(struct bpf_object *obj, __u32 nr_maps,
goto err_free;
}
if (unsupported_uprobe_section(sec)) {
- pr_err("unsupported uprobe section '%s'; use uprobe.multi//absolute/path:function_glob or uretprobe.multi//absolute/path:function_glob",
+ pr_err("unsupported uprobe section '%s'; use uprobe.multi[.s]//absolute/path:function_glob or uretprobe.multi[.s]//absolute/path:function_glob",
sec);
err = -EOPNOTSUPP;
goto err_free;
@@ -1319,7 +1344,7 @@ static int build_prog_metadata(struct bpf_object *obj, __u32 nr_maps,
kind = attach_kind_from_section(sec, &target);
if (kind == UPATCH_ATTACH_RAW_TRACEPOINT &&
!default_attach_section(sec)) {
- pr_err("unsupported section '%s'; supported are fentry, fexit, fmod_ret, lsm, tp_btf, kprobe, kretprobe, uprobe.multi, uretprobe.multi, cgroup_skb, netfilter and xdp/<mask>",
+ pr_err("unsupported section '%s'; supported are fentry, fexit, fmod_ret, lsm, tp_btf, kprobe, kretprobe, uprobe.multi[.s], uretprobe.multi[.s], cgroup_skb, netfilter and xdp/<mask>",
sec);
err = -EOPNOTSUPP;
goto err_free;
@@ -1362,7 +1387,7 @@ static int build_prog_metadata(struct bpf_object *obj, __u32 nr_maps,
pr_err("invalid uprobe multi section '%s': ',' and '|' alternation are unsupported; use one '*'/'?' glob",
sec);
else
- pr_err("invalid uprobe multi section '%s'; expected uprobe.multi//absolute/path:function_glob or uretprobe.multi//absolute/path:function_glob",
+ pr_err("invalid uprobe multi section '%s'; expected uprobe.multi[.s]//absolute/path:function_glob or uretprobe.multi[.s]//absolute/path:function_glob",
sec);
goto err_free;
}