eBPF-based security platform
upatch: remove an unpinned archive only for the directive's payload
Daniel Borkmann3f77e40c5832
diff --git a/Documentation/reference/cli/upatch-unload.rst b/Documentation/reference/cli/upatch-unload.rstindex 783951eb..268baa10 100644--- a/Documentation/reference/cli/upatch-unload.rst+++ b/Documentation/reference/cli/upatch-unload.rst@@ -50,8 +50,10 @@ both in signed sections (see :doc:`build`). ``unload``:directory and compares it with the signed one. A difference, or adigest that cannot be read, is refused with ``payload_mismatch``. Adirective signed with an all-zero digest never matches.-#. When the upatch has no pin, it removes any archive copy, reports- ``already_unloaded`` and exits with 0 without measuring.+#. When the upatch has no pin, it removes the archive copy if it holds+ the directive's payload, reports ``already_unloaded`` and exits with+ 0 without measuring. An archive of another payload stays, and the+ unload is refused with ``payload_mismatch``.#. It extends the register with the ``upatch_unload`` event and appendsit to the eventlog. The event comes first: a failed extend leaves theupatch attached.diff --git a/Documentation/reference/failure-categories.rst b/Documentation/reference/failure-categories.rstindex 1ac20373..b48ae21f 100644--- a/Documentation/reference/failure-categories.rst+++ b/Documentation/reference/failure-categories.rst@@ -238,8 +238,9 @@ Categories- ``pin``- ``EPERM``, errno of the read- The upatch loaded under the name carries another payload than the- directive expects, or the recorded payload cannot be read.- Nothing was detached.+ directive expects, or the recorded payload cannot be read. With+ no pins, the archive of the name holds another payload or cannot+ be read. Nothing was detached or removed.- Compare the ``Payload`` of ``shirudo upatch get <name>`` with thedirective and build a directive for the loaded payload.* - ``detach_failed``@@ -277,7 +278,7 @@ CategoriesA successful operation reports the category ``ok``. An unload of aupatch that has no pins reports ``already_unloaded``, exits 0 and-records no event.+records no event, after removing an archive of the directive's payload.Refusals before a command runs------------------------------diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex dc309693..478d0ca1 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -922,8 +922,9 @@ payload digest recorded on the upatch's pin directory, in the xattr``security.bpf.shirudo.payload`` that only authorized tasks can change(``PinXattr``), with the directive's signed expected payload. It refuses``payload_mismatch`` when they differ or when the xattr cannot be read.-A directive therefore removes the upatch its signer made it for and no-other.+With no pins, it removes the name's archive only when the archive's+bytes are the expected payload. A directive therefore removes the+upatch its signer made it for and no other.The Lua decoders that map export runs with runtime authority ride in asigned section too. Export reads them from the archived artifact onlydiff --git a/builtin-upatch.c b/builtin-upatch.cindex 453ce4b1..24c341bd 100644--- a/builtin-upatch.c+++ b/builtin-upatch.c@@ -3286,10 +3286,29 @@ static int cmd_upatch_unload(int argc, const char **argv)}}+ /*+ * An archive with no pins is one init could not restore, or one an+ * interrupted unload left: the directive removes it only when it is+ * the payload the directive names, as it would its pins.+ */if (!upatch_is_pinned(name)) {- if (unlink(persisted) != 0 && errno != ENOENT)- pr_warn("upatch unload: could not remove %s: %s",- persisted, strerror(errno));+ struct upatch archived;++ err = upatch_archive_verify(name, payload, &archived);+ if (!err) {+ upatch_close(&archived);+ if (unlink(persisted) != 0 && errno != ENOENT)+ pr_warn("upatch unload: could not remove %s: %s",+ persisted, strerror(errno));+ } else if (err != -ESTALE || !access(persisted, F_OK)) {+ pr_err("upatch unload: payload_mismatch, %s is not the "+ "upatch the directive expects; it stays",+ persisted);+ rep_fail(&rep, "pin", "payload_mismatch",+ err == -ESTALE ? EPERM : -err,+ "archived payload does not match directive");+ goto done;+ }pr_info("upatch unload: %s already unloaded (no pin)", name);pr_audit("upatch unload: name=%s already_unloaded", name);rep.ok = true;