Skip to content

eBPF-based security platform

xdp: do not count a device that could not be asked as covered

John Fastabendb7e9496c22cf
diff --git a/Documentation/operate/run/read-status.rst b/Documentation/operate/run/read-status.rst
index 40dfb441..9873bf9d 100644
--- a/Documentation/operate/run/read-status.rst
+++ b/Documentation/operate/run/read-status.rst
@@ -264,7 +264,8 @@ verdict is derived from them.
moving namespace, for up to a minute. 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.
+ checked: <error>`` means the check could not run, or could not ask
+ a device what it runs; such a device may be unfiltered.
* - ``ConfigActive``
- The config PCR, the activation records and the mounted config
image agree. ``WARN`` ``the activation of config <root>.. is
diff --git a/builtin-upatch.c b/builtin-upatch.c
index 34dfc58d..8baf7c7a 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -4458,10 +4458,15 @@ static int reconcile_walk(const struct xdp_work *w,
struct reconcile_pass pass = {
.name = w->name, .next = next, .needed = needed, .rep = rep,
};
- int ret;
+ int ret, query_err;
ret = upatch_xdp_each_uncovered(w->name, w->specs, w->u.hdr.nr_progs,
- devices, count, reconcile_device, &pass);
+ devices, count, reconcile_device, &pass,
+ &query_err);
+ /* The device is tried again next pass; status reports the gap meanwhile. */
+ if (query_err && next)
+ pr_warn("XDP: upatch %s: cannot ask a device what it runs: %s",
+ w->name, strerror(-query_err));
if (ret >= 0)
return ret;
if (!next) {
diff --git a/util/upatch_verify.c b/util/upatch_verify.c
index 631c67a7..4e616566 100644
--- a/util/upatch_verify.c
+++ b/util/upatch_verify.c
@@ -215,10 +215,11 @@ int upatch_xdp_each_uncovered(const char *name, const struct prog_spec *specs,
int (*cb)(int prog_fd, const struct prog_spec *spec,
const struct xdp_device *dev,
__u32 attached, void *ctx),
- void *ctx)
+ void *ctx, int *query_err)
{
__u32 i;
+ *query_err = 0;
for (i = 0; i < nr_progs; i++) {
__u32 prog_id = 0;
size_t j;
@@ -233,12 +234,17 @@ int upatch_xdp_each_uncovered(const char *name, const struct prog_spec *specs,
__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) ==
+ specs[i].device_classes))
+ continue;
+ ret = bpf_xdp_query_id((int)devices[j].ifindex,
+ XDP_FLAGS_DRV_MODE, &attached);
+ if (ret) {
+ if (!*query_err)
+ *query_err = ret;
+ continue;
+ }
+ if (xdp_reconcile_action(true, attached, prog_id) ==
XDP_RECONCILE_COVERED)
continue;
ret = cb(fd, &specs[i], &devices[j], attached, ctx);
@@ -383,8 +389,13 @@ static int note_uncovered(int prog_fd, const struct prog_spec *spec,
__u64 features = 0;
int err = 0;
- if (!attached)
+ if (!attached) {
+ err = xdp_device_verify(dev);
+ /* bpf_xdp_query() finds nothing, not an error, for a gone device. */
+ if (err == -ENODEV || err == -EXDEV)
+ return 0;
err = xdp_device_features(dev->ifindex, &features);
+ }
w->found++;
return w->cb(w->name, dev->name,
xdp_uncovered_reason(attached, err, features), w->ctx);
@@ -399,7 +410,7 @@ static int xdp_uncovered(const struct measured_set *s, const char *name,
struct prog_spec *specs = NULL;
struct upatch_pins pins;
struct upatch u;
- int ret;
+ int ret, query_err = 0;
if (upatch_pins_read(name, &pins) || !pins.nr_xdp_progs ||
!upatch_pin_measured(s, name, payload))
@@ -415,11 +426,12 @@ static int xdp_uncovered(const struct measured_set *s, const char *name,
w->name = name;
ret = upatch_xdp_each_uncovered(name, specs, u.hdr.nr_progs,
w->devices, w->count,
- note_uncovered, w);
+ note_uncovered, w, &query_err);
}
prog_specs_free(specs, u.hdr.nr_progs);
upatch_close(&u);
- return min(ret, 0);
+ /* A device that could not be asked may run nothing: say so. */
+ return ret < 0 ? ret : query_err;
}
int upatch_xdp_uncovered(const struct measured_set *s,
diff --git a/util/upatch_verify.h b/util/upatch_verify.h
index 8a250944..95a4dd9d 100644
--- a/util/upatch_verify.h
+++ b/util/upatch_verify.h
@@ -51,7 +51,8 @@ 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.
+ * be opened ends it with its -errno. A device that cannot be asked what it
+ * runs is passed over and the first such -errno left in *query_err.
*/
int upatch_xdp_each_uncovered(const char *name, const struct prog_spec *specs,
__u32 nr_progs, const struct xdp_device *devices,
@@ -59,7 +60,7 @@ int upatch_xdp_each_uncovered(const char *name, const struct prog_spec *specs,
int (*cb)(int prog_fd, const struct prog_spec *spec,
const struct xdp_device *dev,
__u32 attached, void *ctx),
- void *ctx);
+ void *ctx, int *query_err);
struct measured_set;