Admit arbitrary DKMS packages and resolve exact target kernel headers
This commit is contained in:
parent
fbe54854b8
commit
621a8bb2aa
8 changed files with 176 additions and 21 deletions
|
|
@ -59,19 +59,22 @@ deployment, retained inputs/history, and preservation of the managed overlay.
|
|||
|
||||
## Experimental DKMS adapter
|
||||
|
||||
`extension add v4l2loopback-dkms` uses the same cumulative request path. The adapter
|
||||
recognizes reviewed exact package archives in `adapters/dkms-policy.tsv`; source
|
||||
or framework drift requires review, not a wildcard exemption. Initial scope is the
|
||||
DKMS packages (including `broadcom-wl-dkms` and `v4l2loopback-dkms`) use the same
|
||||
cumulative request path. D-097 removes the package-name/archive-hash allowlist.
|
||||
An archive supplying `/usr/src/<directory>/dkms.conf` is a DKMS source input;
|
||||
the native `dkms` package is the framework. Initial execution scope is the
|
||||
x86_64 Core `linux` profile without Secure Boot; this is not universal DKMS support.
|
||||
|
||||
- Resolve `<pkgbase>-headers=<installed kernel package version>` against retained
|
||||
sync DBs. Generated transaction targets stay separate from explicit requests.
|
||||
- Review DKMS 3.4.4's package scriptlet (historical informational upgrade message)
|
||||
and three ALPM hooks. Replace those exact framework hooks with the offline
|
||||
- DKMS source/framework package scriptlets and hooks are admitted to isolated
|
||||
staging without per-package approval. Replace the three native framework hooks with the offline
|
||||
finalizer: native helper can skip a failed build and still return zero.
|
||||
- Only reviewed source archives may contribute `/usr/src`; header packages may
|
||||
- DKMS source archives may contribute `/usr/src`; header packages may
|
||||
contribute kernel build trees and vDSO objects; `linux-headers` may supply its
|
||||
`/usr/src/linux` link. Unclassified package actions still fail.
|
||||
`/usr/src/linux` link. Non-DKMS unclassified package actions still fail.
|
||||
Signatures/checksums and exact snapshot inputs remain mandatory. Configurations
|
||||
are never sourced on the live host during archive inspection.
|
||||
- Offline staging explicitly adds/builds/installs each source for each image kernel,
|
||||
with bounded commands. Validate matching headers, installed status, nonempty
|
||||
module outputs and vermagic; preserve preexisting modules. Then run depmod and
|
||||
|
|
@ -89,3 +92,11 @@ VM acceptance (`core_iso_acceptance.py --dkms`) checks build/staging, duplicate
|
|||
failed-request preservation, post-reboot modprobe and `/dev/video0`, then another
|
||||
cumulative addition and reboot. Hardware-driver coverage, module signing for Secure
|
||||
Boot, updates to another kernel and the stable shared action engine need further work.
|
||||
|
||||
2026-11-09 D-097 source checks: `python3 tests/dkms_inputs.py` passed four tests
|
||||
on terra in a disposable tools container with libarchive-tools: arbitrary DKMS
|
||||
names/configurations and framework revisions, retained payload boundaries, and
|
||||
target-version header resolution/failure. Shell syntax checks passed. The daemon
|
||||
resolver now includes exact headers in its checked dependency closure (previously
|
||||
only the legacy CLI download path added them). These are next-build source changes;
|
||||
Broadcom compilation/activation and installed-image acceptance remain unverified.
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ mkdir -p /var/lib/dkms
|
|||
printf 'module\tversion\tkernel\tpath\tsha256\tvermagic\n' > /evidence/dkms/modules.tsv
|
||||
for config in "${configs[@]}"; do
|
||||
source_dir=${config%/dkms.conf}
|
||||
# Native DKMS registers the source and evaluates its reviewed configuration.
|
||||
# Native DKMS registers the source and evaluates its configuration in staging.
|
||||
timeout 120 dkms add "$source_dir"
|
||||
done
|
||||
for modules in /usr/lib/modules/*; do
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
# Experimental reviewed package archives; source changes require another review.
|
||||
# role sha256 package
|
||||
framework 5881381014e27c1082aa02ebbb66fbc6deae894f7b11016963313f341279075d dkms
|
||||
source 5e6867f8e6e096afc75c34104d5b66f29e563ad19fafbf177f5f349399aff8a1 v4l2loopback-dkms
|
||||
|
|
|
@ -78,9 +78,15 @@ for archive in "$generation/inputs/"*.pkg.tar.*; do
|
|||
[[ $archive != *.sig ]] || continue
|
||||
listing="$generation/logs/$(basename "$archive").files"
|
||||
bsdtar -tf "$archive" > "$listing"
|
||||
archive_hash=$(sha256sum "$archive" | cut -d' ' -f1)
|
||||
role=$(awk -v hash="$archive_hash" '$2 == hash {print $1}' "$generation/dkms-policy.tsv")
|
||||
package=$(bsdtar -xOf "$archive" .PKGINFO | sed -n 's/^pkgname = //p')
|
||||
# Classify native DKMS inputs structurally, without a package/hash allowlist.
|
||||
# Package configuration is evaluated only by DKMS inside offline staging.
|
||||
role=''
|
||||
if [[ $package == dkms ]]; then
|
||||
role=framework
|
||||
elif grep -qE '^(\./)?usr/src/[^/]+/dkms\.conf$' "$listing"; then
|
||||
role=source
|
||||
fi
|
||||
if [[ $role == framework ]]; then dkms_enabled=true; fi
|
||||
while IFS= read -r path; do
|
||||
path=${path#./}
|
||||
|
|
@ -89,7 +95,7 @@ for archive in "$generation/inputs/"*.pkg.tar.*; do
|
|||
usr/src/linux)
|
||||
[[ $package == linux-headers ]] || { echo "Unexpected kernel source link: $package" >&2; exit 1; } ;;
|
||||
usr/src/*)
|
||||
[[ $role == source ]] || { echo "Unreviewed DKMS source package: $package ($archive_hash)" >&2; exit 1; } ;;
|
||||
[[ $role == source ]] || { echo "Source payload lacks a DKMS configuration: $package" >&2; exit 1; } ;;
|
||||
usr/lib/modules/*/build/*|usr/lib/modules/*/vdso/*.so)
|
||||
[[ $package == *-headers ]] || { echo "Unexpected kernel build payload: $package" >&2; exit 1; } ;;
|
||||
usr/local/*|usr/lib/modules/*|boot/*|opt/*|var/*|home/*|root/*|srv/*|mnt/*|etc/pacman.d/hooks/*)
|
||||
|
|
@ -101,19 +107,19 @@ for archive in "$generation/inputs/"*.pkg.tar.*; do
|
|||
if grep -qxE '(\./)?\.INSTALL' "$listing"; then
|
||||
script=$(grep -xE '(\./)?\.INSTALL' "$listing")
|
||||
hash=$(bsdtar -xOf "$archive" "$script" | sha256sum | cut -d' ' -f1)
|
||||
[[ $role == framework ]] || grep -q "^$hash " "$policy/scriptlets.sha256" || {
|
||||
[[ -n $role ]] || grep -q "^$hash " "$policy/scriptlets.sha256" || {
|
||||
echo "Unclassified .INSTALL in $(basename "$archive"); hash=$hash" >&2; exit 1;
|
||||
}
|
||||
fi
|
||||
while IFS= read -r hook; do
|
||||
hash=$(bsdtar -xOf "$archive" "$hook" | sha256sum | cut -d' ' -f1)
|
||||
[[ $role == framework ]] || grep -Fxq "$hash ${hook#./}" "$policy/hooks.sha256" || {
|
||||
[[ -n $role ]] || grep -Fxq "$hash ${hook#./}" "$policy/hooks.sha256" || {
|
||||
echo "Unclassified hook in $(basename "$archive"): $hook; hash=$hash" >&2; exit 1;
|
||||
}
|
||||
done < <(grep -E '^(\./)?usr/share/libalpm/hooks/[^/]+\.hook$' "$listing" || true)
|
||||
done
|
||||
if $dkms_enabled; then
|
||||
# Exact reviewed framework hooks are replaced by the checked offline finalizer.
|
||||
# Native framework hooks are replaced by the checked offline finalizer.
|
||||
# Keep overrides for future staging; no live transaction is allowed on this OS.
|
||||
mkdir -p "$root/etc/pacman.d/hooks"
|
||||
for hook in 70-dkms-install.hook 70-dkms-upgrade.hook 71-dkms-remove.hook; do
|
||||
|
|
|
|||
|
|
@ -37,7 +37,35 @@ def package(pkg, local=None):
|
|||
require(pkg.base64_sig, 'Repository package lacks mandatory signature')
|
||||
return dict(name=pkg.name, version=pkg.version, architecture=pkg.arch,
|
||||
source='repository', repository=pkg.db.name, checksum=pkg.sha256sum,
|
||||
filename=pkg.filename, signature=pkg.base64_sig, size=pkg.size)
|
||||
filename=pkg.filename, signature=pkg.base64_sig, size=pkg.size)
|
||||
|
||||
|
||||
def kernel_headers(handle, databases, additions, modules_root=Path('/usr/lib/modules')):
|
||||
"""Resolve DKMS build inputs against the target image, never uname or live repos."""
|
||||
localdb = handle.get_localdb()
|
||||
if not any(pkg.name == 'dkms' for pkg in additions) and localdb.get_pkg('dkms') is None:
|
||||
return []
|
||||
headers = {}
|
||||
kernels = 0
|
||||
for modules in sorted(modules_root.iterdir()):
|
||||
if not (modules / 'vmlinuz').is_file():
|
||||
continue
|
||||
kernels += 1
|
||||
pkgbase = (modules / 'pkgbase').read_text().strip()
|
||||
require(re.fullmatch(r'[a-zA-Z0-9_+-]+', pkgbase), 'Invalid target kernel package base')
|
||||
kernel = localdb.get_pkg(pkgbase)
|
||||
require(kernel is not None, 'Target kernel absent from image package database')
|
||||
name = pkgbase + '-headers'
|
||||
installed = localdb.get_pkg(name)
|
||||
if installed is not None:
|
||||
require(installed.version == kernel.version, 'Installed headers differ from target kernel')
|
||||
continue
|
||||
candidate = next((pkg for db in databases if (pkg := db.get_pkg(name)) is not None), None)
|
||||
require(candidate is not None and candidate.version == kernel.version,
|
||||
'Exact target kernel headers unavailable in selected snapshot: ' + name + '=' + kernel.version)
|
||||
headers[name] = candidate
|
||||
require(kernels > 0, 'No target kernel for DKMS')
|
||||
return list(headers.values())
|
||||
|
||||
|
||||
def main():
|
||||
|
|
@ -116,6 +144,24 @@ def main():
|
|||
transaction.add_pkg(pkg)
|
||||
transaction.prepare()
|
||||
require(not transaction.to_remove, 'Transaction would remove managed packages')
|
||||
if mode != 'install':
|
||||
additions = list(transaction.to_add)
|
||||
headers = kernel_headers(handle, databases, additions)
|
||||
if headers:
|
||||
# Re-prepare the complete closure with exact kernel build inputs.
|
||||
# Explicit user requests remain separate in the durable plan.
|
||||
transaction.release()
|
||||
transaction = handle.init_transaction(downloadonly=(mode == 'download'), needed=False)
|
||||
targets = {pkg.name: pkg for pkg in additions}
|
||||
for header in headers:
|
||||
if header.name in targets:
|
||||
require(targets[header.name].version == header.version,
|
||||
'Requested headers differ from target kernel')
|
||||
targets[header.name] = header
|
||||
for pkg in targets.values():
|
||||
transaction.add_pkg(pkg)
|
||||
transaction.prepare()
|
||||
require(not transaction.to_remove, 'Transaction would remove managed packages')
|
||||
additions = list(transaction.to_add)
|
||||
resolved = [package(pkg, local.get(pkg.name)) for pkg in additions] if mode != 'install' else request['resolved']
|
||||
if mode == 'install':
|
||||
|
|
|
|||
|
|
@ -208,7 +208,6 @@ fn compose(generation: &Path, id: &str, base: &str, snapshot: &str,
|
|||
let rootstr = root.to_str().ok_or("invalid workspace path")?;
|
||||
run("ostree", &[REPO, "refs", &format!("--create=extensions/bases/{id}"), base])?;
|
||||
run("ostree", &[REPO, "checkout", "--force-copy", base, rootstr])?;
|
||||
write(generation.join("dkms-policy.tsv"), include_str!("../adapters/dkms-policy.tsv"))?;
|
||||
write(generation.join("dkms-finalize.sh"), include_str!("../adapters/dkms-finalize.sh"))?;
|
||||
write(generation.join("finalize-managed.sh"), include_str!("../adapters/finalize-managed.sh"))?;
|
||||
let transaction = Command::new("/bin/bash").args(["-euo", "pipefail", "-c",
|
||||
|
|
|
|||
|
|
@ -470,7 +470,6 @@ pub(crate) fn execute_locked(worker: &Worker, plan: &Plan, download_only: bool,
|
|||
let names = requests.iter().map(|r| r["name"].as_str().ok_or_else(|| failure("Invalid explicit request")))
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
fs::write(sandbox.path.join("requested"),format!("{}\n",names.join("\n"))).map_err(storage::io_error)?;
|
||||
fs::write(sandbox.path.join("dkms-policy.tsv"),include_bytes!("../../adapters/dkms-policy.tsv")).map_err(storage::io_error)?;
|
||||
fs::write(sandbox.path.join("dkms-finalize.sh"),include_bytes!("../../adapters/dkms-finalize.sh")).map_err(storage::io_error)?;
|
||||
fs::write(sandbox.path.join("finalize.sh"),include_bytes!("../../adapters/extensions.sh")).map_err(storage::io_error)?;
|
||||
fs::write(sandbox.path.join("finalize-managed.sh"),include_bytes!("../../adapters/finalize-managed.sh")).map_err(storage::io_error)?;
|
||||
|
|
|
|||
98
tests/dkms_inputs.py
Normal file
98
tests/dkms_inputs.py
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Exercise the real archive gate and target-image header resolver without installing."""
|
||||
import importlib.util
|
||||
import io
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import tempfile
|
||||
import types
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
# Resolver helper needs package DB objects, not a live libalpm handle.
|
||||
sys.modules['pyalpm'] = types.ModuleType('pyalpm')
|
||||
sys.modules['pycman'] = types.ModuleType('pycman')
|
||||
config = types.ModuleType('pycman.config')
|
||||
config.PacmanConfig = None
|
||||
sys.modules['pycman.config'] = config
|
||||
spec = importlib.util.spec_from_file_location('packages', ROOT / 'adapters/package-transaction.py')
|
||||
packages = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(packages)
|
||||
|
||||
|
||||
class Inputs(unittest.TestCase):
|
||||
def inspect(self, name, payload):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
generation = Path(directory)
|
||||
(generation / 'inputs').mkdir()
|
||||
(generation / 'logs').mkdir()
|
||||
policy = generation / 'root/usr/lib/archipelago/hook-policy'
|
||||
policy.mkdir(parents=True)
|
||||
for file in ('hooks.sha256', 'scriptlets.sha256'):
|
||||
(policy / file).touch()
|
||||
with tarfile.open(generation / 'inputs/test.pkg.tar.gz', 'w:gz') as archive:
|
||||
for path, content in {'.PKGINFO': 'pkgname = ' + name + '\n', **payload}.items():
|
||||
data = content.encode()
|
||||
entry = tarfile.TarInfo(path)
|
||||
entry.size = len(data)
|
||||
archive.addfile(entry, io.BytesIO(data))
|
||||
adapter = (ROOT / 'adapters/extensions.sh').read_text()
|
||||
gate = adapter.split('# Inspect exact signed/downloaded inputs', 1)[1].split('if $dkms_enabled; then', 1)[0]
|
||||
gate = '# Inspect exact signed/downloaded inputs' + gate
|
||||
return subprocess.run(['bash', '-euo', 'pipefail', '-c',
|
||||
'generation=$1; root=$generation/root; policy=$root/usr/lib/archipelago/hook-policy\n' + gate,
|
||||
'dkms-test', directory], capture_output=True, text=True)
|
||||
|
||||
def test_arbitrary_dkms_names_and_contents(self):
|
||||
for name, version in [('broadcom-wl-dkms', '6.30.223.271'), ('custom-driver', '999')]:
|
||||
result = self.inspect(name, {
|
||||
f'usr/src/driver-{version}/dkms.conf': 'exit 99 # must not execute on the host\n',
|
||||
f'usr/src/driver-{version}/source.c': version,
|
||||
'.INSTALL': 'exit 99\n',
|
||||
'usr/share/libalpm/hooks/driver.hook': 'new package hook contents\n'})
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
|
||||
def test_framework_has_no_archive_hash_gate(self):
|
||||
result = self.inspect('dkms', {'.INSTALL': 'new framework revision\n',
|
||||
'usr/share/libalpm/hooks/70-dkms-install.hook': 'new hook revision\n'})
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
|
||||
def test_other_payload_checks_remain(self):
|
||||
for payload in ({'usr/src/random/file.c': 'x'},
|
||||
{'usr/src/driver/dkms.conf': 'x', 'boot/kernel': 'x'},
|
||||
{'.INSTALL': 'unknown non-DKMS action'}):
|
||||
self.assertNotEqual(self.inspect('some-package', payload).returncode, 0)
|
||||
|
||||
def test_exact_headers_and_missing_snapshot(self):
|
||||
def pkg(name, version):
|
||||
return types.SimpleNamespace(name=name, version=version)
|
||||
class DB:
|
||||
def __init__(self, *items): self.items = {p.name: p for p in items}
|
||||
def get_pkg(self, name): return self.items.get(name)
|
||||
kernel = pkg('linux', '7.2.14-1')
|
||||
header = pkg('linux-headers', kernel.version)
|
||||
local = DB(kernel)
|
||||
handle = types.SimpleNamespace(get_localdb=lambda: local)
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
modules = root / '7.2.14-arch1-1'
|
||||
modules.mkdir()
|
||||
(modules / 'vmlinuz').touch()
|
||||
(modules / 'pkgbase').write_text('linux\n')
|
||||
self.assertEqual(packages.kernel_headers(handle, [], [], root), [])
|
||||
additions = [pkg('dkms', '99')]
|
||||
self.assertEqual(packages.kernel_headers(handle, [DB(header)], additions, root), [header])
|
||||
for database in (DB(), DB(pkg('linux-headers', '7.3-1'))):
|
||||
with self.assertRaisesRegex(ValueError, 'Exact target kernel headers unavailable'):
|
||||
packages.kernel_headers(handle, [database], additions, root)
|
||||
local.items[header.name] = header
|
||||
self.assertEqual(packages.kernel_headers(handle, [], additions, root), [])
|
||||
local.items[header.name] = pkg(header.name, 'wrong')
|
||||
with self.assertRaisesRegex(ValueError, 'Installed headers differ'):
|
||||
packages.kernel_headers(handle, [], additions, root)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
Add table
Reference in a new issue