eBPF-based security platform
upatch: give a load that meets an occupied XDP device its own category
John Fastabendf42863c042f0
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex 9cd764b8..acff9824 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -207,7 +207,8 @@ signed config image.and the ``virtio_net`` guest adapter at MTU 9000 attach, which only amulti-buffer program can. A veth with too few rx queues, which itsdriver refuses with ``ENOSPC``, fails the load as- ``xdp_driver_refused`` and leaves nothing. Each case cleans up its state+ ``xdp_driver_refused`` and leaves nothing, and an occupied device+ fails it as ``xdp_device_occupied``. Each case cleans up its stateso a failed assertion does not contaminate later cases.* - ``t3112-xdp-reconcile``- ``upatch reconcile`` attaches a device added after load, adds nodiff --git a/Documentation/reference/cli/upatch-load.rst b/Documentation/reference/cli/upatch-load.rstindex 0069b92d..14fb44b9 100644--- a/Documentation/reference/cli/upatch-load.rst+++ b/Documentation/reference/cli/upatch-load.rst@@ -199,7 +199,8 @@ Exit status and failure categories``signature_rejected``, ``signature_unsupported``, ``lsm_denied``,``verifier_rejected``, ``attach_target_missing``, ``binary_mismatch``,``attach_scope_mismatch``, ``xdp_multibuf_unsupported``,-``xdp_driver_refused``, ``tpm_error`` and ``unknown``.+``xdp_driver_refused``, ``xdp_device_occupied``, ``tpm_error`` and+``unknown``.:doc:`/reference/failure-categories` gives the cause and the action foreach. Handle ``tampered`` as an incident(:doc:`/operate/troubleshoot/incident-tampered`).diff --git a/Documentation/reference/failure-categories.rst b/Documentation/reference/failure-categories.rstindex b6d32fd3..444b4c69 100644--- a/Documentation/reference/failure-categories.rst+++ b/Documentation/reference/failure-categories.rst@@ -165,6 +165,16 @@ Categories- Change the setting that rules XDP out, which ``bnxt`` names in thekernel log, or narrow the signed device-class mask. See:doc:`/upatches/write/attach-kinds`.+ * - ``xdp_device_occupied``+ - ``link_create``+ - ``EBUSY``+ - A selected device already runs another XDP program, in any mode:+ another upatch's, or one shirudo did not attach, generic and+ offloaded programs included. The kernel holds one XDP program per+ device. The load was undone.+ - Unload the upatch that holds the device, detach the other+ program, or narrow the signed device-class mask. See+ :doc:`/upatches/write/attach-kinds`.* - ``binary_mismatch``- ``target_verify``, ``link_create``- ``ESTALE``diff --git a/Documentation/upatches/write/attach-kinds.rst b/Documentation/upatches/write/attach-kinds.rstindex 77141583..6977a722 100644--- a/Documentation/upatches/write/attach-kinds.rst+++ b/Documentation/upatches/write/attach-kinds.rst@@ -258,10 +258,10 @@ one upatch must select disjoint classes: ``shirudo build`` refusesupatch that selects a class another upatch of the tree selects on thesame nodes. Two upatches loaded another way can still select the samedevice. While such a device is there, the second one's ``upatch load``-fails. When the device appears after both loaded, reconcile attaches the-first, ``status`` lists the device for the second under ``XdpCovered``-as ``another XDP program attached``, and the next boot restore fails on-it.+fails with ``xdp_device_occupied``. When the device appears after both+loaded, reconcile attaches the first, ``status`` lists the device for+the second under ``XdpCovered`` as ``another XDP program attached``, and+the next boot restore fails on it... list-table:::header-rows: 1diff --git a/builtin-upatch.c b/builtin-upatch.cindex bd788a6f..c6a266ed 100644--- a/builtin-upatch.c+++ b/builtin-upatch.c@@ -2300,6 +2300,8 @@ static int __upatch_apply(const char *path, bool verify_only,cat = "xdp_multibuf_unsupported";else if (ret == XDP_ERR_DRIVER_SETTINGS)cat = "xdp_driver_refused";+ else if (ret == XDP_ERR_OCCUPIED)+ cat = "xdp_device_occupied";else if (ret == XDP_ERR_LINK_SCOPE || ret == -EXDEV)cat = "attach_scope_mismatch";else if (ret > 0)diff --git a/testing/functional/upatch/t3111-xdp.sh b/testing/functional/upatch/t3111-xdp.shindex 02d76b1c..272a81d8 100644--- a/testing/functional/upatch/t3111-xdp.sh+++ b/testing/functional/upatch/t3111-xdp.sh@@ -165,7 +165,9 @@ test_xdp_success 'a later occupied device rolls back earlier successful links' 'load "$CONFLICT" &&ip link add xdpa index 30000 type veth peer name xdpc index 30001 &&ip link set xdpa up && ip link set xdpc up &&- ! load "$NAME" &&+ category=$("$SHIRUDO_BIN" upatch load "$FIXTURES/$NAME.upatch" \+ --no-precheck --report=- 2>/dev/null | report_field category) &&+ [ "$category" = xdp_device_occupied ] &&[ ! -e "$B/$NAME" ] &&[ "$("$H" query xdpa)" = 0 ] &&[ "$("$H" query xdph0)" -gt 0 ] &&diff --git a/util/report.h b/util/report.hindex 031c8d18..19ddb79f 100644--- a/util/report.h+++ b/util/report.h@@ -23,7 +23,7 @@* signature_rejected, verifier_rejected, parser_rejected,* payload_mismatch, already_loaded, already_unloaded, detach_failed,* tpm_error, not_initialized, xdp_multibuf_unsupported,- * xdp_driver_refused, unknown.+ * xdp_driver_refused, xdp_device_occupied, unknown.*/struct op_report {bool ok;