Skip to content

eBPF-based security platform

status: alert when an XDP archive differs from its loaded payload

John Fastabend258adaff7d19
diff --git a/Documentation/operate/run/read-status.rst b/Documentation/operate/run/read-status.rst
index b0d194d3..02a79acd 100644
--- a/Documentation/operate/run/read-status.rst
+++ b/Documentation/operate/run/read-status.rst
@@ -233,9 +233,13 @@ verdict is derived from them.
this boot: <names>`` is what a load stopped between its pins and
its extend leaves, or an archive root brought back after its
unload, which the next ``upatch load`` or ``upatch unload``
- undoes before it acts. ``WARN`` ``no record of this boot to check
- the pins against`` before ``init``, or ``pins not checked against
- the records: <error>``.
+ undoes before it acts. ``ALERT`` ``<n> XDP archives differ from
+ the loaded payload: <names>``: the sealed archive of a loaded XDP
+ upatch has changed, or is gone, so ``upatch reconcile`` refuses to
+ run and new devices stay uncovered. Handle it as an incident:
+ :doc:`/operate/troubleshoot/incident-tampered`. ``WARN`` ``no
+ record of this boot to check the pins against`` before ``init``, or
+ ``pins not checked against the records: <error>``.
* - ``TpmMeasured``
- The NV index is defined, written and readable. ``WARN`` ``NV
index 0x01818E00 not bound this boot`` or ``no TPM answered``.
diff --git a/builtin-status.c b/builtin-status.c
index 97a32670..b9f479f5 100644
--- a/builtin-status.c
+++ b/builtin-status.c
@@ -59,6 +59,7 @@
#include "util/tamper.h"
#include "util/upatch_resolve.h"
#include "util/upatch_table.h"
+#include "util/upatch_verify.h"
#include "util/version.h"
#define UNMEASURED_NAMES 256
@@ -854,7 +855,9 @@ int cmd_status(int argc, const char **argv)
const char *otel_status = NULL;
bool otel_endpoint_configured = false;
char unmeasured_names[UNMEASURED_NAMES] = "";
+ char xdp_tampered_names[UNMEASURED_NAMES] = "";
struct measured_set *mset = NULL;
+ int xdp_tampered = 0;
char config_root_hex[65] = "";
__u8 config_root[32];
int unmeasured, lock;
@@ -966,6 +969,8 @@ int cmd_status(int argc, const char **argv)
unmeasured = archived < 0 ? archived :
unmeasured + archived;
}
+ xdp_tampered = upatch_xdp_archives_changed(mset, note_unmeasured,
+ xdp_tampered_names);
measured_set_free(mset);
}
eventlog_unlock(lock);
@@ -1031,6 +1036,8 @@ int cmd_status(int argc, const char **argv)
cin.pins_rc = min(unmeasured, 0);
cin.pins_unmeasured = max(unmeasured, 0);
cin.pins_detail = unmeasured_names;
+ cin.xdp_tampered = max(xdp_tampered, 0);
+ cin.xdp_tampered_detail = xdp_tampered_names;
keyring_cond_input(&cin, &bpf, &dmv);
if (json) {
diff --git a/testing/unit/conditions.c b/testing/unit/conditions.c
new file mode 100644
index 00000000..6cd5b2a5
--- /dev/null
+++ b/testing/unit/conditions.c
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/* Copyright (c) 2026 Authors of shirudo */
+
+#include <errno.h>
+#include <string.h>
+
+#include "conditions.h"
+#include "unit.h"
+
+static const struct condition *upatches_measured(const struct conditions_input *in,
+ struct condition *c)
+{
+ size_t n = conditions(in, c, CONDITIONS_MAX), i;
+
+ for (i = 0; i < n; i++)
+ if (!strcmp(c[i].type, "UpatchesMeasured"))
+ return &c[i];
+ return NULL;
+}
+
+static void changed_xdp_archive_is_tampered(void)
+{
+ struct conditions_input in = {
+ .reachable = true,
+ .parsed = true,
+ .lsm_attached = 1,
+ .xdp_tampered = 1,
+ .xdp_tampered_detail = "fix",
+ };
+ struct condition c[CONDITIONS_MAX];
+ const struct condition *row;
+
+ row = upatches_measured(&in, c);
+ ASSERT_TRUE(row);
+ EXPECT_STREQ(row->status, "ALERT");
+ EXPECT_TRUE(strstr(row->detail, "1 XDP archives differ"));
+ EXPECT_TRUE(strstr(row->detail, "fix"));
+ EXPECT_STREQ(status_verdict(&in), "tampered");
+}
+
+static void a_changed_archive_outranks_a_pin_warning(void)
+{
+ struct conditions_input in = {
+ .reachable = true,
+ .parsed = true,
+ .pins_rc = -ENOENT,
+ .xdp_tampered = 2,
+ };
+ struct condition c[CONDITIONS_MAX];
+ const struct condition *row;
+
+ row = upatches_measured(&in, c);
+ ASSERT_TRUE(row);
+ EXPECT_STREQ(row->status, "ALERT");
+}
+
+static void no_change_leaves_the_condition_alone(void)
+{
+ struct conditions_input in = {
+ .reachable = true,
+ .parsed = true,
+ .lsm_attached = 1,
+ };
+ struct condition c[CONDITIONS_MAX];
+ const struct condition *row;
+
+ row = upatches_measured(&in, c);
+ ASSERT_TRUE(row);
+ EXPECT_STREQ(row->status, "OK");
+ EXPECT_TRUE(strcmp(status_verdict(&in), "tampered"));
+}
+
+static const struct unit_case cases[] = {
+ UNIT_CASE(changed_xdp_archive_is_tampered),
+ UNIT_CASE(a_changed_archive_outranks_a_pin_warning),
+ UNIT_CASE(no_change_leaves_the_condition_alone),
+ {}
+};
+
+UNIT_SUITE(conditions, cases);
diff --git a/util/conditions.c b/util/conditions.c
index cf38dee4..c0e4416b 100644
--- a/util/conditions.c
+++ b/util/conditions.c
@@ -140,7 +140,13 @@ size_t conditions(const struct conditions_input *in,
}
if (n < cap) {
c[n].type = "UpatchesMeasured";
- if (in->pins_rc == -ENOENT)
+ if (in->xdp_tampered)
+ set_detail(&c[n], "ALERT",
+ "%d XDP archives differ from the loaded payload: %s",
+ in->xdp_tampered,
+ in->xdp_tampered_detail ?
+ in->xdp_tampered_detail : "?");
+ else if (in->pins_rc == -ENOENT)
set_detail(&c[n], "WARN",
"no record of this boot to check the pins against");
else if (in->pins_rc)
@@ -222,7 +228,7 @@ const char *status_verdict(const struct conditions_input *in)
if (!in->parsed)
return "unparseable";
if ((in->cm_seen && !in->chain_matches) || in->pins_unmeasured ||
- keyring_tampered(in) || config_untrusted(in))
+ in->xdp_tampered || keyring_tampered(in) || config_untrusted(in))
return "tampered";
if (!in->lsm_attached)
return "lsm-off";
@@ -249,6 +255,9 @@ void status_reason(const struct conditions_input *in,
} else if (strcmp(v, "tampered") == 0) {
if (in->cm_seen && !in->chain_matches)
strscpy(buf, "live register differs from the eventlog replay", cap);
+ else if (in->xdp_tampered)
+ strscpy(buf, "the archive of a loaded XDP upatch differs from what was loaded",
+ cap);
else if (in->pins_unmeasured)
strscpy(buf, "a upatch is pinned or archived without a record of this boot",
cap);
diff --git a/util/conditions.h b/util/conditions.h
index dae694d1..4f625b83 100644
--- a/util/conditions.h
+++ b/util/conditions.h
@@ -49,6 +49,8 @@ struct conditions_input {
int pins_rc; /* 0 when the pins were checked, else -errno */
int pins_unmeasured; /* pinned or archived without a record this boot */
const char *pins_detail; /* their names, when any */
+ int xdp_tampered; /* loaded XDP upatches whose archive changed */
+ const char *xdp_tampered_detail; /* their names, when any */
};
struct condition {
diff --git a/util/upatch_verify.c b/util/upatch_verify.c
index e0bb8cf7..dd0f6649 100644
--- a/util/upatch_verify.c
+++ b/util/upatch_verify.c
@@ -5,17 +5,22 @@
* Whether the archive of a loaded upatch is still what was loaded.
*/
+#include <dirent.h>
#include <errno.h>
#include <limits.h>
#include <string.h>
+#include <sys/xattr.h>
#include <unistd.h>
#include <shirudo/string.h>
#include "chain.h"
+#include "hex.h"
+#include "measured.h"
#include "paths.h"
#include "seal.h"
#include "upatch.h"
+#include "upatch_pins.h"
#include "upatch_verify.h"
static int stale_unless_resources(int err)
@@ -68,3 +73,52 @@ int upatch_archive_verify(const char *name,
}
return 0;
}
+
+static bool xdp_archive_changed(const struct measured_set *s, const char *name)
+{
+ __u8 payload[UPATCH_PAYLOAD_HASH_LEN];
+ char hex[2 * UPATCH_PAYLOAD_HASH_LEN + 1];
+ struct upatch_pins pins;
+ char dir[PATH_MAX];
+ struct upatch u;
+ int ret;
+
+ if (upatch_pins_read(name, &pins) || !pins.nr_xdp_progs ||
+ upatch_pin_path(dir, sizeof(dir), name, NULL) ||
+ getxattr(dir, XATTR_PAYLOAD, payload, sizeof(payload)) !=
+ (ssize_t)sizeof(payload))
+ return false;
+ hex_encode(payload, sizeof(payload), hex);
+ if (!measured_holds(s, name, hex))
+ return false;
+ ret = upatch_archive_verify(name, payload, &u);
+ if (!ret)
+ upatch_close(&u);
+ return ret == -ESTALE;
+}
+
+int upatch_xdp_archives_changed(const struct measured_set *s,
+ int (*cb)(const char *name, void *ctx),
+ void *ctx)
+{
+ struct dirent *e;
+ int changed = 0;
+ int ret = 0;
+ DIR *d;
+
+ d = opendir(BPFFS_UPATCHES_DIR);
+ if (!d)
+ return errno == ENOENT ? 0 : -errno;
+ while (!ret && (e = readdir(d))) {
+ char name[UPATCH_NAME_MAX + 1];
+
+ if (!strcmp(e->d_name, ".") || !strcmp(e->d_name, "..") ||
+ upatch_name_from_bpffs(name, sizeof(name), e->d_name) ||
+ !xdp_archive_changed(s, name))
+ continue;
+ changed++;
+ ret = cb(name, ctx);
+ }
+ closedir(d);
+ return ret ? ret : changed;
+}
diff --git a/util/upatch_verify.h b/util/upatch_verify.h
index 2e6a067c..5ab6730b 100644
--- a/util/upatch_verify.h
+++ b/util/upatch_verify.h
@@ -24,4 +24,16 @@ int upatch_archive_verify(const char *name,
const __u8 payload[UPATCH_PAYLOAD_HASH_LEN],
struct upatch *out);
+struct measured_set;
+
+/*
+ * The XDP upatches the set holds whose archive is not what was loaded. cb
+ * runs for each and a non-zero return ends the walk with that value. The
+ * number found, or -errno when the pins cannot be read. A check that
+ * could not run counts as nothing found.
+ */
+int upatch_xdp_archives_changed(const struct measured_set *s,
+ int (*cb)(const char *name, void *ctx),
+ void *ctx);
+
#endif /* SHIRUDO_UTIL_UPATCH_VERIFY_H */