Skip to content

eBPF-based security platform

status: report devices an XDP upatch does not run on

John Fastabend8faee77402bf
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index b56a0e64..79a3429b 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -199,7 +199,7 @@ signed config image.
* - ``t3111-xdp``
- Native XDP class selection, veth pair deduplication with both
endpoint index orderings, cross-namespace pairs, a bridge without
- native XDP skipped, rollback, signed unload and descriptor
+ native XDP skipped and listed under ``XdpCovered``, rollback, signed unload and descriptor
and alternate-attachment lockdown; a repeated init adopts the
archived XDP without another event. A veth with a peer MTU of 9000
and the ``virtio_net`` guest adapter at MTU 9000 attach, which only a
@@ -214,6 +214,10 @@ signed config image.
the ``upatch_verify`` unit cases. An unload racing a pass is not
reported as tampering, and a veth with too few rx queues, which
its driver refuses, is warned about without stopping the pass.
+ ``status`` lists a selected device under ``XdpCovered`` until a
+ pass attaches it, and the refused veth for good. The reasons and
+ the verdict are covered by the ``xdp`` and ``conditions`` unit
+ cases.
``tpm`` (4)
~~~~~~~~~~~
diff --git a/Documentation/operate/deploy/boot-integration.rst b/Documentation/operate/deploy/boot-integration.rst
index 28531d98..689087d9 100644
--- a/Documentation/operate/deploy/boot-integration.rst
+++ b/Documentation/operate/deploy/boot-integration.rst
@@ -453,6 +453,7 @@ Boot and verify
UpatchesMeasured OK every pinned or archived upatch is in this boot's records
TpmMeasured OK NV index 0x01818E00 readable
ConfigActive OK config 6d5ed552f448.. is active
+ XdpCovered OK every device an XDP upatch selects runs it
Tamper attempts (this boot):
LoadNotLoader 15 program load that is not a signed loader
diff --git a/Documentation/operate/deploy/initialize.rst b/Documentation/operate/deploy/initialize.rst
index 9d43a258..04fc7212 100644
--- a/Documentation/operate/deploy/initialize.rst
+++ b/Documentation/operate/deploy/initialize.rst
@@ -77,6 +77,7 @@ Check that init worked
UpatchesMeasured OK every pinned or archived upatch is in this boot's records
TpmMeasured OK NV index 0x01818E00 readable
ConfigActive OK config 6d5ed552f448.. is active
+ XdpCovered OK every device an XDP upatch selects runs it
Tamper attempts (this boot):
LoadNotLoader 15 program load that is not a signed loader
diff --git a/Documentation/operate/run/read-status.rst b/Documentation/operate/run/read-status.rst
index edd9f78b..94151efb 100644
--- a/Documentation/operate/run/read-status.rst
+++ b/Documentation/operate/run/read-status.rst
@@ -48,6 +48,7 @@ Print the report
UpatchesMeasured OK every pinned or archived upatch is in this boot's records
TpmMeasured OK NV index 0x01818E00 readable
ConfigActive OK config 6d5ed552f448.. is active
+ XdpCovered OK every device an XDP upatch selects runs it
Tamper attempts (this boot):
LoadNotLoader 15 program load that is not a signed loader
@@ -100,6 +101,7 @@ line; a section unfolds on its own when its condition is not ``OK``.
UpatchesMeasured OK every pinned or archived upatch is in this boot's records
TpmMeasured OK NV index 0x01818E00 readable
ConfigActive OK config 6d5ed552f448.. is active
+ XdpCovered OK every device an XDP upatch selects runs it
Tamper attempts (this boot):
LoadNotLoader 15 program load that is not a signed loader
@@ -250,6 +252,18 @@ verdict is derived from them.
* - ``TpmMeasured``
- The NV index is defined, written and readable. ``WARN`` ``NV
index 0x01818E00 not bound this boot`` or ``no TPM answered``.
+ * - ``XdpCovered``
+ - Every device the signed class mask of a loaded XDP upatch selects
+ runs that upatch. ``WARN`` ``<n> selected devices run without
+ their XDP upatch: <upatch> on <device> (<why>)`` lists each
+ device that does not, whatever the reason, with what the device
+ reports: ``no native XDP``, ``no multi-buffer XDP``, ``another
+ XDP program attached`` or ``not attached``. A device added in the
+ last seconds shows ``not attached`` until ``upatch reconcile``
+ attaches it. One that stays listed is unfiltered. Its driver
+ refused the program, or a setting such as LRO turned its XDP off,
+ or the reconcile units are stopped. ``WARN`` ``XDP coverage not
+ checked: <error>`` means the check could not run.
* - ``ConfigActive``
- The config PCR, the activation records and the mounted config
image agree. ``WARN`` ``the activation of config <root>.. is
@@ -435,8 +449,9 @@ precedence: ``tampered``, ``lsm-off``, ``init-pending``,
- Nothing. Verify with the TPM regularly, see
:doc:`/operate/run/attest`.
* - ``degraded``
- - Enforcement is up, but this report has no register to check.
- - Read the ``Chain`` line. See :ref:`status-degraded`.
+ - Enforcement is up, but this report has no register to check, or
+ a device an XDP upatch selects runs without it.
+ - Read the reason. See :ref:`status-degraded`.
* - ``reboot-pending``
- A config activation is pending until the next reboot. Every
command except ``status`` and ``image status`` refuses until
@@ -646,6 +661,15 @@ the index takes TPM owner authorization, which root has on a TPM whose
owner authorization is empty. Collect the evidence as for ``tampered``,
see :doc:`/operate/troubleshoot/incident-tampered`, then reboot.
+The reason ``a device an XDP upatch selects does not run it`` comes with
+an ``XdpCovered`` warning that names each device and why. A device
+listed in one report and gone from the next was new and has been
+attached since. One that stays has no filter. Restore what took its XDP
+away, such as an LRO setting, a smaller queue count or another XDP
+program, and the next ``upatch reconcile`` attaches it. Where the
+device cannot run XDP at all, sign the upatch with a class mask that
+leaves the device out.
+
The reason ``no TPM answered`` means the TPM stopped answering while
``status`` ran. On a production target every command first checks that
the TPM is the one ``init`` bound, so a TPM that does not answer at all
diff --git a/Documentation/operate/run/telemetry.rst b/Documentation/operate/run/telemetry.rst
index 7ffb54f1..aced49d2 100644
--- a/Documentation/operate/run/telemetry.rst
+++ b/Documentation/operate/run/telemetry.rst
@@ -404,6 +404,10 @@ The keepalive body is the ``shirudo status --json`` document.
- ``LsmAttached``, ``KeyringSealed``, ``ChainIntact``,
``UpatchesMeasured`` or ``ConfigActive`` found tampering or lost
enforcement.
+ * - ``XdpCovered`` with ``status`` ``WARN`` in several keepalives
+ - A device an XDP upatch selects runs without it: its driver
+ refuses the program or its XDP was turned off. See
+ :doc:`/operate/run/read-status`.
* - ``shirudo.tamper_attempts`` rises
- Something on the target tried an operation the guards refused.
The counters start at zero each boot. See
diff --git a/Documentation/operate/troubleshoot/troubleshooting.rst b/Documentation/operate/troubleshoot/troubleshooting.rst
index 7f80e894..b34c2dfd 100644
--- a/Documentation/operate/troubleshoot/troubleshooting.rst
+++ b/Documentation/operate/troubleshoot/troubleshooting.rst
@@ -43,6 +43,7 @@ Before you begin
UpatchesMeasured OK every pinned or archived upatch is in this boot's records
TpmMeasured OK NV index 0x01818E00 readable
ConfigActive OK config 6d5ed552f448.. is active
+ XdpCovered OK every device an XDP upatch selects runs it
...
A verdict other than ``ok`` is followed by its reason in parentheses,
diff --git a/Documentation/reference/cli/status.rst b/Documentation/reference/cli/status.rst
index 718c0dc3..b28973c6 100644
--- a/Documentation/reference/cli/status.rst
+++ b/Documentation/reference/cli/status.rst
@@ -35,9 +35,10 @@ report. The roles come from what is present:
``init`` froze
- operator: ``/var/lib/shirudo/keys/signing_key.pem``
-The report shows six conditions, each ``OK``, ``WARN`` or ``ALERT``:
+The report shows seven conditions, each ``OK``, ``WARN`` or ``ALERT``:
``LsmAttached``, ``KeyringSealed``, ``ChainIntact``,
-``UpatchesMeasured``, ``TpmMeasured`` and ``ConfigActive``. The verdict is the first of these that applies:
+``UpatchesMeasured``, ``TpmMeasured``, ``ConfigActive`` and
+``XdpCovered``. The verdict is the first of these that applies:
.. list-table::
:header-rows: 1
@@ -59,7 +60,8 @@ The report shows six conditions, each ``OK``, ``WARN`` or ``ALERT``:
* - ``reboot-pending``
- A config activation is pending until the next reboot.
* - ``degraded``
- - No TPM answered, or no register is bound this boot.
+ - No TPM answered, no register is bound this boot, or a device an
+ XDP upatch selects does not run it.
* - ``ok``
- None of the above.
@@ -181,6 +183,7 @@ Show the state of a target:
UpatchesMeasured OK every pinned or archived upatch is in this boot's records
TpmMeasured OK NV index 0x01818E00 readable
ConfigActive OK config 6d5ed552f448.. is active
+ XdpCovered OK every device an XDP upatch selects runs it
Tamper attempts (this boot):
LoadNotLoader 15 program load that is not a signed loader
@@ -216,6 +219,7 @@ system as well:
UpatchesMeasured OK every pinned or archived upatch is in this boot's records
TpmMeasured OK NV index 0x01818E00 readable
ConfigActive OK config 6d5ed552f448.. is active
+ XdpCovered OK every device an XDP upatch selects runs it
Tamper attempts (this boot):
LoadNotLoader 15 program load that is not a signed loader
diff --git a/Documentation/reference/formats/status-json.rst b/Documentation/reference/formats/status-json.rst
index 7171edb6..beaedf45 100644
--- a/Documentation/reference/formats/status-json.rst
+++ b/Documentation/reference/formats/status-json.rst
@@ -168,7 +168,8 @@ Verdicts
- A config activation is pending until the next reboot.
* - ``degraded``
- No register is bound this boot: no TPM answered, or the NV index
- is not written.
+ is not written. Or a device an XDP upatch selects does not run
+ it.
* - ``ok``
- None of the above.
@@ -178,7 +179,8 @@ Reasons
``reason`` is ``null`` for ``ok`` and otherwise one of these strings.
For ``tampered`` it names the first cause that applies, in the order
listed. For ``degraded`` it is ``no TPM answered`` when no TPM
-answered, else ``no register bound this boot``.
+answered, ``no register bound this boot`` when no register is bound,
+else ``a device an XDP upatch selects does not run it``.
.. list-table::
:header-rows: 1
@@ -214,11 +216,13 @@ answered, else ``no register bound this boot``.
- ``no register bound this boot``
* -
- ``no TPM answered``
+ * -
+ - ``a device an XDP upatch selects does not run it``
Conditions
----------
-``conditions`` always holds these six types, in this order. ``status``
+``conditions`` always holds these seven types, in this order. ``status``
is ``OK``, ``WARN`` or ``ALERT``. ``<serial>``, ``<n>`` and ``<root>``
stand for a keyring serial, a number of links and the first 12 hex
digits of the config root hash. ``KeyringSealed`` reports the first of
@@ -330,6 +334,16 @@ its details that applies, in the order listed.
- ``ALERT``
- ``the config PCR, activation records and mounted config
disagree``
+ * - ``XdpCovered``
+ - ``OK``
+ - ``every device an XDP upatch selects runs it``
+ * -
+ - ``WARN``
+ - ``<n> selected devices run without their XDP upatch: <upatch>
+ on <device> (<why>), ...``
+ * -
+ - ``WARN``
+ - ``XDP coverage not checked: <error>``
Keyrings
--------
@@ -778,6 +792,11 @@ indented here:
"type": "ConfigActive",
"status": "OK",
"detail": "config 6d5ed552f448.. is active"
+ },
+ {
+ "type": "XdpCovered",
+ "status": "OK",
+ "detail": "every device an XDP upatch selects runs it"
}
],
"lsm_attached": true,
diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rst
index 6f5e56a7..31d680e7 100644
--- a/Documentation/security/threat-model.rst
+++ b/Documentation/security/threat-model.rst
@@ -1555,8 +1555,10 @@ R21 upatches can be neutralized by changing their targets
one pass plus five seconds when udev gives no signal, as for a veth
peer moving namespace. A device stays uncovered while its XDP slot is
occupied, it has no native XDP, its driver refuses the program, or
- root stops the timer and the udev rule, and ``status`` does not list
- such devices.
+ root stops the timer and the udev rule. ``status`` lists every such
+ device under ``XdpCovered`` with the reason the device reports and
+ gives the verdict ``degraded``, which the keepalive carries; root
+ can stop the keepalive as well, which its collector sees as silence.
At boot restore a device whose driver refuses fails ``init``: the
register stays unbound, so attestation fails, and that upatch and every
archive after it in name order stay unloaded that boot. A setting that
@@ -1572,8 +1574,8 @@ R21 upatches can be neutralized by changing their targets
Every XDP program is loaded with multi-buffer support and a selected
device must report it. At boot restore one that does not fails
- ``init``. After boot it stays uncovered, with a warning.
- The check is made at attach only: a device that later
+ ``init``. After boot it stays uncovered, with a warning, and ``status``
+ lists it. The check is made at attach only: a device that later
stops reporting it keeps its link, as a bond that later enslaves such a
device does, and what happens to a frame too large for one buffer is
then the driver's choice. It may drop the frame or never run the
diff --git a/Documentation/upatches/write/attach-kinds.rst b/Documentation/upatches/write/attach-kinds.rst
index 279218ba..07fc6abb 100644
--- a/Documentation/upatches/write/attach-kinds.rst
+++ b/Documentation/upatches/write/attach-kinds.rst
@@ -310,7 +310,7 @@ or a driver refusing the program. Boot restore fails the same way, and
during the restore, or that an upatch restored before this one holds, is
skipped. That includes a device reconcile only warned about before the
reboot. A setting root makes after boot is the reconcile pass's to meet,
-which leaves the device unattached and warns. Existing XDP
+which leaves the device unattached, warns, and lets ``status`` list it. Existing XDP
programs are never replaced. Device classification and peer identity
are rechecked around attachment, and the returned link's ifindex is
checked before pinning.
@@ -321,7 +321,8 @@ XDP must report multi-buffer support, ``NETDEV_XDP_ACT_RX_SG``. One that
does not fails ``upatch load`` with ``xdp_multibuf_unsupported``, and the
load is undone, so a single such device under the signed mask stops it:
narrow the mask. Boot restore fails on such a device too. Reconcile leaves
-it unattached and logs a warning. In a tree, a failed ``add`` stops ``bpm tree sync`` at
+it unattached, logs a warning, and ``status`` lists it under
+``XdpCovered``. In a tree, a failed ``add`` stops ``bpm tree sync`` at
that operation, so scope it with a node label.
These drivers report multi-buffer XDP in Linux bpf-next at 53435562a725:
diff --git a/builtin-status.c b/builtin-status.c
index 6d550450..a4ce16e0 100644
--- a/builtin-status.c
+++ b/builtin-status.c
@@ -61,6 +61,7 @@
#include "util/upatch_table.h"
#include "util/upatch_verify.h"
#include "util/version.h"
+#include "util/xdp.h"
#define UNMEASURED_NAMES 256
@@ -83,6 +84,17 @@ static int note_unmeasured_archive(const char *name, const char *path,
return note_unmeasured(name, ctx);
}
+static int note_uncovered(const char *name, const char *dev, const char *why,
+ void *ctx)
+{
+ char entry[UPATCH_NAME_MAX + XDP_IFNAME_MAX + 64];
+
+ if (strsprintf(entry, sizeof(entry), "%s on %s (%s)", name, dev,
+ why) < 0)
+ strscpy(entry, "?", sizeof(entry));
+ return note_unmeasured(entry, ctx);
+}
+
static int notdot(const struct dirent *e)
{
return strcmp(e->d_name, ".") != 0 && strcmp(e->d_name, "..") != 0;
@@ -857,8 +869,11 @@ int cmd_status(int argc, const char **argv)
char unmeasured_names[UNMEASURED_NAMES] = "";
char xdp_tampered_names[UNMEASURED_NAMES] = "";
char links_lost_names[UNMEASURED_NAMES] = "";
+ char xdp_uncovered_names[UNMEASURED_NAMES] = "";
struct measured_set *mset = NULL;
int xdp_tampered = 0;
+ int xdp_coverage_rc = 0;
+ int xdp_uncovered = 0;
int links_lost = 0;
int checks_rc = 0;
char config_root_hex[65] = "";
@@ -977,6 +992,9 @@ int cmd_status(int argc, const char **argv)
&checks_rc);
links_lost = upatch_links_lost(mset, note_unmeasured,
links_lost_names, &checks_rc);
+ xdp_uncovered = upatch_xdp_uncovered(mset, note_uncovered,
+ xdp_uncovered_names,
+ &xdp_coverage_rc);
measured_set_free(mset);
}
eventlog_unlock(lock);
@@ -1047,6 +1065,10 @@ int cmd_status(int argc, const char **argv)
cin.links_lost = max(links_lost, 0);
cin.links_lost_detail = links_lost_names;
cin.checks_rc = checks_rc;
+ cin.xdp_uncovered = max(xdp_uncovered, 0);
+ cin.xdp_uncovered_detail = xdp_uncovered_names;
+ cin.xdp_coverage_rc = xdp_uncovered < 0 ? xdp_uncovered :
+ xdp_coverage_rc;
keyring_cond_input(&cin, &bpf, &dmv);
if (json) {
diff --git a/builtin-upatch.c b/builtin-upatch.c
index 25ccb48b..99129a7e 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -4240,23 +4240,9 @@ static int pin_is_measured(const char *name, __u8 *payload, bool *held)
static int reconcile_read(struct xdp_work *w)
{
- const void *attach;
- __u32 len;
- int ret;
-
if (get_pin_payload(w->name, w->payload))
return -ENODATA;
- ret = upatch_archive_verify(w->name, w->payload, &w->u);
- if (ret)
- return ret;
- attach = upatch_signed_attach(&w->u, &len);
- ret = attach ? prog_specs_parse(attach, len, w->u.hdr.nr_maps,
- w->u.hdr.nr_progs, &w->specs) : -ESTALE;
- if (ret) {
- upatch_close(&w->u);
- return ret == -ENOMEM ? ret : -ESTALE;
- }
- return 0;
+ return upatch_archive_specs(w->name, w->payload, &w->u, &w->specs);
}
static int reconcile_fail_verify(const char *name, int err,
@@ -4361,31 +4347,6 @@ static int reconcile_collect(struct xdp_work **out, size_t *count,
return 0;
}
-static int xdp_prog_open(const char *name, __u32 index, __u32 *id)
-{
- struct bpf_prog_info info = {};
- __u32 len = sizeof(info);
- char pin[PATH_MAX];
- char entry[32];
- int fd, ret;
-
- if (strsprintf(entry, sizeof(entry), XDP_PROG_PIN_PREFIX "%u", index) < 0 ||
- upatch_pin_path(pin, sizeof(pin), name, entry, NULL))
- return -ENAMETOOLONG;
- fd = bpf_obj_get(pin);
- if (fd < 0)
- return -errno;
- ret = bpf_prog_get_info_by_fd(fd, &info, &len);
- if (!ret && info.type != BPF_PROG_TYPE_XDP)
- ret = -ESTALE;
- if (ret) {
- close(fd);
- return ret;
- }
- *id = info.id;
- return fd;
-}
-
struct link_scan {
__u32 next;
bool dead;
@@ -4456,10 +4417,10 @@ static int reconcile_attach(int prog_fd, const char *name,
return 0;
}
-static int reconcile_prog_failed(const char *name, __u32 index, int err,
+static int reconcile_prog_failed(const char *name, int err,
struct op_report *rep)
{
- pr_err("upatch reconcile: program %u of %s: %s", index, name,
+ pr_err("upatch reconcile: an XDP program of %s: %s", name,
strerror(-err));
if (err == -EACCES || err == -EPERM)
rep_fail(rep, "pre_flight", "lsm_denied", err,
@@ -4470,6 +4431,27 @@ static int reconcile_prog_failed(const char *name, __u32 index, int err,
return 1;
}
+struct reconcile_pass {
+ const char *name;
+ __u32 *next;
+ bool *needed;
+ struct op_report *rep;
+};
+
+static int reconcile_device(int prog_fd, const struct prog_spec *spec,
+ const struct xdp_device *dev, __u32 attached,
+ void *ctx)
+{
+ struct reconcile_pass *p = ctx;
+
+ if (attached)
+ return 0;
+ *p->needed = true;
+ if (!p->next)
+ return 0;
+ return reconcile_attach(prog_fd, p->name, spec, dev, p->next, p->rep);
+}
+
/*
* With next NULL only says whether a device needs attaching, or that the
* pins need a look under the register lock.
@@ -4478,46 +4460,20 @@ static int reconcile_walk(const struct xdp_work *w,
const struct xdp_device *devices, size_t count,
__u32 *next, bool *needed, struct op_report *rep)
{
- __u32 i;
-
- for (i = 0; i < w->u.hdr.nr_progs; i++) {
- const struct prog_spec *spec = &w->specs[i];
- __u32 prog_id = 0;
- size_t j;
- int fd;
+ struct reconcile_pass pass = {
+ .name = w->name, .next = next, .needed = needed, .rep = rep,
+ };
+ int ret;
- if (spec->kind != UPATCH_ATTACH_XDP)
- continue;
- fd = xdp_prog_open(w->name, i, &prog_id);
- if (fd < 0) {
- if (!next) {
- *needed = true;
- return 0;
- }
- return reconcile_prog_failed(w->name, i, fd, rep);
- }
- for (j = 0; j < count; j++) {
- bool selected = xdp_device_selected(devices, count, j,
- spec->device_classes);
- __u32 attached = 0;
-
- if (selected &&
- bpf_xdp_query_id((int)devices[j].ifindex,
- XDP_FLAGS_DRV_MODE, &attached))
- continue;
- if (xdp_reconcile_action(selected, attached, prog_id) !=
- XDP_RECONCILE_ATTACH)
- continue;
- *needed = true;
- if (next && reconcile_attach(fd, w->name, spec,
- &devices[j], next, rep)) {
- close(fd);
- return 1;
- }
- }
- close(fd);
+ ret = upatch_xdp_each_uncovered(w->name, w->specs, w->u.hdr.nr_progs,
+ devices, count, reconcile_device, &pass);
+ if (ret >= 0)
+ return ret;
+ if (!next) {
+ *needed = true;
+ return 0;
}
- return 0;
+ return reconcile_prog_failed(w->name, ret, rep);
}
static int reconcile_apply(const struct xdp_work *w,
diff --git a/testing/functional/upatch/t3111-xdp.sh b/testing/functional/upatch/t3111-xdp.sh
index b3f0ba9a..9045eeb3 100644
--- a/testing/functional/upatch/t3111-xdp.sh
+++ b/testing/functional/upatch/t3111-xdp.sh
@@ -91,6 +91,7 @@ test_xdp_success 'a device without native XDP is skipped beside supported ones'
ip link add xdpbr type bridge && ip link set xdpbr up &&
load "$NAME" &&
[ "$("$H" query xdph0)" -gt 0 ] && [ "$("$H" query xdpbr)" = 0 ] &&
+ "$SHIRUDO_BIN" status | grep -q "XdpCovered *WARN .*$NAME on xdpbr (no native XDP)" &&
unload "$NAME"
'
diff --git a/testing/functional/upatch/t3112-xdp-reconcile.sh b/testing/functional/upatch/t3112-xdp-reconcile.sh
index 450daceb..5b5916ac 100644
--- a/testing/functional/upatch/t3112-xdp-reconcile.sh
+++ b/testing/functional/upatch/t3112-xdp-reconcile.sh
@@ -70,9 +70,11 @@ test_xdp_success 'a device added after load is attached, once' '
load "$NAME" &&
add_pair xdpc 30010 xdpd 30011 &&
[ "$("$H" query xdpc)" = 0 ] &&
+ "$SHIRUDO_BIN" status | grep -q "XdpCovered *WARN .*$NAME on xdpc (not attached)" &&
reconcile &&
[ "$("$H" query xdpc)" -gt 0 ] &&
[ "$("$H" query xdpd)" = 0 ] &&
+ ! "$SHIRUDO_BIN" status | grep -q "XdpCovered *WARN" &&
[ -e "$B/$NAME/link_1" ] && [ ! -e "$B/$NAME/link_2" ] &&
before=$(wc -l </var/lib/shirudo/eventlog) &&
pins=$(ls "$B/$NAME" | wc -l) &&
@@ -128,7 +130,7 @@ test_xdp_success 'a veth end moved away keeps its link and the host end attaches
[ "$("$H" query xdpb)" -gt 0 ]
'
-test_xdp_success 'a driver refusing one device warns and spares the others' '
+test_xdp_success 'a driver refusing one device warns, spares the others and shows in status' '
add_pair xdpa 30000 xdpb 30001 &&
load "$NAME" &&
ip link add xdpc index 30010 numrxqueues 1 type veth \
@@ -138,7 +140,8 @@ test_xdp_success 'a driver refusing one device warns and spares the others' '
out=$(reconcile 2>&1) &&
[ "$("$H" query xdpc)" = 0 ] &&
[ "$("$H" query xdpe)" -gt 0 ] &&
- printf "%s\n" "$out" | grep -q "attach xdpc"
+ printf "%s\n" "$out" | grep -q "attach xdpc" &&
+ "$SHIRUDO_BIN" status | grep -q "XdpCovered *WARN .*$NAME on xdpc (no native XDP)"
'
test_xdp_success 'an unload racing a pass is not tampering' '
diff --git a/testing/unit/conditions.c b/testing/unit/conditions.c
index c8c9afa5..ee628ce8 100644
--- a/testing/unit/conditions.c
+++ b/testing/unit/conditions.c
@@ -7,17 +7,23 @@
#include "conditions.h"
#include "unit.h"
-static const struct condition *upatches_measured(const struct conditions_input *in,
- struct condition *c)
+static const struct condition *condition_of(const struct conditions_input *in,
+ struct condition *c, const char *type)
{
size_t n = conditions(in, c, CONDITIONS_MAX), i;
for (i = 0; i < n; i++)
- if (!strcmp(c[i].type, "UpatchesMeasured"))
+ if (!strcmp(c[i].type, type))
return &c[i];
return NULL;
}
+static const struct condition *upatches_measured(const struct conditions_input *in,
+ struct condition *c)
+{
+ return condition_of(in, c, "UpatchesMeasured");
+}
+
static void changed_xdp_archive_is_tampered(void)
{
struct conditions_input in = {
@@ -107,12 +113,77 @@ static void no_change_leaves_the_condition_alone(void)
EXPECT_TRUE(strcmp(status_verdict(&in), "tampered"));
}
+static void an_uncovered_device_degrades(void)
+{
+ struct conditions_input in = {
+ .reachable = true,
+ .parsed = true,
+ .lsm_attached = 1,
+ .keyring_present = 1,
+ .chain_seen = 1,
+ .xdp_uncovered = 1,
+ .xdp_uncovered_detail = "fw on eth1 (no multi-buffer XDP)",
+ };
+ struct condition c[CONDITIONS_MAX];
+ const struct condition *row;
+ char reason[128];
+
+ row = condition_of(&in, c, "XdpCovered");
+ ASSERT_TRUE(row);
+ EXPECT_STREQ(row->status, "WARN");
+ EXPECT_TRUE(strstr(row->detail, "fw on eth1 (no multi-buffer XDP)"));
+ EXPECT_STREQ(status_verdict(&in), "degraded");
+ status_reason(&in, reason, sizeof(reason));
+ EXPECT_TRUE(strstr(reason, "XDP upatch selects"));
+}
+
+static void unchecked_coverage_warns_without_degrading(void)
+{
+ struct conditions_input in = {
+ .reachable = true,
+ .parsed = true,
+ .lsm_attached = 1,
+ .keyring_present = 1,
+ .chain_seen = 1,
+ .xdp_coverage_rc = -EACCES,
+ };
+ struct condition c[CONDITIONS_MAX];
+ const struct condition *row;
+
+ row = condition_of(&in, c, "XdpCovered");
+ ASSERT_TRUE(row);
+ EXPECT_STREQ(row->status, "WARN");
+ EXPECT_TRUE(strstr(row->detail, "not checked"));
+ EXPECT_STREQ(status_verdict(&in), "ok");
+}
+
+static void covered_devices_are_ok(void)
+{
+ struct conditions_input in = {
+ .reachable = true,
+ .parsed = true,
+ .lsm_attached = 1,
+ .keyring_present = 1,
+ .chain_seen = 1,
+ };
+ struct condition c[CONDITIONS_MAX];
+ const struct condition *row;
+
+ row = condition_of(&in, c, "XdpCovered");
+ ASSERT_TRUE(row);
+ EXPECT_STREQ(row->status, "OK");
+ EXPECT_STREQ(status_verdict(&in), "ok");
+}
+
static const struct unit_case cases[] = {
UNIT_CASE(changed_xdp_archive_is_tampered),
UNIT_CASE(a_changed_archive_outranks_a_pin_warning),
UNIT_CASE(a_lost_link_is_tampered),
UNIT_CASE(a_check_that_could_not_run_warns),
UNIT_CASE(no_change_leaves_the_condition_alone),
+ UNIT_CASE(an_uncovered_device_degrades),
+ UNIT_CASE(unchecked_coverage_warns_without_degrading),
+ UNIT_CASE(covered_devices_are_ok),
{}
};
diff --git a/testing/unit/upatch_verify.c b/testing/unit/upatch_verify.c
index a680b42e..9b7115a3 100644
--- a/testing/unit/upatch_verify.c
+++ b/testing/unit/upatch_verify.c
@@ -132,6 +132,26 @@ static void links_of_a_missing_archive_are_stale(void)
-ESTALE);
}
+static void specs_of_a_missing_archive_are_stale(void)
+{
+ __u8 payload[UPATCH_PAYLOAD_HASH_LEN] = {};
+ struct prog_spec *specs = NULL;
+ struct upatch u;
+
+ EXPECT_EQ(upatch_archive_specs("shirudo-unit-no-such-upatch", payload,
+ &u, &specs), -ESTALE);
+ EXPECT_TRUE(!specs);
+}
+
+static void an_unpinned_xdp_program_does_not_open(void)
+{
+ __u32 id = 0;
+
+ EXPECT_TRUE(upatch_xdp_prog_open("shirudo-unit-no-such-upatch", 0,
+ &id) < 0);
+ EXPECT_EQ(id, 0);
+}
+
static const struct unit_case cases[] = {
UNIT_CASE(the_loaded_bytes_verify),
UNIT_CASE(another_payload_is_stale),
@@ -139,6 +159,8 @@ static const struct unit_case cases[] = {
UNIT_CASE(a_truncated_file_is_stale),
UNIT_CASE(a_missing_archive_is_stale),
UNIT_CASE(links_of_a_missing_archive_are_stale),
+ UNIT_CASE(specs_of_a_missing_archive_are_stale),
+ UNIT_CASE(an_unpinned_xdp_program_does_not_open),
{}
};
diff --git a/testing/unit/xdp.c b/testing/unit/xdp.c
index 29573cfe..2b1f588e 100644
--- a/testing/unit/xdp.c
+++ b/testing/unit/xdp.c
@@ -192,6 +192,18 @@ static size_t add_attr(__u8 *buf, size_t len, __u16 type,
return len + NLA_ALIGN(attr.nla_len);
}
+static void uncovered_devices_say_why(void)
+{
+ __u64 basic = NETDEV_XDP_ACT_BASIC, sg = NETDEV_XDP_ACT_RX_SG;
+
+ EXPECT_STREQ(xdp_uncovered_reason(9, 0, basic | sg),
+ "another XDP program attached");
+ EXPECT_STREQ(xdp_uncovered_reason(0, -EOPNOTSUPP, 0), "not attached");
+ EXPECT_STREQ(xdp_uncovered_reason(0, 0, 0), "no native XDP");
+ EXPECT_STREQ(xdp_uncovered_reason(0, 0, basic), "no multi-buffer XDP");
+ EXPECT_STREQ(xdp_uncovered_reason(0, 0, basic | sg), "not attached");
+}
+
static void link_messages_are_checked(void)
{
struct ifinfomsg info = { .ifi_index = 12 };
@@ -273,6 +285,7 @@ static const struct unit_case cases[] = {
UNIT_CASE(restore_fails_on_a_driver_refusal),
UNIT_CASE(load_stops_on_an_occupied_device),
UNIT_CASE(multibuf_is_required_of_native_xdp_alone),
+ UNIT_CASE(uncovered_devices_say_why),
UNIT_CASE(device_features_are_checked),
UNIT_CASE(link_messages_are_checked),
UNIT_CASE(kernel_discovery_revalidates_devices),
diff --git a/util/conditions.c b/util/conditions.c
index 8bab510e..68a722f1 100644
--- a/util/conditions.c
+++ b/util/conditions.c
@@ -217,6 +217,22 @@ size_t conditions(const struct conditions_input *in,
}
n++;
}
+ if (n < cap) {
+ c[n].type = "XdpCovered";
+ if (in->xdp_uncovered)
+ set_detail(&c[n], "WARN",
+ "%d selected devices run without their XDP upatch: %s",
+ in->xdp_uncovered,
+ in->xdp_uncovered_detail ?
+ in->xdp_uncovered_detail : "?");
+ else if (in->xdp_coverage_rc)
+ set_detail(&c[n], "WARN", "XDP coverage not checked: %s",
+ strerror(-in->xdp_coverage_rc));
+ else
+ set_detail(&c[n], "OK",
+ "every device an XDP upatch selects runs it");
+ n++;
+ }
return n;
}
@@ -247,7 +263,7 @@ const char *status_verdict(const struct conditions_input *in)
return "init-pending";
if (in->config_seen && in->config_state == -EINPROGRESS)
return "reboot-pending";
- if (!in->chain_seen)
+ if (!in->chain_seen || in->xdp_uncovered)
return "degraded";
return "ok";
}
@@ -301,7 +317,12 @@ void status_reason(const struct conditions_input *in,
strscpy(buf, "a config activation is pending until the next reboot",
cap);
} else if (strcmp(v, "degraded") == 0) {
- strscpy(buf, in->tpm_reachable ?
- "no register bound this boot" : "no TPM answered", cap);
+ if (in->chain_seen)
+ strscpy(buf, "a device an XDP upatch selects does not run it",
+ cap);
+ else
+ strscpy(buf, in->tpm_reachable ?
+ "no register bound this boot" : "no TPM answered",
+ cap);
}
}
diff --git a/util/conditions.h b/util/conditions.h
index 43445f47..c361b200 100644
--- a/util/conditions.h
+++ b/util/conditions.h
@@ -54,6 +54,9 @@ struct conditions_input {
int links_lost; /* loaded upatches missing a link */
const char *links_lost_detail; /* their names, when any */
int checks_rc; /* -errno of a link or archive check that could not run */
+ int xdp_uncovered; /* selected devices an XDP upatch does not run on */
+ const char *xdp_uncovered_detail; /* upatch, device and why, when any */
+ int xdp_coverage_rc; /* -errno when that could not be checked */
};
struct condition {
@@ -65,9 +68,9 @@ struct condition {
/*
* Maximum number of conditions returned today (LsmAttached,
* KeyringSealed, ChainIntact, UpatchesMeasured, TpmMeasured,
- * ConfigActive); callers can size their stack array off this.
+ * ConfigActive, XdpCovered); callers can size their stack array off this.
*/
-#define CONDITIONS_MAX 6
+#define CONDITIONS_MAX 7
size_t conditions(const struct conditions_input *in,
struct condition *out, size_t cap);
diff --git a/util/upatch_verify.c b/util/upatch_verify.c
index ebd9562f..53f07258 100644
--- a/util/upatch_verify.c
+++ b/util/upatch_verify.c
@@ -9,23 +9,30 @@
#include <errno.h>
#include <limits.h>
#include <string.h>
+#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/xattr.h>
#include <unistd.h>
#include <bpf/bpf.h>
+#include <bpf/libbpf.h>
#include <linux/bpf.h>
+#include <linux/if_link.h>
+#include <shirudo/misc.h>
+#include <shirudo/overflow.h>
#include <shirudo/string.h>
#include "chain.h"
#include "hex.h"
+#include "malloc.h"
#include "measured.h"
#include "paths.h"
#include "seal.h"
#include "upatch.h"
#include "upatch_pins.h"
#include "upatch_verify.h"
+#include "xdp.h"
static int stale_unless_resources(int err)
{
@@ -169,6 +176,95 @@ out:
return ret;
}
+int upatch_archive_specs(const char *name,
+ const __u8 payload[UPATCH_PAYLOAD_HASH_LEN],
+ struct upatch *u, struct prog_spec **specs)
+{
+ const void *attach;
+ __u32 len;
+ int ret;
+
+ ret = upatch_archive_verify(name, payload, u);
+ if (ret)
+ return ret;
+ attach = upatch_signed_attach(u, &len);
+ ret = attach ? prog_specs_parse(attach, len, u->hdr.nr_maps,
+ u->hdr.nr_progs, specs) : -ESTALE;
+ if (ret) {
+ upatch_close(u);
+ return ret == -ENOMEM ? ret : -ESTALE;
+ }
+ return 0;
+}
+
+int upatch_xdp_prog_open(const char *name, __u32 index, __u32 *id)
+{
+ struct bpf_prog_info info = {};
+ __u32 len = sizeof(info);
+ char pin[PATH_MAX];
+ char entry[32];
+ int fd, ret;
+
+ if (strsprintf(entry, sizeof(entry), XDP_PROG_PIN_PREFIX "%u", index) < 0 ||
+ upatch_pin_path(pin, sizeof(pin), name, entry, NULL))
+ return -ENAMETOOLONG;
+ fd = bpf_obj_get(pin);
+ if (fd < 0)
+ return -errno;
+ ret = bpf_prog_get_info_by_fd(fd, &info, &len);
+ if (!ret && info.type != BPF_PROG_TYPE_XDP)
+ ret = -ESTALE;
+ if (ret) {
+ close(fd);
+ return ret;
+ }
+ *id = info.id;
+ return fd;
+}
+
+int upatch_xdp_each_uncovered(const char *name, const struct prog_spec *specs,
+ __u32 nr_progs, const struct xdp_device *devices,
+ size_t count,
+ int (*cb)(int prog_fd, const struct prog_spec *spec,
+ const struct xdp_device *dev,
+ __u32 attached, void *ctx),
+ void *ctx)
+{
+ __u32 i;
+
+ for (i = 0; i < nr_progs; i++) {
+ __u32 prog_id = 0;
+ size_t j;
+ int fd;
+
+ if (specs[i].kind != UPATCH_ATTACH_XDP)
+ continue;
+ fd = upatch_xdp_prog_open(name, i, &prog_id);
+ if (fd < 0)
+ return fd;
+ for (j = 0; j < count; j++) {
+ __u32 attached = 0;
+ int ret;
+
+ /* A device that cannot be queried went away. */
+ if (!xdp_device_selected(devices, count, j,
+ specs[i].device_classes) ||
+ bpf_xdp_query_id((int)devices[j].ifindex,
+ XDP_FLAGS_DRV_MODE, &attached) ||
+ xdp_reconcile_action(true, attached, prog_id) ==
+ XDP_RECONCILE_COVERED)
+ continue;
+ ret = cb(fd, &specs[i], &devices[j], attached, ctx);
+ if (ret) {
+ close(fd);
+ return ret;
+ }
+ }
+ close(fd);
+ }
+ return 0;
+}
+
/* Whether the set holds name with the payload its pin directory records. */
static bool pin_measured(const struct measured_set *s, const char *name,
__u8 payload[UPATCH_PAYLOAD_HASH_LEN])
@@ -185,7 +281,8 @@ static bool pin_measured(const struct measured_set *s, const char *name,
}
/* These return 1 for a hit, 0 for none, or -errno when they could not tell. */
-static int xdp_archive_changed(const struct measured_set *s, const char *name)
+static int xdp_archive_changed(const struct measured_set *s, const char *name,
+ void *ctx)
{
__u8 payload[UPATCH_PAYLOAD_HASH_LEN];
struct upatch_pins pins;
@@ -201,7 +298,8 @@ static int xdp_archive_changed(const struct measured_set *s, const char *name)
return ret == -ESTALE ? 1 : ret;
}
-static int links_lost(const struct measured_set *s, const char *name)
+static int links_lost(const struct measured_set *s, const char *name,
+ void *ctx)
{
__u8 payload[UPATCH_PAYLOAD_HASH_LEN];
char path[PATH_MAX];
@@ -218,8 +316,10 @@ static int links_lost(const struct measured_set *s, const char *name)
return !ret || ret == -ESTALE ? 1 : ret;
}
+/* check gets ctx as well, and cb may be NULL. */
static int walk_pinned(const struct measured_set *s,
- int (*check)(const struct measured_set *s, const char *name),
+ int (*check)(const struct measured_set *s, const char *name,
+ void *ctx),
int (*cb)(const char *name, void *ctx), void *ctx,
int *check_err)
{
@@ -241,13 +341,14 @@ static int walk_pinned(const struct measured_set *s,
if (!strcmp(e->d_name, ".") || !strcmp(e->d_name, "..") ||
upatch_name_from_bpffs(name, sizeof(name), e->d_name))
continue;
- result = check(s, name);
+ result = check(s, name, ctx);
if (result < 0 && !*check_err)
*check_err = result;
if (result <= 0)
continue;
found++;
- ret = cb(name, ctx);
+ if (cb)
+ ret = cb(name, ctx);
}
closedir(d);
return ret ? ret : found;
@@ -266,3 +367,74 @@ int upatch_links_lost(const struct measured_set *s,
{
return walk_pinned(s, links_lost, cb, ctx, check_err);
}
+
+struct uncovered_walk {
+ int (*cb)(const char *name, const char *dev,
+ const char *why, void *ctx);
+ void *ctx;
+ const char *name;
+ struct xdp_device *devices;
+ size_t count;
+ bool devices_read;
+ int found;
+};
+
+static int note_uncovered(int prog_fd, const struct prog_spec *spec,
+ const struct xdp_device *dev, __u32 attached,
+ void *ctx)
+{
+ struct uncovered_walk *w = ctx;
+ __u64 features = 0;
+ int err = 0;
+
+ if (!attached)
+ err = xdp_device_features(dev->ifindex, &features);
+ w->found++;
+ return w->cb(w->name, dev->name,
+ xdp_uncovered_reason(attached, err, features), w->ctx);
+}
+
+/* An archive that changed is upatch_xdp_archives_changed()'s to report. */
+static int xdp_uncovered(const struct measured_set *s, const char *name,
+ void *ctx)
+{
+ __u8 payload[UPATCH_PAYLOAD_HASH_LEN];
+ struct uncovered_walk *w = ctx;
+ struct prog_spec *specs = NULL;
+ struct upatch_pins pins;
+ struct upatch u;
+ int ret;
+
+ if (upatch_pins_read(name, &pins) || !pins.nr_xdp_progs ||
+ !pin_measured(s, name, payload))
+ return 0;
+ ret = upatch_archive_specs(name, payload, &u, &specs);
+ if (ret)
+ return ret == -ESTALE ? 0 : ret;
+ if (!w->devices_read) {
+ ret = xdp_devices_read(&w->devices, &w->count);
+ w->devices_read = !ret;
+ }
+ if (!ret) {
+ w->name = name;
+ ret = upatch_xdp_each_uncovered(name, specs, u.hdr.nr_progs,
+ w->devices, w->count,
+ note_uncovered, w);
+ }
+ prog_specs_free(specs, u.hdr.nr_progs);
+ upatch_close(&u);
+ return min(ret, 0);
+}
+
+int upatch_xdp_uncovered(const struct measured_set *s,
+ int (*cb)(const char *name, const char *dev,
+ const char *why, void *ctx),
+ void *ctx, int *check_err)
+{
+ struct uncovered_walk w = { .cb = cb, .ctx = ctx };
+ int ret;
+
+ ret = walk_pinned(s, xdp_uncovered, NULL, &w, check_err);
+ xfree(w.devices, size_mul(w.count, sizeof(*w.devices)));
+ return ret < 0 ? ret : w.found;
+}
diff --git a/util/upatch_verify.h b/util/upatch_verify.h
index b5fd9a82..ba1e5218 100644
--- a/util/upatch_verify.h
+++ b/util/upatch_verify.h
@@ -8,10 +8,14 @@
#ifndef SHIRUDO_UTIL_UPATCH_VERIFY_H
#define SHIRUDO_UTIL_UPATCH_VERIFY_H
+#include <stddef.h>
+
#include <shirudo/types.h>
#include <shirudo/upatch.h>
+struct prog_spec;
struct upatch;
+struct xdp_device;
/*
* 0 with the artifact open in *out, -ESTALE when it is not what payload
@@ -31,6 +35,31 @@ int upatch_archive_verify(const char *name,
*/
int upatch_links_complete(const char *name, const char *path);
+/*
+ * As upatch_archive_verify(), with the signed attach metadata of every
+ * program in *specs, which prog_specs_free() releases.
+ */
+int upatch_archive_specs(const char *name,
+ const __u8 payload[UPATCH_PAYLOAD_HASH_LEN],
+ struct upatch *u, struct prog_spec **specs);
+
+/* The fd of XDP program index pinned for name, its id in *id, or -errno. */
+int upatch_xdp_prog_open(const char *name, __u32 index, __u32 *id);
+
+/*
+ * Calls cb for each device an XDP program of name selects and that does not
+ * run it, with what the device runs instead, 0 for nothing. A non-zero
+ * return of cb ends the walk with that value, and a program pin that cannot
+ * be opened ends it with its -errno.
+ */
+int upatch_xdp_each_uncovered(const char *name, const struct prog_spec *specs,
+ __u32 nr_progs, const struct xdp_device *devices,
+ size_t count,
+ int (*cb)(int prog_fd, const struct prog_spec *spec,
+ const struct xdp_device *dev,
+ __u32 attached, void *ctx),
+ void *ctx);
+
struct measured_set;
/*
@@ -48,4 +77,14 @@ int upatch_links_lost(const struct measured_set *s,
int (*cb)(const char *name, void *ctx), void *ctx,
int *check_err);
+/*
+ * The devices an XDP upatch the set holds selects and that do not run it.
+ * cb runs for each with the upatch, the device and why. The number found,
+ * with *check_err as above.
+ */
+int upatch_xdp_uncovered(const struct measured_set *s,
+ int (*cb)(const char *name, const char *dev,
+ const char *why, void *ctx),
+ void *ctx, int *check_err);
+
#endif /* SHIRUDO_UTIL_UPATCH_VERIFY_H */
diff --git a/util/xdp.c b/util/xdp.c
index 9d5c8da4..e157e219 100644
--- a/util/xdp.c
+++ b/util/xdp.c
@@ -537,6 +537,20 @@ const char *xdp_attach_strerror(int err)
return strerror(-err);
}
+const char *xdp_uncovered_reason(__u32 attached, int features_err,
+ __u64 features)
+{
+ if (attached)
+ return "another XDP program attached";
+ if (features_err)
+ return "not attached";
+ if (!(features & NETDEV_XDP_ACT_BASIC))
+ return "no native XDP";
+ if (xdp_multibuf_refused(features))
+ return "no multi-buffer XDP";
+ return "not attached";
+}
+
static int device_compare(const void *a, const void *b)
{
const struct xdp_device *left = a, *right = b;
diff --git a/util/xdp.h b/util/xdp.h
index b15c249f..47510672 100644
--- a/util/xdp.h
+++ b/util/xdp.h
@@ -60,4 +60,11 @@ int xdp_device_features(__u32 ifindex, __u64 *features);
bool xdp_multibuf_refused(__u64 features);
const char *xdp_attach_strerror(int err);
+/*
+ * Why a device a program selects does not run it: attached as above,
+ * features as read, unless features_err says they could not be.
+ */
+const char *xdp_uncovered_reason(__u32 attached, int features_err,
+ __u64 features);
+
#endif /* SHIRUDO_XDP_H */