mirror of
https://github.com/morluto/rea
synced 2026-10-26 14:25:49 -04:00
dba8a31978
* feat(elf): inspect Linux kernel module metadata Adds inspect-kernel-module and inspect_kernel_module for ELF32/ELF64 ET_REL Linux kernel modules, read statically without executing them. Reports ordered .modinfo entries with duplicates preserved, __versions symbol CRCs, the presence of .gnu.linkonce.this_module and __ksymtab, .init.text and .exit.text sizes, and an appended module signature trailer with its PKCS#7 byte range and SHA-256. gzip, xz and zstd containers are reported unsupported with external decompression as the next probe. Malformed headers and exhausted entry budgets return no partial success. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016y53PdpyMAp9RSW65fatHe * fix(elf): bound kernel module ksymtab listing and tighten contracts Charge listed __ksymtab* sections against max_entries, omit section names longer than 256 bytes with ksymtab_name_exceeds_limit, and aggregate the non-file-backed limitation so repeated huge names cannot inflate Evidence. Use fixedTupleSchema for the signature pad bytes with projection parity tests, and assert the late-cancellation reason and retained observation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016y53PdpyMAp9RSW65fatHe * fix: resolve merge integration errors --------- Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
91 lines
3.5 KiB
TypeScript
91 lines
3.5 KiB
TypeScript
import { symlink, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { createKernelModuleService } from "../../../src/composition/binaryDiagnostics.js";
|
|
import {
|
|
compressedKernelModuleContainer,
|
|
kernelModuleFixture,
|
|
} from "../../../src/native/elf/KernelModule.fixture.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
|
|
describe("kernel module stable filesystem boundary", () => {
|
|
it("reports non-file and malformed ELF selections as caller input errors", async () => {
|
|
const root = await createTestTempDirectory("rea-kernel-module-files-");
|
|
const path = join(root, "demo.ko");
|
|
const alias = join(root, "alias");
|
|
const malformed = join(root, "malformed");
|
|
await writeFile(path, kernelModuleFixture());
|
|
await writeFile(malformed, Buffer.from("not an elf"));
|
|
await symlink(path, alias);
|
|
const service = createKernelModuleService();
|
|
try {
|
|
for (const [candidate, reason] of [
|
|
[root, "invalid_format"],
|
|
[alias, "invalid_format"],
|
|
[malformed, "invalid_format"],
|
|
[join(root, "missing"), "invalid_value"],
|
|
[join(path, "child"), "invalid_value"],
|
|
] as const) {
|
|
const result = await service.inspect({ path: candidate });
|
|
if (result.ok) throw new Error("Expected file acquisition failure");
|
|
expect(result.error).toMatchObject({
|
|
_tag: "AnalysisInputError",
|
|
operation: "inspect_kernel_module",
|
|
issues: [
|
|
{
|
|
path: ["path"],
|
|
reason,
|
|
message: expect.any(String),
|
|
},
|
|
],
|
|
});
|
|
}
|
|
} finally {
|
|
await service.close();
|
|
}
|
|
});
|
|
|
|
it("returns typed resource and cancellation failures", async () => {
|
|
const root = await createTestTempDirectory("rea-kernel-module-budget-");
|
|
const path = join(root, "demo.ko");
|
|
await writeFile(path, kernelModuleFixture());
|
|
const service = createKernelModuleService();
|
|
try {
|
|
const tooSmall = await service.inspect({ path, max_file_bytes: 64 });
|
|
if (tooSmall.ok) throw new Error("Expected resource budget failure");
|
|
expect(tooSmall.error._tag).toBe("AnalysisResourceConstraintError");
|
|
const tooMany = await service.inspect({ path, max_entries: 1 });
|
|
if (tooMany.ok) throw new Error("Expected entry budget failure");
|
|
expect(tooMany.error._tag).toBe("AnalysisResourceConstraintError");
|
|
const cancelled = await service.inspect(
|
|
{ path },
|
|
{ signal: AbortSignal.abort() },
|
|
);
|
|
if (cancelled.ok) throw new Error("Expected cancellation");
|
|
expect(cancelled.error._tag).toBe("AnalysisCancelledError");
|
|
} finally {
|
|
await service.close();
|
|
}
|
|
});
|
|
|
|
it("reports a gzip container as unsupported without treating it as a module", async () => {
|
|
const root = await createTestTempDirectory("rea-kernel-module-gzip-");
|
|
const path = join(root, "demo.ko.gz");
|
|
await writeFile(path, compressedKernelModuleContainer("gzip"));
|
|
const service = createKernelModuleService();
|
|
try {
|
|
const result = await service.inspect({ path });
|
|
if (!result.ok) throw result.error;
|
|
expect(result.value.subject?.format).toBe("file");
|
|
expect(result.value.normalized_result).toMatchObject({
|
|
applicability: "unsupported",
|
|
compression: { codec: "gzip", status: "unsupported" },
|
|
next_probe: { operation: "external_decompression" },
|
|
modinfo: null,
|
|
});
|
|
} finally {
|
|
await service.close();
|
|
}
|
|
});
|
|
});
|