eBPF-based security platform
Documentation: add docs for uretprobe.multi attachment
Jiri Olsa609902dce317
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex acff9824..49ed4ff4 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -161,7 +161,8 @@ signed config image.* - ``t3006-cgroup-skb-metadata``- ``cgroup_skb`` ingress and egress attach metadata* - ``t3007-uprobe-multi-metadata``- - ``uprobe.multi`` globs to file offsets and the target's build ID+ - ``uprobe.multi`` and ``uretprobe.multi`` globs to file offsets and+ the target's build ID, and the uretprobe forms the builder refuses* - ``t3008-override-metadata``- kprobe override and ``fmod_ret`` attach metadata* - ``t3009-netfilter-metadata``@@ -188,7 +189,8 @@ signed config image.* - ``t3106-upatch-get``- ``upatch get`` source lines and JSON* - ``t3107-uprobe-multi``- - A live ``uprobe.multi`` load, refusal after a build ID change+ - A live ``uprobe.multi`` load, refusal after a build ID change, and+ a live ``uretprobe.multi`` load that runs and unloads* - ``t3108-status-many``- ``status --json`` with eighty loaded upatches lists all of them* - ``t3109-policy-labels``@@ -660,7 +662,7 @@ Coverage by area- Offline metadata: ``t3006``, ``t3007``, ``t3008``, ``t3009``,``t3010``. Loaded on a target: fentry (fixtures), ``lsm``(``t9101``), ``cgroup_skb`` and netfilter (``t6116``),- ``uprobe.multi`` (``t3107``)+ ``uprobe.multi`` and ``uretprobe.multi`` (``t3107``)* - bpffs pins and mounts- ``t4101``, ``t6105``, ``t6106``, ``t6108``, ``t6120``,``t6121``diff --git a/Documentation/internals/kernel-interfaces.rst b/Documentation/internals/kernel-interfaces.rstindex 38e433f1..d7925578 100644--- a/Documentation/internals/kernel-interfaces.rst+++ b/Documentation/internals/kernel-interfaces.rst@@ -204,18 +204,20 @@ where the caller is the loader.Kind 6, netfilter: ``attach_type`` ``BPF_NETFILTER``, ``pf`` 10(``NFPROTO_IPV6``), ``hooknum`` 0 (``NF_INET_PRE_ROUTING``),``priority`` -450 (``NF_IP6_PRI_RAW_BEFORE_DEFRAG``), ``flags`` 0.- Kind 7, ``uprobe.multi``: ``attach_type``- ``BPF_TRACE_UPROBE_MULTI``, ``offsets``, ``cnt``, ``flags``- ``BPF_F_UPROBE_MULTI_PATH_FD``, ``path_fd`` a descriptor of the- target binary opened and checked by build ID.+ Kinds 7 and 9, ``uprobe.multi`` and ``uretprobe.multi``:+ ``attach_type`` ``BPF_TRACE_UPROBE_MULTI``, ``offsets``, ``cnt``,+ ``flags`` ``BPF_F_UPROBE_MULTI_PATH_FD``, with+ ``BPF_F_UPROBE_MULTI_RETURN`` for kind 9, ``path_fd`` a descriptor+ of the target binary opened and checked by build ID.Kind 8, XDP: ``target_ifindex`` a selected device,``attach_type`` ``BPF_XDP``, ``flags`` ``XDP_FLAGS_DRV_MODE``.* - ``BPF_OBJ_GET_INFO_BY_FD``- On each link before it is pinned. Cgroup links: ``cgroup_id`` 1.Netfilter: ``pf``, ``hooknum``, ``priority`` as set, and thecaller's network namespace cookie (``SO_NETNS_COOKIE``) 7. Kprobe:- perf event type, function name and offset as signed. Uprobe:- offset count. ``fmod_ret``: ``BPF_MODIFY_RETURN``.+ perf event type, function name and offset as signed. Uprobe+ multi: offset count and the return flag. ``fmod_ret``:+ ``BPF_MODIFY_RETURN``.XDP: ``BPF_LINK_TYPE_XDP`` and ``xdp.ifindex`` matching the selecteddevice; the initial namespace, device class and peer scope arerechecked around attachment.diff --git a/Documentation/internals/signed-loader.rst b/Documentation/internals/signed-loader.rstindex 4dac40d8..89121213 100644--- a/Documentation/internals/signed-loader.rst+++ b/Documentation/internals/signed-loader.rst@@ -97,8 +97,9 @@ loader inside the kernel, which ``lsm/bpf`` sees with ``kernel`` true.- The file is read once into ``/var/lib/shirudo/incoming``. Thesigned name must equal the header name, ``payload_sha256`` mustequal SHA-256 of ``loader_insns || data``, and the signed attach- metadata must parse. Each ``uprobe.multi`` target is opened and- its GNU build ID compared before any BPF loads.+ metadata must parse. Each ``uprobe.multi`` and ``uretprobe.multi``+ target is opened and its GNU build ID compared before any BPF+ loads.* - userspace- ``BPF_MAP_CREATE`` of ``__loader.map``- ``lsm/bpf`` allows it to a task with runtime authority, elsediff --git a/Documentation/operate/plan/scalability.rst b/Documentation/operate/plan/scalability.rstindex 1288ec5d..a9f3264d 100644--- a/Documentation/operate/plan/scalability.rst+++ b/Documentation/operate/plan/scalability.rst@@ -186,7 +186,7 @@ without ``CAP_BPF``. What bounds a target is the attach point.* - ``kprobe``, ``kretprobe``- No limit per symbol; every attachment is a perf event of its own-- * - ``uprobe.multi``+ * - ``uprobe.multi``, ``uretprobe.multi``- 1,048,576 offsets per link, which shirudo also enforces- ``MAX_UPROBE_MULTI_CNT`` in ``kernel/trace/bpf_trace.c``* - ``cgroup_skb``diff --git a/Documentation/operate/plan/system-requirements.rst b/Documentation/operate/plan/system-requirements.rstindex a87628b4..3f0ab7a8 100644--- a/Documentation/operate/plan/system-requirements.rst+++ b/Documentation/operate/plan/system-requirements.rst@@ -253,7 +253,7 @@ point is missing fails to load.* - ``CONFIG_BPF_KPROBE_OVERRIDE``- ``bpf_override_return()`` from a ``kprobe`` upatch.* - ``CONFIG_UPROBE_EVENTS``- - ``uprobe.multi`` upatches.+ - ``uprobe.multi`` and ``uretprobe.multi`` upatches.* - ``CONFIG_CGROUP_BPF``- ``cgroup_skb`` upatches.* - ``CONFIG_NETFILTER``, ``CONFIG_NETFILTER_BPF_LINK``diff --git a/Documentation/reference/failure-categories.rst b/Documentation/reference/failure-categories.rstindex dc633cd5..89bab562 100644--- a/Documentation/reference/failure-categories.rst+++ b/Documentation/reference/failure-categories.rst@@ -40,8 +40,8 @@ measures in ``tpm_extend`` and removes the pins in ``pin``.name, the signed name, ``payload_sha256`` against the loader anddata, and the signed attach metadata.* - ``target_verify``- - Opening each ``uprobe.multi`` target binary and comparing its GNU- build ID with the one the artifact records.+ - Opening each ``uprobe.multi`` and ``uretprobe.multi`` target binary+ and comparing its GNU build ID with the one the artifact records.* - ``signed_loader_load``- Creating, filling and freezing ``__loader.map`` and the``BPF_PROG_LOAD`` of the signed loader, where the kernel verifiesdiff --git a/Documentation/reference/formats/upatch-format.rst b/Documentation/reference/formats/upatch-format.rstindex 7d6a3177..b1454011 100644--- a/Documentation/reference/formats/upatch-format.rst+++ b/Documentation/reference/formats/upatch-format.rst@@ -369,8 +369,9 @@ Each program entry is 160 bytes:- 128- ``target``- NUL-terminated. The kernel symbol for ``kprobe`` and- ``kretprobe``, the function glob for ``uprobe.multi`` (no ``,`` or- ``|``). Empty for every other kind and role.+ ``kretprobe``, the function glob for ``uprobe.multi`` and+ ``uretprobe.multi`` (no ``,`` or ``|``). Empty for every other kind+ and role.* - +144- 16- ``map``@@ -424,11 +425,14 @@ Each program entry is 160 bytes:- netfilter IPv6 pre-routing- ``netfilter``* - 7- - uprobe.multi entry probe+ - uprobe.multi- ``uprobe.multi/<absolute-path>:<function-glob>``* - 8- native XDP device classes- ``xdp/<decimal-mask>``+ * - 9+ - uretprobe.multi+ - ``uretprobe.multi/<absolute-path>:<function-glob>``:doc:`/upatches/write/attach-kinds` describes how the target attaches each kind.XDP retains the 160-byte entry and UPGM version 1; readers that do not@@ -438,9 +442,9 @@ selects all classes. Bit 4 is not a class, and a reader refuses a maskthat sets it or any bit above 16, and a table whose XDP entries share aclass.-When any entry has kind 7, one ``UPUT`` block follows the program entries-and ends the section. Without a kind 7 entry the section ends after the-program entries.+When any entry has kind 7 or 9, one ``UPUT`` block follows the program+entries and ends the section. Without a kind 7 or 9 entry the section ends+after the program entries... list-table:::header-rows: 1@@ -461,7 +465,8 @@ program entries.* - +8- 4- ``nr_targets``- - Number of target records, equal to the number of kind 7 entries.+ - Number of target records, equal to the number of kind 7 and 9+ entries.* - +12- 4- ``reserved``@@ -479,7 +484,7 @@ variable parts:- Value* - +0- ``prog_idx``- - Index of a kind 7 program entry. Each such entry has exactly one+ - Index of a kind 7 or 9 program entry. Each such entry has exactly onerecord.* - +4- ``path_len``@@ -756,9 +761,9 @@ of checks 1 to 6 is reported as ``parser_rejected``, see#. A ``UPGM`` section is present and parses: version 1 (any other versionis ``EOPNOTSUPP``), ``nr_maps`` and ``nr_progs`` equal to the header's,every entry valid for its role and kind, and a ``UPUT`` block that is- present exactly when a kind 7 entry exists and ends the section.-#. Each ``uprobe.multi`` target file is a regular file whose GNU build ID- equals the recorded one.+ present exactly when a kind 7 or 9 entry exists and ends the section.+#. Each ``uprobe.multi`` and ``uretprobe.multi`` target file is a regular+ file whose GNU build ID equals the recorded one.#. The kernel verifies the signature in ``BPF_PROG_LOAD``.An unload directive passes the reader, then these checks:@@ -828,15 +833,16 @@ Limits* - Name of an upatch- 255 characters of ``[A-Za-z0-9._-]``, each ``.`` counting as two,not starting with ``.``- * - ``kprobe``, ``kretprobe`` or ``uprobe.multi`` target+ * - ``kprobe``, ``kretprobe``, ``uprobe.multi`` or ``uretprobe.multi``+ target- 127 bytes* - Serializer map name- 15 bytes- * - ``uprobe.multi`` path+ * - ``uprobe.multi`` or ``uretprobe.multi`` path- 4095 bytes* - GNU build ID- 1 to 64 bytes- * - ``uprobe.multi`` offsets per program+ * - ``uprobe.multi`` or ``uretprobe.multi`` offsets per program- 1 to 1048576* - Decoder source- 16 MiB per filediff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex 9a57cb7e..70a76434 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -1545,9 +1545,9 @@ R20 The TPM owner password is not a secret on the targetR21 upatches can be neutralized by changing their targetsAn upatch stays loaded and measured while root makes it ineffective:by unloading the module a kprobe targets, by replacing the binary a- ``uprobe.multi`` target names with a new inode, or, without lockdown- (A4), by disabling kprobes through debugfs. These are readings of the- kernel source and are not tested.+ ``uprobe.multi`` or ``uretprobe.multi`` target names with a new inode,+ or, without lockdown (A4), by disabling kprobes through debugfs. These+ are readings of the kernel source and are not tested.XDP coverage is reconciled, not continuous. A device added after loadruns without the upatch until ``upatch reconcile`` next runs, and isdiff --git a/Documentation/upatches/learn/concepts.rst b/Documentation/upatches/learn/concepts.rstindex 614ab9b3..15b41031 100644--- a/Documentation/upatches/learn/concepts.rst+++ b/Documentation/upatches/learn/concepts.rst@@ -257,9 +257,10 @@ It cannot attach anywhere other than where its signed metadata says.Before shirudo pins a link, it compares what the kernel reports about thelink with the metadata: the link type and attach type, the kprobe symboland offset, the cgroup, the netfilter hook and network namespace, the-number of uprobe offsets. A mismatch unpins what the load made and fails-with ``attach_scope_mismatch``. For fentry, fexit, ``fmod_ret``, LSM and-``tp_btf`` programs the site is the BTF target the verifier bound at load.+number of offsets and the direction of a uprobe multi link. A mismatch+unpins what the load made and fails with ``attach_scope_mismatch``. For+fentry, fexit, ``fmod_ret``, LSM and ``tp_btf`` programs the site is the+BTF target the verifier bound at load.It cannot use a program type that has no pinnable link. The builderrefuses socket filters, ``sk_skb`` and every other sectiondiff --git a/Documentation/upatches/test/debugging.rst b/Documentation/upatches/test/debugging.rstindex 8fa6bfb2..7d88b606 100644--- a/Documentation/upatches/test/debugging.rst+++ b/Documentation/upatches/test/debugging.rst@@ -98,9 +98,10 @@ Find the cause* - ``target_verify``- ``attach_target_missing``, ``binary_mismatch``,``parser_rejected``, ``lsm_denied``- - A ``uprobe.multi`` binary is missing, differs from the one the- upatch was built against, is shorter than a recorded offset, or- could not be read. Rebuild against the binary the target runs.+ - A ``uprobe.multi`` or ``uretprobe.multi`` binary is missing,+ differs from the one the upatch was built against, is shorter+ than a recorded offset, or could not be read. Rebuild against+ the binary the target runs.* - ``signed_loader_load``- ``signature_rejected``- The signature does not verify against the ``.bpf`` keyring: thediff --git a/Documentation/upatches/test/testing.rst b/Documentation/upatches/test/testing.rstindex ad0ceab0..6634082a 100644--- a/Documentation/upatches/test/testing.rst+++ b/Documentation/upatches/test/testing.rst@@ -190,6 +190,9 @@ one.* - ``shirudo-test-uprobe-multi``- ``uprobe.multi`` on ``/tmp/shirudo-test-uprobe-target``. Copy``shirudo-test-uprobe-target`` from the fixtures to that path first.+ * - ``shirudo-test-uretprobe-multi``+ - ``uretprobe.multi`` on the same binary and functions, counting in+ the map ``hits``* - ``shirudo-test-scope-cgroup``, ``shirudo-test-scope-netfilter``,``shirudo-test-scope-kprobe``- ``cgroup_skb``, ``netfilter`` and ``kprobe`` attachments and thediff --git a/Documentation/upatches/write/attach-kinds.rst b/Documentation/upatches/write/attach-kinds.rstindex 444d211d..4e820791 100644--- a/Documentation/upatches/write/attach-kinds.rst+++ b/Documentation/upatches/write/attach-kinds.rst@@ -57,6 +57,10 @@ the link against the metadata and pins it.- ``BPF_LINK_CREATE``, ``BPF_TRACE_UPROBE_MULTI``,``BPF_F_UPROBE_MULTI_PATH_FD``- ``CONFIG_UPROBE_EVENTS``+ * - ``uretprobe.multi/<path>:<glob>``+ - kprobe+ - as ``uprobe.multi``, with ``BPF_F_UPROBE_MULTI_RETURN``+ - ``CONFIG_UPROBE_EVENTS``* - ``cgroup_skb/ingress``, ``cgroup_skb/egress``- cgroup skb- ``BPF_LINK_CREATE`` on ``/sys/fs/cgroup``,@@ -178,16 +182,18 @@ allows that only at the entry of a function on its error-injection listand with ``CONFIG_BPF_KPROBE_OVERRIDE``. Elsewhere the kernel refusesthe link, and the load fails in phase ``link_create``.-uprobe.multi-------------+uprobe.multi and uretprobe.multi+---------------------------------``uprobe.multi/<path>:<glob>`` attaches to the entry of every function in-a userspace binary whose symbol matches the glob, in every process, for-example ``SEC("uprobe.multi//usr/bin/example:*Func")``. ``<path>`` is-absolute. The glob has libbpf's syntax: ``*`` matches any sequence and-``?`` one character.+``uprobe.multi/<path>:<glob>`` and ``uretprobe.multi/<path>:<glob>``+attach to the entry or the return of every function in a userspace binary+whose symbol matches the glob, in every process, for example+``SEC("uprobe.multi//usr/bin/example:*Func")``. ``<path>`` is absolute.+The glob has libbpf's syntax: ``*`` matches any sequence and ``?`` one+character. A return program reads the return value with+``PT_REGS_RC()``; by then the registers no longer hold the arguments.-This kind is resolved on the operator host. The builder opens the binary+These kinds are resolved on the operator host. The builder opens the binaryat ``<path>``, matches the glob against its function symbols, converts thematches to sorted file offsets and records them with the binary's GNUbuild ID in the signed metadata. It refuses a glob that matches nothing@@ -199,8 +205,9 @@ every offset lies inside the file, and compares the build ID. A differentbinary fails with ``binary_mismatch`` in phase ``target_verify``, beforeany BPF is loaded. shirudo keeps that descriptor open and attaches with``BPF_LINK_CREATE``, ``BPF_TRACE_UPROBE_MULTI`` and-``BPF_F_UPROBE_MULTI_PATH_FD``, so the probes land in the inode it checked,-not in whatever the path names later. There is no path fallback.+``BPF_F_UPROBE_MULTI_PATH_FD``, and ``BPF_F_UPROBE_MULTI_RETURN`` for+``uretprobe.multi``, so the probes land in the inode it checked, not in+whatever the path names later. There is no path fallback... list-table:::header-rows: 1@@ -594,9 +601,12 @@ it generates a loader.``kretprobe.multi*``- ``unsupported kprobe section '<section>'; use kprobe/<symbol> orkretprobe/<symbol>``- * - ``uprobe``, ``uprobe/*``, ``uretprobe*``, other ``uprobe.*`` forms+ * - ``uprobe``, ``uprobe/*``, ``uretprobe``, ``uretprobe/*``, other+ ``uprobe.*`` and ``uretprobe.*`` forms, the sleepable+ ``uprobe.multi.s`` and ``uretprobe.multi.s`` among them- ``unsupported uprobe section '<section>'; use- uprobe.multi//absolute/path:function_glob (entry probes only)``+ uprobe.multi//absolute/path:function_glob or+ uretprobe.multi//absolute/path:function_glob``* - ``sk_skb``, ``sk_skb/*``- ``unsupported sk_skb section '<section>'; supported network packetsections are cgroup_skb/ingress, cgroup_skb/egress, and netfilter``@@ -612,8 +622,8 @@ it generates a loader.* - every other section, ``tp/``, ``raw_tp/``, ``xdp`` and ``tc`` amongthem- ``unsupported section '<section>'; supported are fentry, fexit,- fmod_ret, lsm, tp_btf, kprobe, kretprobe, uprobe.multi, cgroup_skb,- netfilter and xdp/<mask>``+ fmod_ret, lsm, tp_btf, kprobe, kretprobe, uprobe.multi,+ uretprobe.multi, cgroup_skb, netfilter and xdp/<mask>``* - ``syscall`` with another program name- ``SEC("syscall") program '<name>' must be named shirudo_test__<id>``@@ -641,8 +651,9 @@ metadata:* - ``kprobe``, ``kretprobe``- a perf event link of the kprobe or kretprobe type, with the samesymbol and offset- * - ``uprobe.multi``- - a uprobe multi link with as many offsets as recorded+ * - ``uprobe.multi``, ``uretprobe.multi``+ - a uprobe multi link with as many offsets as recorded and the same+ direction* - ``fmod_ret``- a tracing link with attach type ``BPF_MODIFY_RETURN``* - ``fentry``, ``fexit``, ``lsm``, ``tp_btf``@@ -658,8 +669,9 @@ Missing attach targets``attach_target_missing`` reports a site that does not exist on thistarget: a ``kprobe`` symbol that kallsyms does not list, often because themodule that holds it is not loaded, a kernel without the kprobe PMU, a-missing ``/sys/fs/cgroup``, or a ``uprobe.multi`` binary that is not-there. ``shirudo upatch load`` exits with status 2 for it, not 1.+missing ``/sys/fs/cgroup``, or a ``uprobe.multi`` or ``uretprobe.multi``+binary that is not there. ``shirudo upatch load`` exits with status 2 for+it, not 1.The BTF-based kinds never report it. ``fentry``, ``fexit``, ``fmod_ret``,``lsm`` and ``tp_btf`` targets are looked up inside the signed loader, and