Skip to content

eBPF-based security platform

status: report link and archive checks that could not run

John Fastabenddf1ade384e90
diff --git a/Documentation/operate/run/read-status.rst b/Documentation/operate/run/read-status.rst
index 0ade6114..edd9f78b 100644
--- a/Documentation/operate/run/read-status.rst
+++ b/Documentation/operate/run/read-status.rst
@@ -238,13 +238,15 @@ verdict is derived from them.
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`. ``ALERT`` ``<n>
- upatches are missing a link: <names>``: a loaded upatch has fewer
- link pins than its signed metadata implies, so part of it is
- detached. For an upatch with XDP that means an ``xdp_prog_<i>`` pin
+ upatches are missing a link or their archive: <names>``: a loaded
+ upatch has fewer link pins than its signed metadata implies, so part
+ of it is detached, or its sealed archive is gone or unusable. For an upatch with XDP that means an ``xdp_prog_<i>`` pin
or the link of another attach program; a device going away is not
a missing link. Handle it the same way. ``WARN`` ``no
record of this boot to check the pins against`` before ``init``, or
- ``pins not checked against the records: <error>``.
+ ``pins not checked against the records: <error>``. ``WARN`` ``links
+ or archives not checked: <error>`` means one of those checks could
+ not run, which says nothing either way.
* - ``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 d0e38d24..6d550450 100644
--- a/builtin-status.c
+++ b/builtin-status.c
@@ -860,6 +860,7 @@ int cmd_status(int argc, const char **argv)
struct measured_set *mset = NULL;
int xdp_tampered = 0;
int links_lost = 0;
+ int checks_rc = 0;
char config_root_hex[65] = "";
__u8 config_root[32];
int unmeasured, lock;
@@ -972,9 +973,10 @@ int cmd_status(int argc, const char **argv)
unmeasured + archived;
}
xdp_tampered = upatch_xdp_archives_changed(mset, note_unmeasured,
- xdp_tampered_names);
+ xdp_tampered_names,
+ &checks_rc);
links_lost = upatch_links_lost(mset, note_unmeasured,
- links_lost_names);
+ links_lost_names, &checks_rc);
measured_set_free(mset);
}
eventlog_unlock(lock);
@@ -1044,6 +1046,7 @@ int cmd_status(int argc, const char **argv)
cin.xdp_tampered_detail = xdp_tampered_names;
cin.links_lost = max(links_lost, 0);
cin.links_lost_detail = links_lost_names;
+ cin.checks_rc = checks_rc;
keyring_cond_input(&cin, &bpf, &dmv);
if (json) {
diff --git a/testing/unit/conditions.c b/testing/unit/conditions.c
index 6db89b7a..c8c9afa5 100644
--- a/testing/unit/conditions.c
+++ b/testing/unit/conditions.c
@@ -69,10 +69,28 @@ static void a_lost_link_is_tampered(void)
row = upatches_measured(&in, c);
ASSERT_TRUE(row);
EXPECT_STREQ(row->status, "ALERT");
- EXPECT_TRUE(strstr(row->detail, "missing a link: fix"));
+ EXPECT_TRUE(strstr(row->detail, "missing a link or their archive: fix"));
EXPECT_STREQ(status_verdict(&in), "tampered");
}
+static void a_check_that_could_not_run_warns(void)
+{
+ struct conditions_input in = {
+ .reachable = true,
+ .parsed = true,
+ .lsm_attached = 1,
+ .checks_rc = -EACCES,
+ };
+ struct condition c[CONDITIONS_MAX];
+ const struct condition *row;
+
+ row = upatches_measured(&in, c);
+ ASSERT_TRUE(row);
+ EXPECT_STREQ(row->status, "WARN");
+ EXPECT_TRUE(strstr(row->detail, "not checked"));
+ EXPECT_TRUE(strcmp(status_verdict(&in), "tampered"));
+}
+
static void no_change_leaves_the_condition_alone(void)
{
struct conditions_input in = {
@@ -93,6 +111,7 @@ 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),
{}
};
diff --git a/testing/unit/upatch_verify.c b/testing/unit/upatch_verify.c
index 51e685a1..a680b42e 100644
--- a/testing/unit/upatch_verify.c
+++ b/testing/unit/upatch_verify.c
@@ -125,12 +125,20 @@ static void a_missing_archive_is_stale(void)
payload, &u), -ESTALE);
}
+static void links_of_a_missing_archive_are_stale(void)
+{
+ EXPECT_EQ(upatch_links_complete("shirudo-unit-no-such-upatch",
+ "/nonexistent/shirudo-unit.upatch"),
+ -ESTALE);
+}
+
static const struct unit_case cases[] = {
UNIT_CASE(the_loaded_bytes_verify),
UNIT_CASE(another_payload_is_stale),
UNIT_CASE(changed_data_under_an_intact_header_is_stale),
UNIT_CASE(a_truncated_file_is_stale),
UNIT_CASE(a_missing_archive_is_stale),
+ UNIT_CASE(links_of_a_missing_archive_are_stale),
{}
};
diff --git a/util/conditions.c b/util/conditions.c
index e4c82644..8bab510e 100644
--- a/util/conditions.c
+++ b/util/conditions.c
@@ -148,7 +148,7 @@ size_t conditions(const struct conditions_input *in,
in->xdp_tampered_detail : "?");
else if (in->links_lost)
set_detail(&c[n], "ALERT",
- "%d upatches are missing a link: %s",
+ "%d upatches are missing a link or their archive: %s",
in->links_lost,
in->links_lost_detail ?
in->links_lost_detail : "?");
@@ -164,6 +164,10 @@ size_t conditions(const struct conditions_input *in,
"%d pinned or archived without a record of this boot: %s",
in->pins_unmeasured,
in->pins_detail ? in->pins_detail : "?");
+ else if (in->checks_rc)
+ set_detail(&c[n], "WARN",
+ "links or archives not checked: %s",
+ strerror(-in->checks_rc));
else
set_detail(&c[n], "OK",
"every pinned or archived upatch is in this boot's records");
@@ -266,7 +270,8 @@ void status_reason(const struct conditions_input *in,
strscpy(buf, "the archive of a loaded XDP upatch differs from what was loaded",
cap);
else if (in->links_lost)
- strscpy(buf, "a loaded upatch is missing a link", cap);
+ strscpy(buf, "a loaded upatch is missing a link or its archive",
+ 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 dc8fdc0e..43445f47 100644
--- a/util/conditions.h
+++ b/util/conditions.h
@@ -53,6 +53,7 @@ struct conditions_input {
const char *xdp_tampered_detail; /* their names, when any */
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 */
};
struct condition {
diff --git a/util/upatch_verify.c b/util/upatch_verify.c
index d5079437..ebd9562f 100644
--- a/util/upatch_verify.c
+++ b/util/upatch_verify.c
@@ -142,12 +142,14 @@ int upatch_links_complete(const char *name, const char *path)
ret = upatch_open(path, &u);
if (ret)
- return ret;
+ return stale_unless_resources(ret);
attach = upatch_signed_attach(&u, &len);
ret = attach ? prog_specs_parse(attach, len, u.hdr.nr_maps,
- u.hdr.nr_progs, &specs) : -EINVAL;
- if (ret)
+ u.hdr.nr_progs, &specs) : -ESTALE;
+ if (ret) {
+ ret = stale_unless_resources(ret);
goto out;
+ }
for (i = 0; i < u.hdr.nr_progs; i++) {
if (specs[i].role == UPATCH_PROG_ROLE_ATTACH)
nr_attach++;
@@ -182,7 +184,8 @@ static bool pin_measured(const struct measured_set *s, const char *name,
return measured_holds(s, name, hex);
}
-static bool xdp_archive_changed(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)
{
__u8 payload[UPATCH_PAYLOAD_HASH_LEN];
struct upatch_pins pins;
@@ -191,28 +194,34 @@ static bool xdp_archive_changed(const struct measured_set *s, const char *name)
if (upatch_pins_read(name, &pins) || !pins.nr_xdp_progs ||
!pin_measured(s, name, payload))
- return false;
+ return 0;
ret = upatch_archive_verify(name, payload, &u);
if (!ret)
upatch_close(&u);
- return ret == -ESTALE;
+ return ret == -ESTALE ? 1 : ret;
}
-static bool links_lost(const struct measured_set *s, const char *name)
+static int links_lost(const struct measured_set *s, const char *name)
{
__u8 payload[UPATCH_PAYLOAD_HASH_LEN];
char path[PATH_MAX];
+ int ret;
- if (!pin_measured(s, name, payload) ||
- strsprintf(path, sizeof(path), "%s/%s.upatch", UPATCHES_DIR,
+ if (!pin_measured(s, name, payload))
+ return 0;
+ if (strsprintf(path, sizeof(path), "%s/%s.upatch", UPATCHES_DIR,
name) < 0)
- return false;
- return !upatch_links_complete(name, path);
+ return -ENAMETOOLONG;
+ ret = upatch_links_complete(name, path);
+ if (ret == 1)
+ return 0;
+ return !ret || ret == -ESTALE ? 1 : ret;
}
static int walk_pinned(const struct measured_set *s,
- bool (*hit)(const struct measured_set *s, const char *name),
- int (*cb)(const char *name, void *ctx), void *ctx)
+ int (*check)(const struct measured_set *s, const char *name),
+ int (*cb)(const char *name, void *ctx), void *ctx,
+ int *check_err)
{
struct dirent *e;
int found = 0;
@@ -220,14 +229,22 @@ static int walk_pinned(const struct measured_set *s,
DIR *d;
d = opendir(BPFFS_UPATCHES_DIR);
- if (!d)
- return errno == ENOENT ? 0 : -errno;
+ if (!d) {
+ if (errno != ENOENT && !*check_err)
+ *check_err = -errno;
+ return 0;
+ }
while (!ret && (e = readdir(d))) {
char name[UPATCH_NAME_MAX + 1];
+ int result;
if (!strcmp(e->d_name, ".") || !strcmp(e->d_name, "..") ||
- upatch_name_from_bpffs(name, sizeof(name), e->d_name) ||
- !hit(s, name))
+ upatch_name_from_bpffs(name, sizeof(name), e->d_name))
+ continue;
+ result = check(s, name);
+ if (result < 0 && !*check_err)
+ *check_err = result;
+ if (result <= 0)
continue;
found++;
ret = cb(name, ctx);
@@ -238,13 +255,14 @@ static int walk_pinned(const struct measured_set *s,
int upatch_xdp_archives_changed(const struct measured_set *s,
int (*cb)(const char *name, void *ctx),
- void *ctx)
+ void *ctx, int *check_err)
{
- return walk_pinned(s, xdp_archive_changed, cb, ctx);
+ return walk_pinned(s, xdp_archive_changed, cb, ctx, check_err);
}
int upatch_links_lost(const struct measured_set *s,
- int (*cb)(const char *name, void *ctx), void *ctx)
+ int (*cb)(const char *name, void *ctx), void *ctx,
+ int *check_err)
{
- return walk_pinned(s, links_lost, cb, ctx);
+ return walk_pinned(s, links_lost, cb, ctx, check_err);
}
diff --git a/util/upatch_verify.h b/util/upatch_verify.h
index 99b6896d..b5fd9a82 100644
--- a/util/upatch_verify.h
+++ b/util/upatch_verify.h
@@ -26,8 +26,8 @@ int upatch_archive_verify(const char *name,
/*
* 1 when every link the signed metadata of the archive at path implies is
- * pinned for name, 0 when one is missing, or a negative errno when that
- * cannot be told.
+ * pinned for name, 0 when one is missing, -ESTALE when the archive is gone
+ * or unusable, or another negative errno when that cannot be told.
*/
int upatch_links_complete(const char *name, const char *path);
@@ -36,15 +36,16 @@ 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.
+ * number found. The first check that could not run leaves its -errno in
+ * *check_err, unless that already holds one.
*/
int upatch_xdp_archives_changed(const struct measured_set *s,
int (*cb)(const char *name, void *ctx),
- void *ctx);
+ void *ctx, int *check_err);
-/* As upatch_xdp_archives_changed(), for upatches that have lost a link. */
+/* As upatch_xdp_archives_changed(), for a lost link or an unusable archive. */
int upatch_links_lost(const struct measured_set *s,
- int (*cb)(const char *name, void *ctx), void *ctx);
+ int (*cb)(const char *name, void *ctx), void *ctx,
+ int *check_err);
#endif /* SHIRUDO_UTIL_UPATCH_VERIFY_H */