Skip to content

fork-kit/update-policy: daily exposure check: KEV, distro security data, EPSS (#1045 part 3) - #1053

Merged
scuttletoby merged 3 commits into
mainfrom
fork/1045-exposure-check
Nov 23, 2026
Merged

scuttletoby merged 3 commits into
mainfrom
fork/1045-exposure-check

Conversation

@scuttletoby

@scuttletoby scuttletoby commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Part of #1045, part 3 (with part 6's "a security update pending more than 3 days" alert). Follows #1051 (PR A), in the same kit.

What it does

update-policy exposure is a daily check (update-policy-exposure.timer, off unless exposure.enabled). It checks the installed packages and the running kernel against three sources: the distribution's OVAL file, CISA's KEV list, and FIRST.org's daily EPSS file. It prints only what needs action, sends it through the kit's alertCommand (event exposure), and exits 1 on any line.

The lines it can print:

  • KEV CVE-… is exploited in the wild: SOURCE VERSION (PKGS): update to FIXED: one line per CVE. A kernel line says and restart. A fix that needs Ubuntu Pro (esm) says so.
  • KEV CVE-… … has no fix yet: mitigate or watch.
  • security fix waiting N day(s): SOURCE …: one line per source package. It is shown when a CVE's EPSS is ≥ epssMin, or the fix has waited longer than fixWaitingDays. The days count per (CVE, package) from first sight; a newer fix does not reset them, and neither does a run without data.
  • cannot check: … and drift: …: never an all-clear.
  • kernel: not checked (why): a note, not a finding. It appears in every report where the running kernel could not be judged.

Ranking is KEV first, then EPSS. At most 40 lines are printed; the rest are counted on the last line and kept in the report.

Kernel

  • Ubuntu: the OVAL file's running-kernel tests (each flavour's release pattern and its fixed version) are compared with uname -r. The flavour comes from the source package of the running kernel's linux-modules-<release>.
  • Debian: the running linux-image-<release> is matched as source linux.
  • Other installed kernels, headers or modules never give lines.

Debian: a "less than 0:0" state is read as no fix yet, so its KEV no-fix lines fire.

Privacy: EPSS comes from the daily bulk file, so no list of this machine's CVEs is sent anywhere. Only the OVAL URL names the release codename.

Strict reading. These are all "cannot check", and the good copy stays:

  • an unknown test kind, state operation, missing object/state/variable, or unknown section;
  • fewer than 90% of package tests resolving;
  • fewer entries than a floor (OVAL 1,000, KEV 500, EPSS 100,000);
  • under half of the kept copy's entries.

Memory: the decompressed size is capped while streaming (maxXmlMb), and finished entries are dropped. One entry is capped at 500k elements. The unit has MemoryHigh=768M, MemoryMax=1G, and low CPU and IO weights. Live on noble: about 10 s and about 350 MB.

Feeds:

  • downloaded at most once a day, with a size cap, a timeout, ETag, and a sha256 of the kept copy;
  • https only: a redirect to http is refused;
  • temporary files left by a killed run are swept at the start, under a cache lock.

Privileges: the check runs as a systemd DynamicUser. Only the alert step (ExecStopPost=+) runs as root. Running it by hand as root on the unit's cache is refused; the README points to systemctl start update-policy-exposure.service.

dpkg states: installed, held, and half-installed/unpacked/half-configured/triggers states count. An unknown status is "cannot check".

Other package systems: rpm and apk fit in as one more ECOSYSTEMS entry.

State question

  • Runs again: the same day there is no download, and the lines are the same. The next day only a changed feed is downloaded (ETag/304). A second run at the same time finds the cache lock held and does nothing.
  • Stops half-way:
    • Downloads, meta, state and report are each written to a temporary file and renamed.
    • A SIGTERM or timeout runs no cleanup, so the next run first removes the temporary files a killed run left.
    • A stop between a copy and its meta leaves a copy that does not match its sha256. That is no copy, so "cannot check" until the next download: it fails closed.
  • Old or empty cache:
    • No copy gives "cannot check".
    • A broken meta or state starts again from empty (a waiting fix is then dated from today).
    • A run without usable data keeps the waiting clock as it was.
    • A copy older than staleDays is still read and is reported as drift.
  • Feed format change: a whole-file or partial change, or a feed far smaller than before, gives "cannot check" naming the feed, and the old copy stays.
  • Alert step: a report that is missing, broken, older than 6 h, or a link is itself one "cannot check" line. A report with only notes sends no alert.

General vs project

  • General (this PR, fork kit): the check, the feed cache, the OVAL reader, version order, the ranking and the alert hook. No machine facts; the README and machine.example.json use placeholders.
  • Project config (/etc/fork-kit/machine.json → update-policy.exposure): on/off, epssMin, fixWaitingDays, staleDays, maxFeedMb, timeoutSeconds, optional feed URLs, and the ignore list (CVE, reason, until date). Which machines run it is the owner's rollout.

Registered

fork-kit/README.md row, machine.example.json, .github/fork-ci-tests.txt (exposure.test.py). The installer now covers the two new units and the new modules, and uninstall removes the cache. No upstream file changed.

Tests

fork-kit/update-policy/tests/exposure.test.py runs on recorded cuts of the real feeds in tests/fixtures/:

Network is replaced by a fake web, and the clock is fixed.

Each round-1 finding has a test that fails on the previous head (39 of the new tests fail there), plus a red-check mutation per rule. They cover:

  • a partial format change (state operation, renamed object, test kind, variable, unknown section, kernel operation, a missing object);
  • the bz2 bomb and the entry cap;
  • the floors;
  • kernel by flavour, ambiguous and unknown kernels, Debian's image, old kernel packages;
  • 0:0;
  • the waiting clock across a run without data and a newer fix;
  • one line per source with its highest fix, and the line cap;
  • dpkg hi/iU/iF/iH/iW/it, removed, and unknown states;
  • the temporary-file sweep and lock;
  • refusing a redirect to http;
  • server text escaped;
  • the root guard.

Local: all kit tests and the installer contract pass, plus fork-ci-release.test.py, vp run check:changed, and gitleaks.

Not installed on any machine.

🤖 Generated with Claude Code

…ta, EPSS (#1045 part 3)

update-policy exposure compares the installed packages (dpkg) with the
distribution's OVAL file (Ubuntu's CVE OVAL, Debian's OVAL), CISA's KEV list and
EPSS (FIRST.org API, only for the CVEs found) and prints only what needs action:
- KEV CVE with a fixed version out: update;
- KEV CVE with no fix: mitigate or watch;
- a security fix waiting, shown when KEV, EPSS >= epssMin or waiting longer
  than fixWaitingDays; ranked KEV first, then EPSS;
- cannot check (a feed down or not understood, no data source, dpkg failing,
  EPSS down), never all clear; drift (a cache older than staleDays, an ignore
  entry past its date).
Feeds are fetched at most once a day with a size cap, timeout, ETag and a
sha256 of the stored copy; a download the reader does not understand never
replaces the good copy. The unit runs it as a DynamicUser with its own cache
folder; only the alert step (ExecStopPost=+) runs as root. machine.json:
update-policy.exposure (off by default), ignore list with reason and date.
Ecosystems table for rpm/apk later. Tests on recorded cuts of the real feeds,
no network.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: state · reviewer: Claude Code (review sub-agent) · read at: ea4e1ce

major: a partial feed format change still reads as all clear. oval.read only refuses a file with no definitions or no dpkginfo tests; if objects, variables or states change shape, every test resolves to nothing and the check prints nothing and exits 0. Reproduced on the noble fixture (see block 1). KEV is the same: one valid entry is enough to replace a good copy. Fix: FormatError when too few dpkginfo tests resolve to names plus a readable state (say under 90 %), or none do. Also refuse a download whose advisory/KEV count falls far below the kept copy's (count in the meta).
major: the kernel is never checked, and the output never says so. On today's real noble OVAL the reader keeps 26,127 advisories and none has a linux kernel source or a linux-image binary: kernel CVEs use the 60 uname_test and 236 variable_test entries, which are skipped. On Debian the images come from the linux-signed-amd64 source, but the OVAL names linux, so only linux-headers and linux-libc-dev can match. KEV lists many kernel CVEs, and an un-updated kernel gives exit 0. The PR body calls this a known limit, but the report and the alert read as all clear. Fix: read Ubuntu's kernel tests against the running kernel (uname -r against the variable_test version), and map linux-signed-* to linux on Debian. At the least, add a standing "not checked: kernel" note to the report, separate from the action lines.
major: on Debian, a CVE with no fix yet can never show. Debian writes it as evr "less than 0:0" (3,838 tests in today's bookworm file, for example CVE-2005-3660 linux, "DPKG is earlier than 0"). The reader treats that as "fixed in 0:0", and nothing sorts below it, so the "KEV ... has no fix yet" line can never fire on Debian. Fix: read 0 / 0:0 as no fix (Debian also uses it for some not-affected entries; if that cannot be told apart, say Debian no-fix KEV is not covered), plus a fixture.
minor: a run killed during a download leaves its temporary file for good. TimeoutStartSec sends SIGTERM, and Python runs no finally on SIGTERM. Reproduced: .oval.XXXX.tmp stays in the cache with a unique name each time, up to maxFeedMb (max 1024). Sweep old .*.tmp files at start.
minor: decompressed size has no bound. maxFeedMb caps only the compressed bytes: a 681-byte bz2 expands to 12 MB of XML and 284 MB RSS (iterparse keeps every element under the root). The unit has no MemoryMax. Add MemoryMax=/MemoryHigh= (around 1G; a real feed peaks at 236 MB) and/or cap the decompressed bytes.
minor: the fix-waiting clock is keyed on the binary plus the newest fixed version. A newer fix resets the days to 0, so a held package that gets fixes often never passes fixWaitingDays (part 6: "pending more than 3 days"). Key on the binary plus the installed version.
minor: dpkg states iU, iF and iH (half-installed, failed upgrade) are skipped, so those packages, whose files are on disk, go unchecked without a word. Mutants that drop "hi" or the "keep the highest fixed" line leave every test green.
minor: urllib follows a redirect from https to http; refuse a redirect that is not https. EPSS: the CVE ids sent are exactly this machine's unfixed CVEs, tied to its IP. The daily bulk EPSS CSV (about 2 MB) would send nothing. The owner decides.

# 1: format change -> silence (noble fixture through oval.read)
original                                   -> 6 advisories (glibc fixed 2.38-1ubuntu6, aide fixed ...)
dpkginfo_object renamed                    -> []                       (check: no lines, exit 0)
operation="less than or equal" on states   -> only the 4 unfixed; every fixed advisory dropped

What held

  • XXE (undefined entity) and billion laughs (expat 2.6 amplification limit) both end as FormatError, which gives a cannot check line.
  • A truncated bz2 or an HTML error page is not understood and the old copy stays.
  • A sha256 mismatch counts as no copy.
  • A content-length above the cap and a stream over the cap are both refused.
  • debver against dpkg --compare-versions: 3,000 random pairs (epoch, tilde, revisions), 0 mismatches.
  • Privilege: only report.json crosses to the root step. It is opened with O_NOFOLLOW|O_NONBLOCK, read up to 1 MiB, and every line goes through one_line before the alert. The alert command gets the text on stdin.
  • What leaves the machine: only CVE ids, plus the release codename in the OVAL URL.
  • Real feeds: noble takes 6.7 s and 236 MB; bookworm reads 68,943 advisories.
  • Tests: exposure.test.py 30 OK, install.test.py 11 OK.
  • Mutants that remove the stream cap, the sha check, the empty-format guard, the report age check or O_NOFOLLOW each turn tests red.

State question

  • Runs again: the same day there is no download (20 h window). The report lines are the same, except the fix-waiting key resets when a newer fix appears (minor above).
  • Stopped half-way:
    • Data and meta are written to a temporary file and renamed. A stop between the data rename and the meta write gives a sha mismatch, which means no copy, then a fresh download. If the network is down then, the result is cannot check, so it fails closed.
    • A SIGTERM or timeout leaves an orphan .tmp file (minor above).
    • A crash before the report is written leaves yesterday's report, which the root step finds older than 6 h and turns into a cannot check line. That fails closed.
  • Empty cache: no copy plus no network gives cannot check.
  • Old cache: it is still read, and a drift line appears once it is older than staleDays.
  • Broken state or EPSS file: it starts from empty, so a waiting fix is dated from today.
  • Feed format change: a whole-file change is caught. A partial change (objects or states) reads as all clear (major 1).
  • No machine.json: the check prints cannot check and exits 1 without writing a report. The root step returns 1 without an alert (there is no alert command to use). The unit shows as failed.
  • Exposure off: both steps exit 0. The cache stays until uninstall, which removes both cache paths.
  • Release upgrade (new codename): the URL changes, so the old copy counts as no copy and is downloaded again.

Lens state: not safe (3 majors).

🤖 Generated with Claude Code

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: Claude Code (code lens sub-agent) · read at: ea4e1ce

blocker: none
major: a tiny feed can exhaust the host's memory. maxFeedMb caps only the compressed download, and oval.read clears only the elements it knows, so every other element stays attached to the root. I built a 10 KB bz2 of 200 MB of empty unknown elements: RSS went to 4.6 GB in 17 s before the FormatError. The unit has no MemoryMax, so on a live host the OOM killer picks the biggest process, which can be the game server. The real noble file already peaks at about 270 MB. Fix: clear every finished element (or clear the root's children as you go), cap the decompressed bytes in oval._open with a counting reader, and add MemoryMax=/MemoryHigh= (about 1G) to update-policy-exposure.service.
major: a feed that still parses but changed shape reads as all clear. The only guard is "no definitions or no dpkginfo tests". If the state operation is no longer exactly "less than", every fixed advisory is dropped silently. Reproduced on the noble fixture (block 1): 6 advisories become 4, glibc and aide are gone, no FormatError, no cannot-check line. A renamed object or variable child has the same effect. Fix: raise FormatError when few dpkginfo tests resolve to names and a readable state (or none do), and refuse a download whose advisory count falls far below the kept copy's (store the count in the meta).
major: the kernel is never checked, and the output never says so. In today's real noble OVAL, the 60 uname_test and 236 variable_test entries are skipped. None of the 26,127 advisories read has a kernel source, and KEV kernel CVEs (for example CVE-2023-0386 and CVE-2021-22555) are not in them. On Debian the image binaries come from the linux-signed-amd64 source, which the OVAL does not name, so only linux-headers and linux-libc-dev can match. The headers of an old ABI that is still installed then give a "fix waiting" line that updating never clears. A kernel that was never updated (held, Pro-only, apt broken; Livepatch not checked) gives exit 0, and the restart policy only sees a kernel that is installed and waiting for a restart. Fix: read Ubuntu's kernel variable_test (fixed version) against the running kernel (uname -r), map Debian's linux-image-* and linux-signed-* to source linux, and skip images that are installed but not running. At the least, the report should say "kernel: not checked".
major: on Debian the "KEV ... has no fix yet" line can never fire. Debian writes unfixed (and some not-affected) entries as evr "less than 0:0". In today's bookworm file 12,042 advisories have fixed=0:0 and none has None. Nothing installed sorts below 0:0, so they never match, including KEV ones such as CVE-2022-22965 (libspring-java) and the wpewebkit set. Fix: read 0 or 0:0 as "no fixed version" (and tell not-affected from unfixed if the file allows it, or document the gap), with a Debian fixture.
minor: a run killed during a download leaves .NAME.XXXX.tmp in the cache for good (up to maxFeedMb each). TimeoutStartSec=30min sends SIGTERM, Python runs no finally on it, and nothing sweeps these files. Remove old .*.tmp files at start.
minor: the fix-waiting clock (part 6, "pending more than 3 days") restarts in two cases. (a) A run with no usable OVAL copy writes fixSeen={}, so every waiting fix is dated from the next good run. (b) The key is binary plus newest fixed version, so a newer fix resets the days to 0. Keep the state when advisories is None, and key on binary plus installed version.
minor: there is one line per installed binary, not per fix. The glibc KEV on noble lists 10+ binaries, so libc6, libc-bin, libc-dev-bin and the rest each get their own KEV line in the alert. The alert text also has no line-count cap: report.json may hold up to 1 MB of lines. Group by source and cap the lines sent.
minor: the "cannot check: {p}" problem lines are printed to the journal without one_line. They can carry a server's HTTP reason text or an exception text. The alert step escapes them, the journal does not. urllib also follows a redirect from https to http. The README says "Run them as root": run by hand that way, exposure parses the feeds as root and leaves root-owned files in the DynamicUser cache. Document systemctl start update-policy-exposure.service instead.

# 1: noble fixture through oval.read, states edited with sed
original                                   -> 6 advisories: CVE-2023-4911 glibc fixed 2.38-1ubuntu6, CVE-2025-54389 aide fixed 0.18.6-2ubuntu0.1, 2 unfixed
operation="less than or equal"             -> 4 advisories: only the unfixed ones; no FormatError

# 2: bz2 bomb through oval.read (python 3, expat 2.7)
10,293-byte .bz2 -> 200 MB of <x/> under the root -> RSS 75 MB -> 4,665 MB, 17 s, then FormatError "no definitions"

# 3: real feeds today
noble:    26,127 advisories, 4.8 s, ~270 MB peak; tests: dpkginfo 4,005, variable 236, uname 60 (kernel)
bookworm: 68,943 advisories, 2.9 s; fixed=0:0 on 12,042; no linux-signed-* name anywhere in the file

What held

  • XXE: an external entity is not loaded ("undefined entity", FormatError). Billion laughs: expat's amplification limit ends it as a FormatError. Truncated bz2 or XML, HTML in place of the feed, and an empty or changed KEV all give a cannot-check line, and the good copy stays.
  • Version order: debver._part matches dpkg's verrevcmp line by line: ~ before the end, letters before other characters, leading zeros, then the epoch. A fixed version that cannot be parsed skips the advisory silently. Here the dpkg cross-check test skips (no dpkg); it runs where dpkg is installed.
  • Privilege separation is real. The check runs as a DynamicUser with ProtectSystem=strict, and the cache is its only writable place. The only thing that crosses back is report.json. The root step opens it with O_NOFOLLOW|O_NONBLOCK, reads at most 1 MB, re-escapes each line (400 characters) and passes the text on stdin. The machine file is installed 0644 (common README), so the unprivileged reader works.
  • What leaves the machine: the OVAL URL (it names the codename), the KEV GET, and EPSS GETs carrying exactly this machine's waiting or KEV-unfixed CVE ids, tied to its IP. That list is the machine's unpatched inventory. The daily bulk EPSS CSV would send nothing; the owner decides.
  • Tests: exposure.test.py 30 ok (1 skipped: no dpkg), install 11, baseline 20, tick 35, idle 29, all ok on the head.

State question

  • Runs again: the same day there is no download (fetchedAt is less than 20 h old). The OVAL is parsed again (about 5 s, about 270 MB), the lines are the same and fixSeen is kept. The next day a conditional GET is made; a 304 refreshes fetchedAt.
  • Stops half-way: if killed during a download, the old copy stays and the .tmp file is left behind (minor above). If killed between the data rename and the meta write, the new data does not match the old sha256, so it counts as no copy. That is a cannot-check line until the next good download: it fails closed. If the check is killed or times out, the ExecStopPost alert finds yesterday's report (more than 6 h old) and says "missing or broken", so it is not silent.
  • Empty cache: the first run downloads; offline it gives cannot-check lines, never all clear. Old cache: it is still read, with a "download failed" cannot-check line every day plus drift after staleDays. Broken meta, state or EPSS files start again from empty. A feed format change that cannot be parsed keeps the old copy and gives cannot check; one that still parses can give a silent all clear (major above).
  • No machine.json: the check prints cannot check and exits 1 without a report; the alert step returns 1 and sends nothing. Only the journal and the unit's failed state show it, and the baseline check has to catch it. Exposure off: both steps exit 0 and the old cache and report stay until uninstall, which removes both cache paths.

🤖 Generated with Claude Code

…the kernel, bounded memory, no CVE list sent

- OVAL is read strictly: an unknown test kind, state operation, missing object,
  state or variable, an unknown section, or fewer than 90% of package tests
  resolving is a FormatError ("cannot check"), never fewer advisories.
- Feeds have absolute floors and must hold at least half the kept copy's
  entries; otherwise the good copy stays and the run says cannot check.
- Memory: the decompressed size is capped while streaming (maxXmlMb), every
  finished entry and section is dropped, one entry is capped at 500k
  elements, and the unit has MemoryHigh/MemoryMax and low CPU/IO weights.
- Kernel: Ubuntu's running-kernel tests (flavour pattern + fixed version)
  against uname -r, the flavour from linux-modules-<release>; Debian's running
  linux-image as source linux; other installed kernel packages never count;
  what cannot be judged is a "kernel: not checked (why)" note in every report.
- Debian "less than 0:0" is no fix yet (KEV no-fix lines fire).
- EPSS from FIRST.org's daily bulk file: no CVE list leaves the machine.
- Temporary files of a killed run are swept under a cache lock; the waiting
  clock is per (CVE, package) and survives runs without data and newer fixes;
  one line per KEV CVE or source package, capped at 40; every line escaped;
  https only (redirects to http refused); held and half-installed dpkg states
  count, unknown ones are cannot check; refuses to run as root on the unit's
  cache.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: state · reviewer: Claude Code (review sub-agent) · read at: 921cf32

blocker: none
major: none
minor: a broken kernel entry crashes the check instead of giving a cannot-check line. oval.read never compiles the kernel capture pattern and never parses a kernel's fixed version, and run() catches only OSError. Reproduced on the noble fixture (block 1): a re.error or ValueError comes out of check() with a traceback and no report is written. It fails closed only because the alert step finds yesterday's report too old. The kept copy then crashes every day until the feed changes. Fix: compile the capture and run debver.split on the fixed version in _resolve (FormatError keeps the old copy), and have run() write a cannot-check report for any other exception.
minor: the relative floor can hold a feed forever after a real shrink. A download under half the kept count is refused every day, the kept count never moves, and the README gives no way out. 95 % of noble's count is kernel × flavour entries (512,516 of 538,583, 54 flavours), so one cleanup of old flavours could do it. It is loud, not silent: a cannot-check line every day, then drift. The count is also one total, so the package part (26,127 advisories) could fall by 90 % behind a stable kernel part and pass. Fix: give the README the recovery (delete oval.meta.json), or accept a smaller file seen unchanged (same sha) for N days; floor advisories and kernels separately.
minor: the report is written after the lock is released, so a second run's sweep could delete the first run's .report.*.tmp before its rename. The OSError is swallowed and no report is written. In practice only the unit can write this cache (root is refused on it), and systemd never runs the unit twice at once, so this is an edge case.
minor: the waiting clock for the kernel is keyed on the CVE plus "kernel RELEASE". Rebooting into a newer kernel that is still behind restarts its days at 0.
minor: two fix lines are not proven by a test. Replacing w['since'] = min(...) with the last first-sight, and removing the dropping of finished entries in oval.read (stack[-1].remove), both leave all 45 tests green.

# 1: noble fixture, kernel entries edited after oval.read, through exposure.kernel_affected
capture pattern "(["   -> re.error "unterminated character set"   (uncaught in check)
fixed "0:6.8 0"        -> ValueError "not a Debian version"         (uncaught in check)

# 2: real feeds today, through the head's readers
noble:    count 538,583 = 26,127 package advisories + 512,456 kernel entries; 8.2 s; 341 MB, 430 MB with two parses held
          running 6.8.0-31-generic -> 10,295 kernel CVEs (12 on KEV); 6.8.0-90-generic -> 7,492 (newest fix 6.8.0-151)
          a WSL or unknown kernel -> note "kernel: not checked (... none of ubuntu's kernels ...)"
bookworm: 68,943 advisories, 4.0 s;  KEV 1,790 rows;  EPSS 411,399 rows (floors 1,000 / 500 / 100,000: all pass)
round-1 block 1 again: renamed dpkginfo_object and "less than or equal" -> FormatError (was: silent all clear)

Round 1 (this lens and the code lens), on this head

  • round 1, fixed: a partial format change read as all clear. An unknown test kind, state operation, object or variable now raises FormatError, so do package tests under 90 % resolved, and a download under an absolute floor or under half the kept copy is refused. Proved by the format tests plus the floor and far-smaller-download tests; mutants that remove the resolved share, the absolute floor and the relative floor each turn red.
  • round 1, fixed: the kernel was never checked. Ubuntu's uname_test and variable_test are now read against the running release, Debian's running image is matched by the source linux, and old kernel packages give no line. A kernel the check cannot place gives the note "kernel: not checked". The kernel tests cover this; a mutant that removes the KERNEL_PKG skip turns red.
  • round 1, fixed: Debian's "less than 0:0" is now read as no fix, and the README states the not-affected caveat. test_debian_..._0_0_is_no_fix proves it (mutant red).
  • round 1, fixed: temp files left by a killed run are swept under the cache's lock. Proved by the two swept tests (mutants that remove the sweep or the lock turn red).
  • round 1, fixed: memory and decompression. There is now a maxXmlMb cap, a cap of 500k elements per entry, finished entries are dropped, and the unit has MemoryHigh=768M and MemoryMax=1G. A real file peaks at 341 MB. The test for dropping entries is missing (minor above).
  • round 1, fixed: the waiting clock is kept per CVE and binary, a run without data keeps fixSeen (mutant red), and a newer fix no longer resets it. That last point holds in the code but no test proves it (minor above).
  • round 1, fixed: half-installed, unpacked and failed packages count, and an unknown status gives cannot check (test). Redirects are https only (mutant red). EPSS is now the daily bulk file, so no CVE list leaves the machine. Lines are grouped per CVE or per source and capped at 40 lines plus a "+N more" line (mutant red). Journal lines go through one_line. A root run on the unit's cache is refused (test).
  • Tests on this head: exposure 45 OK, install, baseline, tick and idle OK.

State question

  • Runs again:
    • The same day there is no download, the lines are the same and fixSeen is kept. The "+N more" count is computed fresh each run; nothing about it is stored.
    • A second run while one is going finds the lock held, prints that and exits 0 without a report. Its alert step then reads the first run's report.
  • Stops half-way:
    • Every write goes to a temporary file and is renamed whole, and the next run sweeps those files under the lock first. A kill during the sweep only leaves fewer temporary files.
    • A stop between a copy and its meta gives a sha mismatch, so no copy and cannot check until the next download.
    • A kill or timeout leaves no new report, so the alert step says "missing or broken". A crash does the same (first minor).
  • Empty state:
    • No copy means cannot check. A first download still has to pass the absolute floor, so a tiny bad file cannot become the reference. An inflated one (more than twice the real count) could, and would then refuse the real file loudly (second minor).
    • A meta from the previous head has no count, so only the absolute floor applies once.
  • Old or broken state:
    • A broken state.json, or one in the previous head's format (keys "binary fixed"), starts the clocks from today. The kit is not installed anywhere yet, so that costs nothing.
    • A CVE that is gone and then comes back is dated from its return. An ignored CVE gets no clock until its ignore ends.
    • An old copy is still read, with a drift line after staleDays.
  • EPSS: the bulk file goes through the same cache, floors and staleness. If it is down, the result is a cannot-check line, with no ranking from it.
  • Exposure off, then on: off, both steps exit 0 and the cache and state stay. On again, the feeds are downloaded fresh, and a fix that was still waiting keeps its old first sight, which is correct because the fix was out all that time.
  • Uninstall: it removes /var/cache/update-policy-exposure (the link) and private/update-policy-exposure.
  • No machine.json: the check prints cannot check and exits 1 without a report, and the alert step returns 1 silently. The unit shows as failed.

Lens state: safe (no blocker or major open; 5 minors).

🤖 Generated with Claude Code

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: Claude Code (code lens sub-agent, round 2) · read at: 921cf32

blocker: none
major: none
minor: memory headroom is thinner than the unit comment says. oval.read keeps a Kernel entry for every flavour of every kernel CVE: 512k entries on today's noble file, 887k on jammy. Peak RSS here was about 370 MB on noble and about 630 MB on jammy, against MemoryHigh=768M and MemoryMax=1G, while the unit comment says "near 350 MB". Each kernel release grows the list. Past the cap the check is OOM-killed every day and the alert says "report missing", so it fails closed but stays broken. Keep only the kernel entries whose pattern matches the running release (pass uname -r into read), or raise the limits and fix the comment.
minor: a broken kernel entry in the feed crashes the run with a traceback instead of giving cannot check. kernel_affected uses the feed's regex_capture as is: re.error on a bad pattern, IndexError from m.group(1) when it has no group, and ValueError from debver.compare on a malformed fixed version. None of these is caught; run() only catches OSError. It still fails closed, because the alert finds an old report. Check all three in oval._resolve as FormatError (compile the capture, require one group, debver.split the fixed version).
minor: Debian kernel lines never say "and restart". The rows use source linux, not "kernel ...", so the restart suffix is not added. When the fixed kernel is installed but not booted, the line still reads "linux 6.1.90-1 (linux-image-...): update to X". It is also grouped with linux-libc-dev and other binaries of the same source.
minor: Debian's "less than 0:0" now reads as "no fix yet" (correct for unfixed entries, for example CVE-2005-3660 linux). The tracker also writes not-affected entries as version 0, and the OVAL may not tell them apart: today's file has CVE-2022-22965 (libspring-java) and CVE-2023-28204 (wpewebkit) at 0:0 next to real fixes for webkit2gtk. A machine with such a package may get a lasting false "KEV ... no fix yet" line until an ignore entry is added. Worth one sentence in the README.
minor: Livepatch is not read. On live hosts that use Livepatch (the owner's plan), a kernel KEV fixed by a live patch still shows "update to X and restart" until the planned restart. That fits the policy, but the line could note it.
minor: within the 1 GB decompressed cap, one text node is not bounded. An 804-byte bz2 holding 900 MB of text in one element went to 1.35 GB RSS. MemoryMax now contains that to the check's own cgroup. A 10 KB bz2 of 200 MB of empty elements now stays at 43 MB but costs 80 s of CPU (CPUWeight=20). Both are acceptable now; noted only.

Round 1 (this lens and the state lens), on this head:

  • round 1, fixed: memory from a small feed. Each finished entry and section is removed from its parent, decompressed bytes are capped (maxXmlMb), one entry is capped at MAX_ENTRY, and the unit has MemoryHigh/MemoryMax. My round-1 bomb (10 KB, 200 MB of elements) was 4.6 GB RSS at ea4e1ce and is 43 MB now. Test: test_the_decompressed_size_and_one_entry_are_capped.
  • round 1, fixed: a format change read as all clear. An unknown test kind, a state operation, or a missing test, object or variable is now a FormatError. Other guards: the 90 % resolve floor, absolute floors (oval 1000, kev 500, epss 100k) and the 50 % floor against the kept copy (the meta now stores the count). My repro (operation "less than or equal") was a silent 6->4 at ea4e1ce; now it is a FormatError. Tests: test_a_shape_it_does_not_know_is_an_error_never_fewer_advisories, test_a_download_far_smaller_than_the_kept_copy_never_replaces_it, test_package_tests_that_name_nothing_are_a_format_error.
  • round 1, fixed: the kernel. Ubuntu matches the uname pattern plus the version test, picks the flavour from the running kernel's linux-modules/linux-image source, and gives a note when it cannot place the kernel. Debian uses the running linux-image version against source linux. Other kernel packages are left out. Checked on the real feeds (block 1). Tests: test_the_running_kernel_by_its_flavour, test_old_kernel_packages_never_give_lines, test_a_kernel_it_cannot_place_is_a_note_never_a_finding, test_debian_source_names_no_fix_kev_and_the_running_image.
  • round 1, fixed: Debian 0:0 is read as no fix (no_fix). Test: test_debian_names_source_packages_and_0_0_is_no_fix.
  • round 1, fixed: killed runs' .tmp files are swept at start under a flock on the cache, and a second run waits. Tests: test_a_killed_runs_temporary_files_are_swept, ..._and_a_second_run_waits_for_none.
  • round 1, fixed: the waiting clock is keyed on CVE plus binary and kept on a run without data, so a newer fix no longer resets it. Test: test_the_waiting_clock_survives_a_run_without_data_and_a_newer_fix.
  • round 1, fixed: one line per KEV CVE or per source, at most 40 lines; the alert step caps at 45 lines and 5 notes. Tests: test_one_line_per_source_with_its_highest_fix, the alert tests.
  • round 1, fixed: every printed or alerted line goes through one_line, there is no plain http and no redirect to http, and a root run against the unit's cache refuses. Tests: test_server_text_reaches_the_lines_as_one_line, test_only_https_and_no_redirect_to_http, test_as_root_on_the_units_cache_it_refuses.
  • round 1 (state lens), fixed: iU, iF, iH and iW/it count as installed, and an unknown status is cannot check (test_held_and_half_installed_packages_count_removed_do_not_and_unknown_is_cannot_check). EPSS is now the daily bulk file (2.9 MB gz, 411k rows), so no CVE list leaves the machine; only plain GETs of the three public files.
# 1: this head's reader on today's real feeds (normal user, python 3)
noble     26,127 advisories + 512,456 kernel entries (54 flavours)  5.9 s  ~370 MB   no FormatError
jammy     35,319 advisories + 887,399 kernel entries (60 flavours)  7.7 s  ~630 MB   no FormatError
bookworm  68,943 advisories (12,042 no fix)                          3.2 s            no FormatError
trixie    74,423 advisories (8,957 no fix)                           3.2 s            no FormatError
epss      411,399 rows, 0.1 s;  kev 1,790
kernel, noble 6.8.0-31-generic (modules from linux):    10,295 affected, 12 KEV (CVE-2024-36971, CVE-2024-53104, ...)
kernel, noble 6.14.0-29-generic (linux-hwe-6.14):       placed; 4 KEV, no fix
kernel, noble 6.8.0-31-generic, no packages:            note "matches several kernels (linux, linux-riscv)"
kernel, bookworm 6.1.0-17-amd64 image 6.1.69-1:         KEV incl. CVE-2024-1086

# 2: round-1 repros on this head
operation="less than or equal"   -> FormatError: a dpkginfo state with operation "less than or equal"
10 KB bz2, 200 MB of <x/>        -> FormatError after 80.7 s, RSS 43 MB   (ea4e1ce4: 4.6 GB)
10 KB bz2, one 52M-child entry   -> FormatError: an entry with more than 500000 elements, 0.2 s
804 B bz2, 900 MB text node      -> 1.35 GB RSS, then FormatError        (contained by MemoryMax=1G)

Tests on this head: exposure.test.py 45 ok (1 skipped: no dpkg here), install 11, baseline 20, tick 35, idle 29, all ok. The red check passes. The new tests use the new API, so running them against ea4e1ce says nothing useful. Instead, each round-1 repro above fails at ea4e1ce and passes here.

State question

  • Runs again: the same day there is no download. The kept OVAL is parsed again (6 to 8 s; about 370 MB on noble), the lines are the same, and the clock is kept. A second run at the same time finds the flock held and does nothing. The next day: conditional GETs. EPSS changes daily, so about 3 MB is downloaded each day.
  • Killed half-way: the .tmp files are swept at the next start. If killed between the data rename and the meta write, the data's sha256 does not match, so it counts as no copy and is downloaded again: it fails closed. If killed or OOM-killed, the alert step finds the old report and alerts "missing or broken".
  • Old cache from ea4e1ce: the oval and kev copies stay valid (same URL and sha) and are read by the new reader. Their meta has no count, so the 50 % floor waits for the next download. epss.json is left behind as an orphan (it is not a .tmp file; uninstall removes it). The old fixSeen keys ("binary fixed") never match the new "CVE binary" keys, so waiting clocks restart once. A v1 report is read fine by the alert step.
  • Empty state: the first run downloads all three. Offline, it gives cannot-check lines for oval, KEV and EPSS plus the note "kernel: not checked (no security data)", exits 1 and alerts. Never all clear. Exposure off, or no machine.json: same as round 1 (off: exit 0, nothing written; no machine file: exit 1, journal only).

🤖 Generated with Claude Code

- a kernel entry it cannot read (fixed version, a capture pattern with no
  group or that does not compile) is a format error when the file is read; a
  fault in the check is a cannot-check report, never a traceback;
- only the running kernel's entries are kept (jammy ~375 MB, noble ~265 MB),
  counts still cover the whole file; unit comment fixed;
- package advisories and kernel entries are floored apart; a feed that shrank
  for good is accepted after the same smaller counts 3 days in a row, with a
  visible "feed shrank, accepted" drift line;
- the report is written while the cache lock is held;
- the kernel's waiting clock is per flavour (kept across a reboot into a newer
  kernel still behind); tests for the oldest-first-sight and the dropping of
  finished entries;
- Debian kernel lines say "and restart"; Debian 0:0 reads "no fixed version
  listed by Debian" with the ignore-entry way out; README: Livepatch not read;
- the first cache format's epss.json is removed and its waiting days kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scuttletoby
scuttletoby merged commit 859db71 into main Nov 23, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant