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>
112 lines
3.9 KiB
TypeScript
112 lines
3.9 KiB
TypeScript
import { writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect } from "vitest";
|
|
import { toolContract } from "../../../src/contracts/toolContracts.js";
|
|
import { createServer } from "../../../src/server/createServer.js";
|
|
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
|
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
|
import {
|
|
compressedKernelModuleContainer,
|
|
kernelModuleFixture,
|
|
} from "../../../src/native/elf/KernelModule.fixture.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { mcpTest, type TestMcp } from "../../support/mcp/mcpFixture.js";
|
|
|
|
const connect = async (mcp: TestMcp) => {
|
|
const session = createTestBinarySession(() => {
|
|
throw new Error("Kernel module inspection must not start a deep provider");
|
|
});
|
|
const client = await mcp.connect(createServer({ kind: "session", session }));
|
|
return { client, session };
|
|
};
|
|
|
|
mcpTest(
|
|
"advertises inspect_kernel_module and reads an ELF32 big-endian module",
|
|
async ({ mcp }) => {
|
|
const { client, session } = await connect(mcp);
|
|
try {
|
|
const advertised = (await client.listTools()).tools.find(
|
|
(tool) => tool.name === "inspect_kernel_module",
|
|
);
|
|
expect(advertised?.annotations).toMatchObject({
|
|
readOnlyHint: false,
|
|
idempotentHint: true,
|
|
});
|
|
const root = await createTestTempDirectory("rea-kernel-module-mcp-");
|
|
const path = join(root, "demo.ko");
|
|
await writeFile(path, kernelModuleFixture({ bits: 32, little: false }));
|
|
const response = await client.callTool({
|
|
name: "inspect_kernel_module",
|
|
arguments: { path },
|
|
});
|
|
expect(response.isError, JSON.stringify(response.content)).not.toBe(true);
|
|
const evidence = toolContract("inspect_kernel_module").outputSchema.parse(
|
|
response.structuredContent,
|
|
);
|
|
expect(evidence.normalized_result).toMatchObject({
|
|
format: "elf32",
|
|
byte_order: "big",
|
|
machine: 20,
|
|
applicability: "applicable",
|
|
});
|
|
expect(evidence.subject?.architecture).toBe("powerpc");
|
|
expect(evidence.normalized_result.modinfo?.entries[0]).toMatchObject({
|
|
key: "license",
|
|
value: "GPL",
|
|
});
|
|
expect(evidence.normalized_result.versions?.entries[1]?.crc_hex).toBe(
|
|
"90abcdef",
|
|
);
|
|
} finally {
|
|
await session.close();
|
|
}
|
|
},
|
|
);
|
|
|
|
mcpTest(
|
|
"requires an absolute path for inspect_kernel_module",
|
|
async ({ mcp }) => {
|
|
const { client, session } = await connect(mcp);
|
|
try {
|
|
const response = await client.callTool({
|
|
name: "inspect_kernel_module",
|
|
arguments: { path: "demo.ko" },
|
|
});
|
|
expect(response.isError).toBe(true);
|
|
expect(parseMcpToolError(response).error).toMatchObject({
|
|
code: "invalid_request",
|
|
details: { operation: "inspect_kernel_module" },
|
|
});
|
|
} finally {
|
|
await session.close();
|
|
}
|
|
},
|
|
);
|
|
|
|
mcpTest(
|
|
"reports a zstd container as an unsupported kernel-module target",
|
|
async ({ mcp }) => {
|
|
const { client, session } = await connect(mcp);
|
|
try {
|
|
const root = await createTestTempDirectory("rea-kernel-module-zstd-mcp-");
|
|
const path = join(root, "demo.ko.zst");
|
|
await writeFile(path, compressedKernelModuleContainer("zstd"));
|
|
const response = await client.callTool({
|
|
name: "inspect_kernel_module",
|
|
arguments: { path },
|
|
});
|
|
expect(response.isError, JSON.stringify(response.content)).not.toBe(true);
|
|
const evidence = toolContract("inspect_kernel_module").outputSchema.parse(
|
|
response.structuredContent,
|
|
);
|
|
expect(evidence.normalized_result).toMatchObject({
|
|
applicability: "unsupported",
|
|
compression: { codec: "zstd", status: "unsupported" },
|
|
next_probe: { operation: "external_decompression" },
|
|
});
|
|
} finally {
|
|
await session.close();
|
|
}
|
|
},
|
|
);
|