Skip to content

eBPF-based security platform

backend: fail check 4 for a window at seq 0 that starts elsewhere

John Fastabend365bbfcd88f4
diff --git a/Documentation/operate/backend/status.rst b/Documentation/operate/backend/status.rst
index bb592ec9..2dcb6c14 100644
--- a/Documentation/operate/backend/status.rst
+++ b/Documentation/operate/backend/status.rst
@@ -259,6 +259,9 @@ digest. It passes when all of these hold:
``tree_ops``;
- ``base_seq``, ``last_seq``, ``base_root`` and ``projection_root`` are
present and well formed;
+- when ``base_seq`` is 0, ``base_root`` is the zero root every tree
+ starts from: the history is folded from it, so a window that starts
+ anywhere else at seq 0 would pass with nothing stored for it;
- when ``base_seq`` is above 0, ``base_root`` is the root the node's
history has at ``base_seq``, see `Gaps`_;
- at every operation of the window the history reaches, the code and the
diff --git a/tools/backend/sql/40-status.sql b/tools/backend/sql/40-status.sql
index 4e7d3465..087a877a 100644
--- a/tools/backend/sql/40-status.sql
+++ b/tools/backend/sql/40-status.sql
@@ -441,8 +441,12 @@ WITH
ifNull(l.base_root, '') AS p_root,
ifNull(l.mask, '') AS p_mask,
ifNull(l.config_root, '') AS p_config,
+ -- A tree starts from the zero root: node_ops_mv folds a
+ -- window at seq 0 from it, whatever base_root the record
+ -- names, so another one there has no history to agree with.
l.base_seq IS NOT NULL AND l.last_seq IS NOT NULL AND p_last >= p_base
AND match(p_root, '^[0-9a-f]{64}$')
+ AND (p_base > 0 OR p_root = repeat('0', 64))
AND match(ifNull(l.projection_root, ''), '^[0-9a-f]{64}$') AS well_formed,
-- The pairs up to last_seq: what peers at the same point
-- of a tree have in common, whatever head each has seen.
diff --git a/tools/backend/test/status-chain.expected b/tools/backend/test/status-chain.expected
index bd8a7e6f..22b3f149 100644
--- a/tools/backend/test/status-chain.expected
+++ b/tools/backend/test/status-chain.expected
@@ -3,6 +3,7 @@ applied-too healthy 0 4 chain: pass, root 15452248 6 set: pass, 1 loaded
module-missing healthy 0 4 chain: pass, root 15452248 6 set: pass, 0 loaded
passed-over healthy 0 4 chain: pass, root 00000000 6 set: pass, 0 loaded
no-mask unhealthy 3 4 chain: no mask 6 set: no mask
+base-root-at-seq-0 unhealthy 4 4 chain: FAIL, root 086d7c7b 6 set: FAIL drift, 1 loaded
mask-not-base64 unhealthy 4 4 chain: FAIL, root 15452248 6 set: FAIL drift, 1 loaded
no-last-seq unhealthy 4 4 chain: FAIL, root 15452248 6 set: FAIL drift, 1 loaded
past-the-head unhealthy 4 4 chain: FAIL, root 15452248 6 set: pass, 1 loaded
diff --git a/tools/backend/test/status-chain.sql b/tools/backend/test/status-chain.sql
index fb545633..3d8fb876 100644
--- a/tools/backend/test/status-chain.sql
+++ b/tools/backend/test/status-chain.sql
@@ -4,7 +4,10 @@
-- Check 4 folds the operations a mask marks as chained from base_root and
-- holds the result against projection_root. A mask that contradicts the
-- root, one that leaves an operation up to last_seq unreached and a record
--- whose tree keys cannot be read fail it; a mask with an operation whose
+-- whose tree keys cannot be read fail it, and so does a window at seq 0
+-- that starts from another root than the zero one, though its mask folds
+-- from that root to its projection_root: the history, which starts every
+-- tree from zero, would never hold it; a mask with an operation whose
-- attach module was missing chains it and loads nothing; that node runs
-- another kernel, so it is nobody's peer here. A record without
-- a mask on a node that follows a tree fails check 3 by its flag, and
@@ -43,6 +46,7 @@ FROM
('no-mask', 'node-a-1.1.0', [('"flags":0', '"flags":4'), ('"base_root":"0000000000000000000000000000000000000000000000000000000000000000"', '"base_root":null'), ('"mask":"VA=="', '"mask":null')]),
('mask-not-base64', 'node-a-1.1.0', [('"mask":"VA=="', '"mask":"!!!!"')]),
('root-too-long', 'node-a-1.1.0', [('"base_root":"0000', '"base_root":"00000000')]),
+ ('base-root-at-seq-0', 'node-a-1.1.0', [('"base_root":"0000000000000000000000000000000000000000000000000000000000000000"', '"base_root":"1111111111111111111111111111111111111111111111111111111111111111"'), ('"projection_root":"154522480ff8884daa95589e80f26f20248bbf9c192dfbb3cee04e03b4f136a1"', '"projection_root":"086d7c7b43990572ed048a537f0864ff1e81ed81e693e66e75f30916abefe6f5"')]),
('root-not-hex', 'node-a-1.1.0', [('"projection_root":"1545', '"projection_root":"zzzz')]),
('no-last-seq', 'node-a-1.1.0', [('"last_seq":3', '"last_seq":null')]),
('past-the-head', 'node-a-1.1.0', [('"last_seq":3', '"last_seq":9')])