mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 05:32:44 +00:00
fix(elf): report empty kernel module signature ranges as malformed (#12471)
This commit is contained in:
1 parent
987a71222f
commit
8349201627
4 files changed
+59
-22
No files matched your search
@@ -64,10 +64,10 @@ limitation that the decoded size is unknown.
|
||||
The signature trailer is the 28-byte magic `~Module signature appended~\n`
|
||||
preceded by a 12-byte `module_signature` (`algo`, `hash`, `id_type`,
|
||||
`signer_len`, `key_id_len`, three pad bytes, and big-endian `sig_len`). When
|
||||
those parameter fields are zero and `id_type` is PKCS#7 (`2`), the preceding
|
||||
`sig_len` bytes are the PKCS#7 range and its SHA-256. The range is not parsed
|
||||
and no certificate, signer, or digest-coverage claim is made. An absent
|
||||
trailer is observed absence, not proof the module is unsigned.
|
||||
those parameter fields are zero, `id_type` is PKCS#7 (`2`), and `sig_len` is
|
||||
positive, the report gives the preceding PKCS#7 range and its SHA-256.
|
||||
Certificate, signer, and digest coverage remain unobserved. An absent trailer
|
||||
records observed absence for this input.
|
||||
|
||||
When section names are incomplete, a missing named section is `unknown`
|
||||
rather than `absent`. An empty file-backed section is present and empty.
|
||||
@@ -119,7 +119,7 @@ entries. `SHT_NOBITS` or a declared range that leaves the file is
|
||||
`signature_trailer_truncated` is reserved for an appended magic with fewer
|
||||
than 12 preceding bytes. ELF admission requires at least 52 (ELF32) or 64
|
||||
(ELF64) bytes, so this inspection never returns it for an admitted file. A
|
||||
`sig_len` that does not leave at least one module byte is
|
||||
`sig_len` that leaves no module bytes or names an empty PKCS#7 range is
|
||||
`signature_length_inconsistent`. Nonzero `algo`, `hash`, signer, key-id, or
|
||||
pad fields for PKCS#7 are `signature_parameters_nonzero`.
|
||||
A parameter block whose `id_type` is not PKCS#7 is
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
"src/native/elf/ElfNoteParser.ts": 27,
|
||||
"src/native/elf/ElfUnwindTables.ts": 6,
|
||||
"src/native/elf/KernelBuildConfig.ts": 7,
|
||||
"src/native/elf/KernelModuleParser.ts": 5,
|
||||
"src/native/elf/KernelModuleParser.ts": 4,
|
||||
"src/native/hardening/ElfHardening.ts": 2,
|
||||
"src/native/initializers/ElfInitializerSymbols.ts": 4,
|
||||
"src/native/initializers/MachoInitializers.ts": 22,
|
||||
|
||||
@@ -13,9 +13,10 @@ import {
|
||||
type InspectKernelModuleInput,
|
||||
} from "../../domain/native/kernelModule.js";
|
||||
import type { AnalysisParameterLimit } from "../../domain/analysisSettings.js";
|
||||
import type {
|
||||
ImageSection,
|
||||
BinaryContainer,
|
||||
import {
|
||||
BinaryReader,
|
||||
type ImageSection,
|
||||
type BinaryContainer,
|
||||
} from "../../domain/binaryContainer.js";
|
||||
import { readElfImage } from "../../domain/native/elfImage.js";
|
||||
import { kernelCompressionCodecAt } from "./KernelCompressionCodec.js";
|
||||
@@ -438,21 +439,23 @@ const parseSignature = (bytes: Buffer): Report["signature"] => {
|
||||
reason: "signature_trailer_truncated",
|
||||
};
|
||||
const infoOffset = magic.offset - MODULE_SIGNATURE_INFO_BYTES;
|
||||
const footer = new BinaryReader(
|
||||
bytes.subarray(infoOffset, magic.offset),
|
||||
false,
|
||||
"elf",
|
||||
);
|
||||
const info = {
|
||||
location: { offset: infoOffset, bytes: MODULE_SIGNATURE_INFO_BYTES },
|
||||
algo: bytes[infoOffset] ?? 0,
|
||||
hash: bytes[infoOffset + 1] ?? 0,
|
||||
id_type: bytes[infoOffset + 2] ?? 0,
|
||||
signer_len: bytes[infoOffset + 3] ?? 0,
|
||||
key_id_len: bytes[infoOffset + 4] ?? 0,
|
||||
pad: [
|
||||
bytes[infoOffset + 5] ?? 0,
|
||||
bytes[infoOffset + 6] ?? 0,
|
||||
bytes[infoOffset + 7] ?? 0,
|
||||
] as [number, number, number],
|
||||
sig_len: bytes.readUInt32BE(infoOffset + 8),
|
||||
algo: footer.u8(0),
|
||||
hash: footer.u8(1),
|
||||
id_type: footer.u8(2),
|
||||
signer_len: footer.u8(3),
|
||||
key_id_len: footer.u8(4),
|
||||
pad: [footer.u8(5), footer.u8(6), footer.u8(7)] as [number, number, number],
|
||||
sig_len: footer.u32(8),
|
||||
};
|
||||
if (info.sig_len >= infoOffset)
|
||||
const isPkcs7 = info.id_type === MODULE_SIGNATURE_PKCS7_ID_TYPE;
|
||||
if (info.sig_len >= infoOffset || (isPkcs7 && info.sig_len === 0))
|
||||
return {
|
||||
status: "malformed",
|
||||
magic,
|
||||
@@ -460,7 +463,7 @@ const parseSignature = (bytes: Buffer): Report["signature"] => {
|
||||
pkcs7: null,
|
||||
reason: "signature_length_inconsistent",
|
||||
};
|
||||
if (info.id_type !== MODULE_SIGNATURE_PKCS7_ID_TYPE)
|
||||
if (!isPkcs7)
|
||||
return {
|
||||
status: "unsupported",
|
||||
magic,
|
||||
|
||||
@@ -6,10 +6,44 @@ import { createKernelModuleService } from "../../../src/composition/binaryDiagno
|
||||
import {
|
||||
compressedKernelModuleContainer,
|
||||
kernelModuleFixture,
|
||||
moduleSignatureTrailer,
|
||||
} from "../../../src/native/elf/KernelModule.fixture.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
describe("kernel module stable filesystem boundary", () => {
|
||||
it("retains trailer fields but withholds an empty PKCS#7 range", async () => {
|
||||
const root = await createTestTempDirectory("rea-kernel-module-empty-sig-");
|
||||
const path = join(root, "demo.ko");
|
||||
await writeFile(
|
||||
path,
|
||||
kernelModuleFixture({
|
||||
signature: moduleSignatureTrailer(Buffer.alloc(0)),
|
||||
}),
|
||||
);
|
||||
const service = createKernelModuleService();
|
||||
try {
|
||||
const result = await service.inspect({ path });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.normalized_result).toMatchObject({
|
||||
coverage: { status: "partial" },
|
||||
modinfo: {
|
||||
entries: expect.arrayContaining([
|
||||
expect.objectContaining({ key: "license", value: "GPL" }),
|
||||
]),
|
||||
},
|
||||
signature: {
|
||||
status: "malformed",
|
||||
reason: "signature_length_inconsistent",
|
||||
magic: { bytes: 28 },
|
||||
info: { sig_len: 0, id_type: 2 },
|
||||
pkcs7: null,
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
await service.close();
|
||||
}
|
||||
});
|
||||
|
||||
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");
|
||||
|
||||
Reference in new issue
Block a user