Skip to content

eBPF-based security platform

eventlog: take the register lock on the root of the private bpffs

Daniel Borkmanne879d4832955
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index b2d991c0..3aabc9d8 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -449,7 +449,8 @@ signed config image.
* - ``t6127-proc-substitution``
- Config read through a substituted ``/proc``
* - ``t6128-register-lock``
- - The lock that keeps register and eventlog in step
+ - The lock that keeps register and eventlog in step, the same in a
+ mount namespace of root's own
* - ``t6129-keyring-seal``
- The exact keyring check at ``init``
* - ``t6130-verity-devices``
diff --git a/Documentation/figures/internals-register-events.tex b/Documentation/figures/internals-register-events.tex
index 2f7fcc84..efde0e96 100644
--- a/Documentation/figures/internals-register-events.tex
+++ b/Documentation/figures/internals-register-events.tex
@@ -51,7 +51,7 @@
\node at (10,290) {every later};
\node at (10,305) {command};
\node at (160,388) {upatch\_load, upatch\_unload, tree\_op,
- key\_revoke: extend, then append, under eventlog.lock};
+ key\_revoke: extend, then append, under the register lock};
\end{scope}
\end{tikzpicture}
\end{document}
diff --git a/Documentation/figures/internals-register-lock.tex b/Documentation/figures/internals-register-lock.tex
index 11600b19..c0203e65 100644
--- a/Documentation/figures/internals-register-lock.tex
+++ b/Documentation/figures/internals-register-lock.tex
@@ -2,8 +2,9 @@
% Copyright (c) 2026 Authors of shirudo
%
% The steps of a upatch load, a upatch unload and a revocation's purge
-% of one upatch, the span each holds eventlog.lock, and what a failure or
-% a stop between two steps leaves (internals/measurement-register.rst).
+% of one upatch, the span each holds the register lock, and what a
+% failure or a stop between two steps leaves
+% (internals/measurement-register.rst).
\documentclass[tikz,dvisvgm]{standalone}
\usepackage{shirudo-figure}
@@ -62,7 +63,7 @@
\node[small, note] at (10,206) {bpm remove};
\node[title] at (10,308) {revocation};
\node[small, note] at (10,326) {purge of one upatch};
- \node[small, note] at (128,124) {eventlog.lock held};
+ \node[small, note] at (128,124) {register lock held};
\end{scope}
\figmark{389}{44}{1}
diff --git a/Documentation/images/internals-register-events.svg b/Documentation/images/internals-register-events.svg
index 01a1b469..2155d491 100644
--- a/Documentation/images/internals-register-events.svg
+++ b/Documentation/images/internals-register-events.svg
@@ -1,7 +1,6 @@
-<svg xmlns='http://www.w3.org/2000/svg' width='900.0' height='400.0' viewBox='-72 -72 674.996 299.998' class='fig fig-f-ink' role='img'><!-- Documentation/figures/internals-register-events.tex, sha256 930cc2fb4899a2ecd3c0f38cd4f36db49b3d32793fd016baaafb74a340e72b7c --><style>.fig-f-ink{fill:var(--fig-ink,#171b22)}.fig-s-ink{stroke:var(--fig-ink,#171b22)}.fig-f-muted{fill:var(--fig-muted,#5d6675)}.fig-s-muted{stroke:var(--fig-muted,#5d6675)}.fig-f-line{fill:var(--fig-line,#8a93a0)}.fig-s-line{stroke:var(--fig-line,#8a93a0)}.fig-f-grid{fill:var(--fig-grid,#e2e6eb)}.fig-s-grid{stroke:var(--fig-grid,#e2e6eb)}.fig-f-axis{fill:var(--fig-axis,#c3c9d1)}.fig-s-axis{stroke:var(--fig-axis,#c3c9d1)}.fig-f-accent{fill:var(--fig-accent,#8b1e3f)}.fig-s-accent{stroke:var(--fig-accent,#8b1e3f)}.fig-f-s1{fill:var(--fig-s1,#2a78d6)}.fig-s-s1{stroke:var(--fig-s1,#2a78d6)}.fig-f-s2{fill:var(--fig-s2,#eb6834)}.fig-s-s2{stroke:var(--fig-s2,#eb6834)}.fig-f-s3{fill:var(--fig-s3,#1baf7a)}.fig-s-s3{stroke:var(--fig-s3,#1baf7a)}.fig-f-s4{fill:var(--fig-s4,#eda100)}.fig-s-s4{stroke:var(--fig-s4,#eda100)}.fig-f-free{fill:var(--fig-free,#dde2e8)}.fig-s-free{stroke:var(--fig-free,#dde2e8)}.fig-f-on{fill:var(--fig-on,#ffffff)}.fig-s-on{stroke:var(--fig-on,#ffffff)}@media (prefers-color-scheme:dark){.fig-f-ink{fill:var(--fig-ink,#e4e8ee)}.fig-s-ink{stroke:var(--fig-ink,#e4e8ee)}.fig-f-muted{fill:var(--fig-muted,#9ba5b3)}.fig-s-muted{stroke:var(--fig-muted,#9ba5b3)}.fig-f-line{fill:var(--fig-line,#8a93a0)}.fig-s-line{stroke:var(--fig-line,#8a93a0)}.fig-f-grid{fill:var(--fig-grid,#262d37)}.fig-s-grid{stroke:var(--fig-grid,#262d37)}.fig-f-axis{fill:var(--fig-axis,#39414c)}.fig-s-axis{stroke:var(--fig-axis,#39414c)}.fig-f-accent{fill:var(--fig-accent,#e8899f)}.fig-s-accent{stroke:var(--fig-accent,#e8899f)}.fig-f-s1{fill:var(--fig-s1,#3987e5)}.fig-s-s1{stroke:var(--fig-s1,#3987e5)}.fig-f-s2{fill:var(--fig-s2,#d95926)}.fig-s-s2{stroke:var(--fig-s2,#d95926)}.fig-f-s3{fill:var(--fig-s3,#199e70)}.fig-s-s3{stroke:var(--fig-s3,#199e70)}.fig-f-s4{fill:var(--fig-s4,#c98500)}.fig-s-s4{stroke:var(--fig-s4,#c98500)}.fig-f-free{fill:var(--fig-free,#2f3640)}.fig-s-free{stroke:var(--fig-free,#2f3640)}.fig-f-on{fill:var(--fig-on,#ffffff)}.fig-s-on{stroke:var(--fig-on,#ffffff)}}</style>
+<svg xmlns='http://www.w3.org/2000/svg' width='900.0' height='400.0' viewBox='-72 -72 674.996 299.998' class='fig fig-f-ink' role='img'><!-- Documentation/figures/internals-register-events.tex, sha256 ff7f02c3ca32253ea362cc60836f9176740e4eb1298b0ff48236ee6a25f729db --><style>.fig-f-ink{fill:var(--fig-ink,#171b22)}.fig-s-ink{stroke:var(--fig-ink,#171b22)}.fig-f-muted{fill:var(--fig-muted,#5d6675)}.fig-s-muted{stroke:var(--fig-muted,#5d6675)}.fig-f-line{fill:var(--fig-line,#8a93a0)}.fig-s-line{stroke:var(--fig-line,#8a93a0)}.fig-f-grid{fill:var(--fig-grid,#e2e6eb)}.fig-s-grid{stroke:var(--fig-grid,#e2e6eb)}.fig-f-axis{fill:var(--fig-axis,#c3c9d1)}.fig-s-axis{stroke:var(--fig-axis,#c3c9d1)}.fig-f-accent{fill:var(--fig-accent,#8b1e3f)}.fig-s-accent{stroke:var(--fig-accent,#8b1e3f)}.fig-f-s1{fill:var(--fig-s1,#2a78d6)}.fig-s-s1{stroke:var(--fig-s1,#2a78d6)}.fig-f-s2{fill:var(--fig-s2,#eb6834)}.fig-s-s2{stroke:var(--fig-s2,#eb6834)}.fig-f-s3{fill:var(--fig-s3,#1baf7a)}.fig-s-s3{stroke:var(--fig-s3,#1baf7a)}.fig-f-s4{fill:var(--fig-s4,#eda100)}.fig-s-s4{stroke:var(--fig-s4,#eda100)}.fig-f-free{fill:var(--fig-free,#dde2e8)}.fig-s-free{stroke:var(--fig-free,#dde2e8)}.fig-f-on{fill:var(--fig-on,#ffffff)}.fig-s-on{stroke:var(--fig-on,#ffffff)}@media (prefers-color-scheme:dark){.fig-f-ink{fill:var(--fig-ink,#e4e8ee)}.fig-s-ink{stroke:var(--fig-ink,#e4e8ee)}.fig-f-muted{fill:var(--fig-muted,#9ba5b3)}.fig-s-muted{stroke:var(--fig-muted,#9ba5b3)}.fig-f-line{fill:var(--fig-line,#8a93a0)}.fig-s-line{stroke:var(--fig-line,#8a93a0)}.fig-f-grid{fill:var(--fig-grid,#262d37)}.fig-s-grid{stroke:var(--fig-grid,#262d37)}.fig-f-axis{fill:var(--fig-axis,#39414c)}.fig-s-axis{stroke:var(--fig-axis,#39414c)}.fig-f-accent{fill:var(--fig-accent,#e8899f)}.fig-s-accent{stroke:var(--fig-accent,#e8899f)}.fig-f-s1{fill:var(--fig-s1,#3987e5)}.fig-s-s1{stroke:var(--fig-s1,#3987e5)}.fig-f-s2{fill:var(--fig-s2,#d95926)}.fig-s-s2{stroke:var(--fig-s2,#d95926)}.fig-f-s3{fill:var(--fig-s3,#199e70)}.fig-s-s3{stroke:var(--fig-s3,#199e70)}.fig-f-s4{fill:var(--fig-s4,#c98500)}.fig-s-s4{stroke:var(--fig-s4,#c98500)}.fig-f-free{fill:var(--fig-free,#2f3640)}.fig-s-free{stroke:var(--fig-free,#2f3640)}.fig-f-on{fill:var(--fig-on,#ffffff)}.fig-s-on{stroke:var(--fig-on,#ffffff)}}</style>
<defs>
<use id='internals-register-events-g7-44' href='#internals-register-events-g3-44' transform='scale(.925)'/>
-<use id='internals-register-events-g7-46' href='#internals-register-events-g3-46' transform='scale(.925)'/>
<use id='internals-register-events-g7-58' href='#internals-register-events-g3-58' transform='scale(.925)'/>
<use id='internals-register-events-g7-77' href='#internals-register-events-g3-77' transform='scale(.925)'/>
<use id='internals-register-events-g7-80' href='#internals-register-events-g3-80' transform='scale(.925)'/>
@@ -582,19 +581,21 @@
<use x='240.955' y='-72' href='#internals-register-events-g7-100'/>
<use x='246.32' y='-72' href='#internals-register-events-g7-101'/>
<use x='251.398' y='-72' href='#internals-register-events-g7-114'/>
-<use x='256.976' y='-72' href='#internals-register-events-g7-101'/>
-<use x='261.98' y='-72' href='#internals-register-events-g7-118'/>
-<use x='266.457' y='-72' href='#internals-register-events-g7-101'/>
-<use x='271.535' y='-72' href='#internals-register-events-g7-110'/>
-<use x='276.789' y='-72' href='#internals-register-events-g7-116'/>
-<use x='280.036' y='-72' href='#internals-register-events-g7-108'/>
-<use x='282.552' y='-72' href='#internals-register-events-g7-111'/>
-<use x='287.732' y='-72' href='#internals-register-events-g7-103'/>
-<use x='292.736' y='-72' href='#internals-register-events-g7-46'/>
-<use x='295.252' y='-72' href='#internals-register-events-g7-108'/>
-<use x='297.768' y='-72' href='#internals-register-events-g7-111'/>
-<use x='302.948' y='-72' href='#internals-register-events-g7-99'/>
-<use x='307.601' y='-72' href='#internals-register-events-g7-107'/>
+<use x='256.976' y='-72' href='#internals-register-events-g7-116'/>
+<use x='260.223' y='-72' href='#internals-register-events-g7-104'/>
+<use x='265.477' y='-72' href='#internals-register-events-g7-101'/>
+<use x='272.738' y='-72' href='#internals-register-events-g7-114'/>
+<use x='276.086' y='-72' href='#internals-register-events-g7-101'/>
+<use x='281.165' y='-72' href='#internals-register-events-g7-103'/>
+<use x='286.049' y='-72' href='#internals-register-events-g7-105'/>
+<use x='288.361' y='-72' href='#internals-register-events-g7-115'/>
+<use x='292.801' y='-72' href='#internals-register-events-g7-116'/>
+<use x='296.011' y='-72' href='#internals-register-events-g7-101'/>
+<use x='301.089' y='-72' href='#internals-register-events-g7-114'/>
+<use x='306.667' y='-72' href='#internals-register-events-g7-108'/>
+<use x='309.183' y='-72' href='#internals-register-events-g7-111'/>
+<use x='314.363' y='-72' href='#internals-register-events-g7-99'/>
+<use x='319.016' y='-72' href='#internals-register-events-g7-107'/>
</g>
</g>
</g>
diff --git a/Documentation/images/internals-register-lock.svg b/Documentation/images/internals-register-lock.svg
index dc657c7f..afd3c93a 100644
--- a/Documentation/images/internals-register-lock.svg
+++ b/Documentation/images/internals-register-lock.svg
@@ -1,5 +1,19 @@
-<svg xmlns='http://www.w3.org/2000/svg' width='840.0' height='500.0' viewBox='-72 -72 629.996 374.998' class='fig fig-f-ink' role='img'><!-- Documentation/figures/internals-register-lock.tex, sha256 791f29f5fe47377cac2397aef985f121f16a05187c453d9a23fcbbd72db0434c --><style>.fig-f-ink{fill:var(--fig-ink,#171b22)}.fig-s-ink{stroke:var(--fig-ink,#171b22)}.fig-f-muted{fill:var(--fig-muted,#5d6675)}.fig-s-muted{stroke:var(--fig-muted,#5d6675)}.fig-f-line{fill:var(--fig-line,#8a93a0)}.fig-s-line{stroke:var(--fig-line,#8a93a0)}.fig-f-grid{fill:var(--fig-grid,#e2e6eb)}.fig-s-grid{stroke:var(--fig-grid,#e2e6eb)}.fig-f-axis{fill:var(--fig-axis,#c3c9d1)}.fig-s-axis{stroke:var(--fig-axis,#c3c9d1)}.fig-f-accent{fill:var(--fig-accent,#8b1e3f)}.fig-s-accent{stroke:var(--fig-accent,#8b1e3f)}.fig-f-s1{fill:var(--fig-s1,#2a78d6)}.fig-s-s1{stroke:var(--fig-s1,#2a78d6)}.fig-f-s2{fill:var(--fig-s2,#eb6834)}.fig-s-s2{stroke:var(--fig-s2,#eb6834)}.fig-f-s3{fill:var(--fig-s3,#1baf7a)}.fig-s-s3{stroke:var(--fig-s3,#1baf7a)}.fig-f-s4{fill:var(--fig-s4,#eda100)}.fig-s-s4{stroke:var(--fig-s4,#eda100)}.fig-f-free{fill:var(--fig-free,#dde2e8)}.fig-s-free{stroke:var(--fig-free,#dde2e8)}.fig-f-on{fill:var(--fig-on,#ffffff)}.fig-s-on{stroke:var(--fig-on,#ffffff)}@media (prefers-color-scheme:dark){.fig-f-ink{fill:var(--fig-ink,#e4e8ee)}.fig-s-ink{stroke:var(--fig-ink,#e4e8ee)}.fig-f-muted{fill:var(--fig-muted,#9ba5b3)}.fig-s-muted{stroke:var(--fig-muted,#9ba5b3)}.fig-f-line{fill:var(--fig-line,#8a93a0)}.fig-s-line{stroke:var(--fig-line,#8a93a0)}.fig-f-grid{fill:var(--fig-grid,#262d37)}.fig-s-grid{stroke:var(--fig-grid,#262d37)}.fig-f-axis{fill:var(--fig-axis,#39414c)}.fig-s-axis{stroke:var(--fig-axis,#39414c)}.fig-f-accent{fill:var(--fig-accent,#e8899f)}.fig-s-accent{stroke:var(--fig-accent,#e8899f)}.fig-f-s1{fill:var(--fig-s1,#3987e5)}.fig-s-s1{stroke:var(--fig-s1,#3987e5)}.fig-f-s2{fill:var(--fig-s2,#d95926)}.fig-s-s2{stroke:var(--fig-s2,#d95926)}.fig-f-s3{fill:var(--fig-s3,#199e70)}.fig-s-s3{stroke:var(--fig-s3,#199e70)}.fig-f-s4{fill:var(--fig-s4,#c98500)}.fig-s-s4{stroke:var(--fig-s4,#c98500)}.fig-f-free{fill:var(--fig-free,#2f3640)}.fig-s-free{stroke:var(--fig-free,#2f3640)}.fig-f-on{fill:var(--fig-on,#ffffff)}.fig-s-on{stroke:var(--fig-on,#ffffff)}}</style>
+<svg xmlns='http://www.w3.org/2000/svg' width='840.0' height='500.0' viewBox='-72 -72 629.996 374.998' class='fig fig-f-ink' role='img'><!-- Documentation/figures/internals-register-lock.tex, sha256 506164e682e76b3512111ea5cc1cd89b1d19c1bb773233cc08677cc2b1065d9b --><style>.fig-f-ink{fill:var(--fig-ink,#171b22)}.fig-s-ink{stroke:var(--fig-ink,#171b22)}.fig-f-muted{fill:var(--fig-muted,#5d6675)}.fig-s-muted{stroke:var(--fig-muted,#5d6675)}.fig-f-line{fill:var(--fig-line,#8a93a0)}.fig-s-line{stroke:var(--fig-line,#8a93a0)}.fig-f-grid{fill:var(--fig-grid,#e2e6eb)}.fig-s-grid{stroke:var(--fig-grid,#e2e6eb)}.fig-f-axis{fill:var(--fig-axis,#c3c9d1)}.fig-s-axis{stroke:var(--fig-axis,#c3c9d1)}.fig-f-accent{fill:var(--fig-accent,#8b1e3f)}.fig-s-accent{stroke:var(--fig-accent,#8b1e3f)}.fig-f-s1{fill:var(--fig-s1,#2a78d6)}.fig-s-s1{stroke:var(--fig-s1,#2a78d6)}.fig-f-s2{fill:var(--fig-s2,#eb6834)}.fig-s-s2{stroke:var(--fig-s2,#eb6834)}.fig-f-s3{fill:var(--fig-s3,#1baf7a)}.fig-s-s3{stroke:var(--fig-s3,#1baf7a)}.fig-f-s4{fill:var(--fig-s4,#eda100)}.fig-s-s4{stroke:var(--fig-s4,#eda100)}.fig-f-free{fill:var(--fig-free,#dde2e8)}.fig-s-free{stroke:var(--fig-free,#dde2e8)}.fig-f-on{fill:var(--fig-on,#ffffff)}.fig-s-on{stroke:var(--fig-on,#ffffff)}@media (prefers-color-scheme:dark){.fig-f-ink{fill:var(--fig-ink,#e4e8ee)}.fig-s-ink{stroke:var(--fig-ink,#e4e8ee)}.fig-f-muted{fill:var(--fig-muted,#9ba5b3)}.fig-s-muted{stroke:var(--fig-muted,#9ba5b3)}.fig-f-line{fill:var(--fig-line,#8a93a0)}.fig-s-line{stroke:var(--fig-line,#8a93a0)}.fig-f-grid{fill:var(--fig-grid,#262d37)}.fig-s-grid{stroke:var(--fig-grid,#262d37)}.fig-f-axis{fill:var(--fig-axis,#39414c)}.fig-s-axis{stroke:var(--fig-axis,#39414c)}.fig-f-accent{fill:var(--fig-accent,#e8899f)}.fig-s-accent{stroke:var(--fig-accent,#e8899f)}.fig-f-s1{fill:var(--fig-s1,#3987e5)}.fig-s-s1{stroke:var(--fig-s1,#3987e5)}.fig-f-s2{fill:var(--fig-s2,#d95926)}.fig-s-s2{stroke:var(--fig-s2,#d95926)}.fig-f-s3{fill:var(--fig-s3,#199e70)}.fig-s-s3{stroke:var(--fig-s3,#199e70)}.fig-f-s4{fill:var(--fig-s4,#c98500)}.fig-s-s4{stroke:var(--fig-s4,#c98500)}.fig-f-free{fill:var(--fig-free,#2f3640)}.fig-s-free{stroke:var(--fig-free,#2f3640)}.fig-f-on{fill:var(--fig-on,#ffffff)}.fig-s-on{stroke:var(--fig-on,#ffffff)}}</style>
<defs>
+<use id='internals-register-lock-g3-97' href='#internals-register-lock-g1-97' transform='scale(1.162)'/>
+<use id='internals-register-lock-g3-99' href='#internals-register-lock-g1-99' transform='scale(1.162)'/>
+<use id='internals-register-lock-g3-100' href='#internals-register-lock-g1-100' transform='scale(1.162)'/>
+<use id='internals-register-lock-g3-101' href='#internals-register-lock-g1-101' transform='scale(1.162)'/>
+<use id='internals-register-lock-g3-104' href='#internals-register-lock-g1-104' transform='scale(1.162)'/>
+<use id='internals-register-lock-g3-105' href='#internals-register-lock-g1-105' transform='scale(1.162)'/>
+<use id='internals-register-lock-g3-108' href='#internals-register-lock-g1-108' transform='scale(1.162)'/>
+<use id='internals-register-lock-g3-110' href='#internals-register-lock-g1-110' transform='scale(1.162)'/>
+<use id='internals-register-lock-g3-111' href='#internals-register-lock-g1-111' transform='scale(1.162)'/>
+<use id='internals-register-lock-g3-112' href='#internals-register-lock-g1-112' transform='scale(1.162)'/>
+<use id='internals-register-lock-g3-114' href='#internals-register-lock-g1-114' transform='scale(1.162)'/>
+<use id='internals-register-lock-g3-116' href='#internals-register-lock-g1-116' transform='scale(1.162)'/>
+<use id='internals-register-lock-g3-117' href='#internals-register-lock-g1-117' transform='scale(1.162)'/>
+<use id='internals-register-lock-g3-118' href='#internals-register-lock-g1-118' transform='scale(1.162)'/>
<path id='internals-register-lock-g1-49' d='M5.271 0V-.986H3.797V-6.432H1.963L.369-4.534L1.124-3.898L2.525-5.557H2.608V-.986H.839V0H5.271Z'/>
<path id='internals-register-lock-g1-50' d='M5.032-1.023H1.889L3.244-2.138C4.138-2.875 4.866-3.557 4.866-4.626C4.866-5.732 4.092-6.543 2.737-6.543C1.428-6.543 .737-5.797 .461-4.939L1.511-4.534C1.659-5.059 1.972-5.492 2.636-5.492C3.161-5.492 3.585-5.179 3.585-4.617V-4.497C3.585-3.935 3.271-3.493 2.59-2.894L.571-1.124V0H5.032V-1.023Z'/>
<path id='internals-register-lock-g1-51' d='M1.779-3.834V-2.82H2.414C3.179-2.82 3.612-2.507 3.612-1.917V-1.852C3.612-1.253 3.216-.885 2.507-.885C1.788-.885 1.401-1.253 1.115-1.769L.221-1.087C.627-.461 1.253 .111 2.507 .111C3.926 .111 4.875-.645 4.875-1.779C4.875-2.691 4.276-3.207 3.53-3.345V-3.4C4.202-3.539 4.764-4.036 4.764-4.866C4.764-5.898 3.88-6.543 2.58-6.543C1.493-6.543 .885-6.073 .452-5.474L1.226-4.774C1.539-5.262 1.981-5.548 2.543-5.548C3.124-5.548 3.493-5.225 3.493-4.7V-4.635C3.493-4.175 3.152-3.834 2.414-3.834H1.779Z'/>
@@ -18,20 +32,6 @@
<path id='internals-register-lock-g1-116' d='M2.184 0H3.032V-.94H2.12V-3.87H3.106V-4.81H2.12V-6.128H1.06V-5.308C1.06-4.976 .949-4.81 .599-4.81H.23V-3.87H.94V-1.226C.94-.442 1.373 0 2.184 0Z'/>
<path id='internals-register-lock-g1-117' d='M3.557 0H4.737V-4.81H3.557V-1.631C3.557-1.115 3.087-.866 2.617-.866C2.055-.866 1.806-1.226 1.806-1.889V-4.81H.627V-1.769C.627-.571 1.18 .111 2.166 .111C2.958 .111 3.345-.323 3.511-.802H3.557V0Z'/>
<path id='internals-register-lock-g1-118' d='M3.115 0L4.728-4.81H3.603L2.949-2.737L2.479-1.023H2.414L1.944-2.737L1.272-4.81H.111L1.714 0H3.115Z'/>
-<use id='internals-register-lock-g3-97' href='#internals-register-lock-g1-97' transform='scale(1.162)'/>
-<use id='internals-register-lock-g3-99' href='#internals-register-lock-g1-99' transform='scale(1.162)'/>
-<use id='internals-register-lock-g3-100' href='#internals-register-lock-g1-100' transform='scale(1.162)'/>
-<use id='internals-register-lock-g3-101' href='#internals-register-lock-g1-101' transform='scale(1.162)'/>
-<use id='internals-register-lock-g3-104' href='#internals-register-lock-g1-104' transform='scale(1.162)'/>
-<use id='internals-register-lock-g3-105' href='#internals-register-lock-g1-105' transform='scale(1.162)'/>
-<use id='internals-register-lock-g3-108' href='#internals-register-lock-g1-108' transform='scale(1.162)'/>
-<use id='internals-register-lock-g3-110' href='#internals-register-lock-g1-110' transform='scale(1.162)'/>
-<use id='internals-register-lock-g3-111' href='#internals-register-lock-g1-111' transform='scale(1.162)'/>
-<use id='internals-register-lock-g3-112' href='#internals-register-lock-g1-112' transform='scale(1.162)'/>
-<use id='internals-register-lock-g3-114' href='#internals-register-lock-g1-114' transform='scale(1.162)'/>
-<use id='internals-register-lock-g3-116' href='#internals-register-lock-g1-116' transform='scale(1.162)'/>
-<use id='internals-register-lock-g3-117' href='#internals-register-lock-g1-117' transform='scale(1.162)'/>
-<use id='internals-register-lock-g3-118' href='#internals-register-lock-g1-118' transform='scale(1.162)'/>
<path id='internals-register-lock-g5-39' d='M1.299-6.912C.912-6.912 .737-6.69 .737-6.368V-6.239C.737-5.99 .848-5.806 1.097-5.75C.995-5.317 .774-4.995 .405-4.608H1.023C1.548-5.059 1.862-5.741 1.862-6.239V-6.368C1.862-6.69 1.686-6.912 1.299-6.912Z'/>
<path id='internals-register-lock-g5-44' d='M1.253-1.078C.866-1.078 .691-.857 .691-.534V-.405C.691-.157 .802 .028 1.051 .083C.949 .516 .728 .839 .359 1.226H.977C1.502 .774 1.815 .092 1.815-.405V-.534C1.815-.857 1.64-1.078 1.253-1.078Z'/>
<path id='internals-register-lock-g5-46' d='M1.253 .111C1.64 .111 1.815-.111 1.815-.424V-.544C1.815-.857 1.64-1.078 1.253-1.078S.691-.857 .691-.544V-.424C.691-.111 .866 .111 1.253 .111Z'/>
@@ -610,23 +610,22 @@
<use x='5.311' y='-72' href='#internals-register-lock-g5-104'/>
</g>
<g stroke='none' transform='matrix(1.004 0 0 -1.004 168.629 -165.618)' class='fig-f-muted'>
-<use x='-72' y='-72' href='#internals-register-lock-g5-101'/>
-<use x='-66.996' y='-72' href='#internals-register-lock-g5-118'/>
-<use x='-62.519' y='-72' href='#internals-register-lock-g5-101'/>
-<use x='-57.441' y='-72' href='#internals-register-lock-g5-110'/>
-<use x='-52.187' y='-72' href='#internals-register-lock-g5-116'/>
-<use x='-48.94' y='-72' href='#internals-register-lock-g5-108'/>
-<use x='-46.424' y='-72' href='#internals-register-lock-g5-111'/>
-<use x='-41.244' y='-72' href='#internals-register-lock-g5-103'/>
-<use x='-36.24' y='-72' href='#internals-register-lock-g5-46'/>
-<use x='-33.724' y='-72' href='#internals-register-lock-g5-108'/>
-<use x='-31.208' y='-72' href='#internals-register-lock-g5-111'/>
-<use x='-26.028' y='-72' href='#internals-register-lock-g5-99'/>
-<use x='-21.375' y='-72' href='#internals-register-lock-g5-107'/>
-<use x='-14.317' y='-72' href='#internals-register-lock-g5-104'/>
-<use x='-9.063' y='-72' href='#internals-register-lock-g5-101'/>
-<use x='-3.985' y='-72' href='#internals-register-lock-g5-108'/>
-<use x='-1.469' y='-72' href='#internals-register-lock-g5-100'/>
+<use x='-72' y='-72' href='#internals-register-lock-g5-114'/>
+<use x='-68.652' y='-72' href='#internals-register-lock-g5-101'/>
+<use x='-63.573' y='-72' href='#internals-register-lock-g5-103'/>
+<use x='-58.689' y='-72' href='#internals-register-lock-g5-105'/>
+<use x='-56.377' y='-72' href='#internals-register-lock-g5-115'/>
+<use x='-51.937' y='-72' href='#internals-register-lock-g5-116'/>
+<use x='-48.727' y='-72' href='#internals-register-lock-g5-101'/>
+<use x='-43.649' y='-72' href='#internals-register-lock-g5-114'/>
+<use x='-38.071' y='-72' href='#internals-register-lock-g5-108'/>
+<use x='-35.555' y='-72' href='#internals-register-lock-g5-111'/>
+<use x='-30.375' y='-72' href='#internals-register-lock-g5-99'/>
+<use x='-25.722' y='-72' href='#internals-register-lock-g5-107'/>
+<use x='-18.665' y='-72' href='#internals-register-lock-g5-104'/>
+<use x='-13.411' y='-72' href='#internals-register-lock-g5-101'/>
+<use x='-8.332' y='-72' href='#internals-register-lock-g5-108'/>
+<use x='-5.816' y='-72' href='#internals-register-lock-g5-100'/>
</g>
<g class='fig-f-accent fig-s-accent'>
<path d='M299.241-33.124C299.241-36.658 296.376-39.522 292.842-39.522S286.443-36.658 286.443-33.124S289.308-26.725 292.842-26.725S299.241-29.59 299.241-33.124ZM292.842-33.124' stroke='none'/>
diff --git a/Documentation/internals/measurement-register.rst b/Documentation/internals/measurement-register.rst
index 2051bc59..e799f59d 100644
--- a/Documentation/internals/measurement-register.rst
+++ b/Documentation/internals/measurement-register.rst
@@ -154,7 +154,7 @@ shows the binding and the extensions that follow it.
with the anchor digest and writes the init record to
eventlog.pending. Every later command extends the index with a
tagged event digest and then appends its record to the
- eventlog, under eventlog.lock.
+ eventlog, under the register lock.
Figure 1. Binding the register at boot and extending it later.
@@ -318,8 +318,14 @@ a time extends and appends. Two measuring commands that each held a lock
of their own could interleave extend, extend, append, append, and leave a
log that replays the events in the other order. Every measuring command,
a upatch load or unload, a live revocation and a tree operation,
-therefore holds ``/var/lib/shirudo/eventlog.lock`` at least from its
-extension to its append. Figure 3 shows the three that change the
+therefore holds the register lock at least from its extension to its
+append: an ``flock`` on the root of the private bpffs,
+``/run/shirudo/bpffs``. That directory is the same inode in every mount
+namespace, and root can neither mount over it nor add an entry to it,
+where a lock file beside the eventlog is root's to cover with another
+labeled inode in a namespace of its own. A command opens the directory,
+reads the identity record pinned in it and checks that the directory
+lies on the device the record names before it locks. Figure 3 shows the three that change the
loaded set, which hold it longer, the order of their steps and what a
failure or a stop between two of them leaves.
@@ -338,7 +344,7 @@ failure or a stop between two of them leaves.
leaves pins the next command removes.
Figure 3. The steps of a load, an unload and a purge, the span each
- holds ``eventlog.lock``, and what an interruption leaves.
+ holds the register lock, and what an interruption leaves.
A load changes the target before it measures, and an unload or a purge
measures before it changes it. A load that fails before its event can
diff --git a/Documentation/internals/signed-loader.rst b/Documentation/internals/signed-loader.rst
index 79150103..240672ba 100644
--- a/Documentation/internals/signed-loader.rst
+++ b/Documentation/internals/signed-loader.rst
@@ -114,7 +114,7 @@ made inside the test run, reach it with ``kernel`` true.
- The kernel ABI check passes, the ``.bpf`` keyring serial equals
the frozen identity record, and ``lsm_link`` is pinned. With
``--expect-chain``, the register equals the given value.
- * - take ``eventlog.lock``, undo
+ * - take the register lock, undo
- The register lock is held from here to the append. The undo pass
removes pins and archives this boot's records do not cover, and
refuses when the records do not fold to the register.
diff --git a/Documentation/reference/cli/upatch-load.rst b/Documentation/reference/cli/upatch-load.rst
index 4446f45a..bb393064 100644
--- a/Documentation/reference/cli/upatch-load.rst
+++ b/Documentation/reference/cli/upatch-load.rst
@@ -46,8 +46,8 @@ Description
message ``chain_drift``).
#. It refuses when the eventlog would exceed ``eventlog.max_bytes``
(``eventlog_full``).
-#. It takes the register lock, ``/var/lib/shirudo/eventlog.lock``, which
- it holds to the end, and undoes the pins and archives this boot's
+#. It takes the register lock, an ``flock`` on the root of the private
+ bpffs, ``/run/shirudo/bpffs``, which it holds to the end, and undoes the pins and archives this boot's
records do not cover: those of a load stopped before its extend, of
an unload stopped after it, and an archive brought back after its
unload, which ``status`` reports under ``UpatchesMeasured``. It takes
diff --git a/Documentation/reference/environment.rst b/Documentation/reference/environment.rst
index 78d9b629..4ddb05ea 100644
--- a/Documentation/reference/environment.rst
+++ b/Documentation/reference/environment.rst
@@ -37,7 +37,9 @@ forbidden`` and fails with ``EPERM`` and exit status 1.
- TPM owner password in place of ``tpm.owner_auth``, as a literal
or ``hex:<even number of hex digits>``.
* - ``SHIRUDO_EVENTLOG_PATH``
- - Eventlog path in place of ``/var/lib/shirudo/eventlog``.
+ - Eventlog path in place of ``/var/lib/shirudo/eventlog``. The
+ register lock is then a file beside it, ``<path>.lock``, in place
+ of the root of the private bpffs.
* - ``SHIRUDO_EVENTLOG_PENDING_PATH``
- Pending eventlog record in place of
``/run/shirudo/eventlog.pending``.
diff --git a/Documentation/reference/eventlog.rst b/Documentation/reference/eventlog.rst
index b825fa45..3cfd6374 100644
--- a/Documentation/reference/eventlog.rst
+++ b/Documentation/reference/eventlog.rst
@@ -32,11 +32,14 @@ Files
- The ``init`` record that ``shirudo init`` writes while it runs
from the initrd. Readers treat it as the end of the eventlog
until it is adopted.
- * - ``/var/lib/shirudo/eventlog.lock``
- - Lock file. upatch loads and unloads, key revocations and tree
- operations hold it from the register extend to the matching
- append, so the register and the log advance in the same order.
- Adopting the pending record also takes it.
+ * - ``/run/shirudo/bpffs``
+ - The register lock, an ``flock`` on the private bpffs's root.
+ upatch loads and unloads, key revocations and tree operations
+ hold it from the register extend to the matching append, so the
+ register and the log advance in the same order. Adopting the
+ pending record also takes it. With ``SHIRUDO_EVENTLOG_PATH`` set,
+ which a host without shirudo's config allows, the lock is a file
+ beside that log, its path with ``.lock`` appended.
``SHIRUDO_EVENTLOG_PATH`` and ``SHIRUDO_EVENTLOG_PENDING_PATH`` override
the two paths for host tests. A target running from a runtime image
diff --git a/Documentation/reference/files.rst b/Documentation/reference/files.rst
index f431d540..150d0d96 100644
--- a/Documentation/reference/files.rst
+++ b/Documentation/reference/files.rst
@@ -133,11 +133,6 @@ the label as foreign. In the initrd, ``init`` binds
- ``0600``
- Append-only eventlog, one JSON record per line. See
:doc:`/reference/eventlog`.
- * - ``eventlog.lock``
- - measuring commands
- - ``0600``
- - Lock held from each register extend to its eventlog append, and
- by a load or an unload from before it touches the pins.
* - ``locks/bpm.lock``
- ``bpm``
- ``0600``
@@ -239,7 +234,10 @@ carries ``/run`` from the initrd into the root file system.
- ``init``
- bpffs
- Private bpffs (``mode=0700``, ``nosuid``, ``nodev``,
- ``noexec``) holding every pin.
+ ``noexec``) holding every pin. Its root is also the register
+ lock: measuring commands ``flock`` it from each register extend to
+ its eventlog append, and a load or an unload from before it
+ touches the pins.
* - ``/run/shirudo/runtime/``
- ``init``
- dm-verity
diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rst
index 55517ee2..08cb64aa 100644
--- a/Documentation/security/threat-model.rst
+++ b/Documentation/security/threat-model.rst
@@ -1064,10 +1064,11 @@ derives every record's digest from its fields and folds them to the
value the TPM reports, and refuses ``tampered`` when they do not fold. A
boot ID that root binds over ``/proc``, or a pending record in a
``/run`` of root's making, which no reader takes since it carries no
-seal label, therefore moves nothing (``t6147``). One lock beside the
-eventlog orders every extend and append and covers the undo, so the
-register and the log advance in one order and the undo never takes a
-load in flight for a stopped one. A failure or a stop between an extend
+seal label, therefore moves nothing (``t6147``). One lock, the root of
+the private bpffs, orders every extend and append and covers the undo,
+in every mount namespace, so the register and the log advance in one
+order and the undo never takes a load in flight for a stopped one
+(``t6128``). A failure or a stop between an extend
and its append leaves the register ahead of the log; shirudo reports
the desync, ``shirudo status`` reports a register its replay cannot
explain, and every later load and unload refuses until the next reboot.
@@ -1817,7 +1818,16 @@ R22 Labeled inodes are interchangeable
content from a registry (``t7002``). This is a reading of
the code and is not reproduced. A bind mount over the state root in
``init``'s namespace, an idmapped one among them, was reproduced:
- every command refuses the state as foreign from then on.
+ every command refuses the state as foreign from then on. The lock
+ that keeps the register in step rests on no label: a lock file
+ beside the eventlog would let a command in root's namespace lock a
+ decoy and undo the pins of a load still in flight in another, which
+ then measures an upatch nothing runs. The register lock is the root
+ of the private bpffs, which takes no mount and no entry from root, so
+ a command in any namespace waits for the same inode (``t6128``). The
+ bpm lock, ``locks/bpm.lock``, still rests on a label: two package or
+ tree commands under a decoy can interleave their own state, while
+ each step they measure still waits for the register lock.
R23 Policy labels follow the inode
A policy label is an xattr of the executable's inode, applied at
diff --git a/Makefile.shirudo b/Makefile.shirudo
index 8cb07356..1b21bcf0 100644
--- a/Makefile.shirudo
+++ b/Makefile.shirudo
@@ -1217,7 +1217,9 @@ $(FUZZ_OUT)/fuzz-attest: FUZZ_LIBS += $(TSS2_LIBS) $(LIBBPF_A) $(LIBELF_LIBS) $(
$(FUZZ_OUT)/fuzz-eventlog: testing/fuzz/fuzz-eventlog.c $(FUZZ_BASE) \
util/eventlog.c util/timefmt.c util/upatch.c \
$(FUZZ_SEAL) util/io.c util/crypto_openssl.c \
- testing/fuzz/chain.c
+ util/identity.c testing/fuzz/chain.c $(LIBBPF_A)
+$(FUZZ_OUT)/fuzz-eventlog: FUZZ_CFLAGS += $(LIBELF_CFLAGS)
+$(FUZZ_OUT)/fuzz-eventlog: FUZZ_LIBS += $(LIBBPF_A) $(LIBELF_LIBS) $(ZLIB_LIBS)
$(FUZZ_OUT)/fuzz-kernel: testing/fuzz/fuzz-kernel.c $(FUZZ_BASE) \
util/kernel_build_id.c
$(FUZZ_OUT)/fuzz-elf: testing/fuzz/fuzz-elf.c $(FUZZ_BASE) \
diff --git a/testing/functional/tamperproof/t6128-register-lock.sh b/testing/functional/tamperproof/t6128-register-lock.sh
index d8f9e747..8ba3aa16 100755
--- a/testing/functional/tamperproof/t6128-register-lock.sh
+++ b/testing/functional/tamperproof/t6128-register-lock.sh
@@ -6,10 +6,12 @@
# process at a time extends and appends, and the lock that serialises
# whole commands is not taken by init, which adopts the initrd's record
# while a command may append. A measuring command must hold the lock
-# beside the eventlog from its extend to its append: with the lock held
-# elsewhere a load waits, and completes with a log that replays to the
-# register. Root may hold the lock and so delay a command, but cannot
-# remove it.
+# from its extend to its append: with the lock held elsewhere a load
+# waits, and completes with a log that replays to the register. The lock
+# is the root of the private bpffs, the same inode in a mount namespace
+# of root's own, where a lock file beside the log could be covered with
+# another labeled inode. Root may hold the lock and so delay a command,
+# but cannot remove or cover it.
cd "$(dirname "$0")/../.."
. ./integration-lib.sh
@@ -21,7 +23,7 @@ NAME=shirudo-test-lifecycle
LOAD="$FIXTURES/$NAME.upatch"
UNLOAD="$FIXTURES/$NAME.unload.upatch"
PIN="/run/shirudo/bpffs/upatches/$NAME"
-LOCK=/var/lib/shirudo/eventlog.lock
+LOCK=/run/shirudo/bpffs
[ -s "$LOAD" ] && [ -s "$UNLOAD" ] || test_skip_all "missing lifecycle fixture"
[ ! -e "$PIN" ] || test_skip_all "$NAME is loaded"
@@ -42,12 +44,10 @@ lines() {
wc -l </var/lib/shirudo/eventlog
}
-test_expect_success 'a measuring command makes the lock beside the eventlog' '
- "$SHIRUDO_BIN" upatch load "$LOAD" --no-precheck >/dev/null 2>&1 &&
- "$SHIRUDO_BIN" upatch unload "$UNLOAD" --no-precheck >/dev/null 2>&1 &&
- [ -f "$LOCK" ] &&
- ! rm -f "$LOCK" 2>/dev/null &&
- [ -f "$LOCK" ]
+test_expect_success 'root can neither remove nor cover the register lock' '
+ ! rmdir "$LOCK" 2>/dev/null &&
+ ! unshare -m mount -t tmpfs tmpfs "$LOCK" 2>/dev/null &&
+ [ -e "$LOCK/identity" ]
'
test_expect_success 'a load waits while the register lock is held and then measures' '
@@ -70,4 +70,18 @@ test_expect_success 'the unload after it leaves the register and the log in step
matches
'
+test_expect_success 'a load in a mount namespace of root'"'"'s own waits for the same lock' '
+ before=$(lines) &&
+ { flock "$LOCK" sleep 4 & holder=$!; } &&
+ sleep 1 &&
+ { unshare -m "$SHIRUDO_BIN" upatch load "$LOAD" --no-precheck \
+ >/dev/null 2>&1 & loader=$!; } &&
+ sleep 2 &&
+ [ "$(lines)" = "$before" ] &&
+ wait "$holder" && wait "$loader" &&
+ [ "$(lines)" -gt "$before" ] &&
+ [ -e "$PIN/link" ] &&
+ matches
+'
+
test_done
diff --git a/util/eventlog.c b/util/eventlog.c
index 827cc3c6..8301e607 100644
--- a/util/eventlog.c
+++ b/util/eventlog.c
@@ -24,6 +24,7 @@
#include "crypto.h"
#include "eventlog.h"
#include "hex.h"
+#include "identity.h"
#include "timefmt.h"
#include "io.h"
#include "json.h"
@@ -326,16 +327,36 @@ static int adopt_pending(void)
* their own interleaved extend, extend, append, append and left a log
* that replays the events in the other order. A load or an unload holds
* this from before it touches the pins to its append, every other
- * measuring path from its extend to its append; it lives beside the log
- * it guards.
+ * measuring path from its extend to its append.
+ *
+ * The lock is the root of the private bpffs, one inode in every mount
+ * namespace. A file beside the log is root's to cover with another
+ * labeled inode in a namespace of its own, where a command would lock
+ * that one and undo the pins of a load still in flight, which then
+ * measures an upatch nothing runs. Only a log the environment names,
+ * which image_enter() allows on a host without shirudo's config alone,
+ * keeps its lock beside it.
*/
int eventlog_lock(void)
{
+ const char *log = eventlog_path();
char path[PATH_MAX];
+ int fd, ret;
- if (strsprintf(path, sizeof(path), "%s.lock", eventlog_path()) < 0)
- return -ENAMETOOLONG;
- return seal_lock(path);
+ if (strcmp(log, EVENTLOG_PATH)) {
+ if (strsprintf(path, sizeof(path), "%s.lock", log) < 0)
+ return -ENAMETOOLONG;
+ return seal_lock(path);
+ }
+ fd = bpffs_root_open();
+ if (fd < 0)
+ return fd;
+ ret = lock_exclusive(fd);
+ if (ret) {
+ close(fd);
+ return ret;
+ }
+ return fd;
}
void eventlog_unlock(int fd)
diff --git a/util/identity.c b/util/identity.c
index f2615b4b..e78f0c1d 100644
--- a/util/identity.c
+++ b/util/identity.c
@@ -9,6 +9,7 @@
#include <fcntl.h>
#include <string.h>
#include <sys/prctl.h>
+#include <sys/stat.h>
#include <unistd.h>
#include <linux/bpf.h>
@@ -19,6 +20,7 @@
#include <shirudo/misc.h>
#include "identity.h"
+#include "io.h"
#include "paths.h"
int enforcement_active(void)
@@ -67,3 +69,30 @@ int identity_read(struct identity *out)
{
return identity_read_at(AT_FDCWD, IDENTITY_PIN, out);
}
+
+/*
+ * Root may mount over /run/shirudo in a mount namespace of its own, but
+ * no mount lands inside the private bpffs and no pin but shirudo's
+ * enters it, so the one directory that holds the identity pin and lies
+ * on the device it records is the bpffs root, reached through any mount.
+ */
+int bpffs_root_open(void)
+{
+ struct identity id;
+ struct stat st;
+ int fd, ret;
+
+ fd = open(BPFFS_DIR, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ if (fd < 0)
+ return -errno;
+ ret = identity_read_at(fd, IDENTITY_PIN_NAME, &id);
+ if (!ret && fstat(fd, &st))
+ ret = -errno;
+ if (!ret && kernel_dev(st.st_dev) != id.sb_dev)
+ ret = -EXDEV;
+ if (ret) {
+ close(fd);
+ return ret;
+ }
+ return fd;
+}
diff --git a/util/identity.h b/util/identity.h
index fc3e712c..07eed494 100644
--- a/util/identity.h
+++ b/util/identity.h
@@ -93,4 +93,11 @@ int enforcement_active(void);
int identity_read(struct identity *out);
int identity_read_at(int dirfd, const char *name, struct identity *out);
+/*
+ * The root of the private bpffs init mounted this boot, as a directory
+ * descriptor. -ENOENT when init has not run, -EXDEV when BPFFS_DIR is
+ * not on that bpffs, another -errno when it cannot be opened or read.
+ */
+int bpffs_root_open(void);
+
#endif /* SHIRUDO_UTIL_IDENTITY_H */