mirror of
https://github.com/morluto/rea.git
synced 2026-11-18 12:42:20 +00:00
fix(native): validate ELF section backing against its type (#10066)
fix(native): reject contradictory ELF section backing
This commit is contained in:
1 parent
34025d2fcd
commit
d9537fc75c
3 files changed
+131
-1
No files matched your search
@@ -218,3 +218,122 @@ it.each([
|
||||
error: { _tag: "AnalysisOutputError" },
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
type: "SHT_PROGBITS",
|
||||
backing: "file",
|
||||
offset: "0x40",
|
||||
size: "0x10",
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
type: "SHT_PROGBITS",
|
||||
backing: "none",
|
||||
offset: "0x40",
|
||||
size: "0x10",
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
type: "SHT_PROGBITS",
|
||||
backing: "none",
|
||||
offset: "0xffffffffffffffff",
|
||||
size: "0x10",
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
type: "SHT_NOBITS",
|
||||
backing: "none",
|
||||
offset: "0xffffffffffffffff",
|
||||
size: "0x2000",
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
type: "SHT_NOBITS",
|
||||
backing: "file",
|
||||
offset: "0x40",
|
||||
size: "0x10",
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
type: "SHT_NULL",
|
||||
backing: "none",
|
||||
offset: "0xffffffffffffffff",
|
||||
size: "0x2000",
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
type: "SHT_NULL",
|
||||
backing: "file",
|
||||
offset: "0x40",
|
||||
size: "0x10",
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
type: 0x70000001,
|
||||
backing: "file",
|
||||
offset: "0x40",
|
||||
size: "0x10",
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
type: 0x70000001,
|
||||
backing: "none",
|
||||
offset: "0x40",
|
||||
size: "0x10",
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
type: "SHT_PROGBITS",
|
||||
backing: "file",
|
||||
offset: "0x80",
|
||||
size: "0x0",
|
||||
valid: true,
|
||||
},
|
||||
] as const)(
|
||||
"validates section $type backing=$backing offset=$offset size=$size before Evidence",
|
||||
async ({ type, backing, offset, size, valid }) => {
|
||||
const layout = binaryLayoutFixture();
|
||||
layout.sections.push({
|
||||
index: 0,
|
||||
name: {
|
||||
display: "data",
|
||||
bytes_base64: "ZGF0YQ==",
|
||||
location: null,
|
||||
unknown_reason: null,
|
||||
},
|
||||
name_offset: "0x0",
|
||||
type,
|
||||
header_location: { offset: "0x0", bytes: "0x40" },
|
||||
address: "0x20000000000001",
|
||||
offset,
|
||||
size,
|
||||
alignment: "0x1",
|
||||
flags: "0x3",
|
||||
link: 0,
|
||||
info: 0,
|
||||
entry_size: "0x0",
|
||||
file_backing: backing,
|
||||
});
|
||||
const service = new BinaryLayoutService({
|
||||
inspectAndClose(input, options) {
|
||||
return this.inspect(input, options);
|
||||
},
|
||||
identity: BINARY_LAYOUT_TEST_PROVIDER,
|
||||
inspect: async () => ok(layout),
|
||||
});
|
||||
const result = await service.inspect({ path: layout.artifact.path });
|
||||
if (valid) {
|
||||
if (!result.ok) throw result.error;
|
||||
expect(parseEvidence(result.value).normalized_result).toEqual(layout);
|
||||
} else {
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
_tag: "AnalysisOutputError",
|
||||
capturedOutput: layout.diagnostics,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -141,6 +141,7 @@ it.each([
|
||||
|
||||
it.each([
|
||||
"file-backed-outside",
|
||||
"false-no-file-backing",
|
||||
"header-outside",
|
||||
"wrong-index",
|
||||
"noncanonical-base64",
|
||||
@@ -151,6 +152,7 @@ it.each([
|
||||
const section = value.sections[0];
|
||||
if (section === undefined) throw new Error("section missing");
|
||||
if (problem === "file-backed-outside") section.file_backing = "file";
|
||||
if (problem === "false-no-file-backing") section.type = "SHT_PROGBITS";
|
||||
if (problem === "header-outside") section.header_location.offset = "0x80";
|
||||
if (problem === "wrong-index") section.index = 1;
|
||||
if (problem === "wrong-machine") value.architecture.machine = "EM_RISCV";
|
||||
|
||||
@@ -281,7 +281,16 @@ export const binaryLayoutSchema = binaryLayoutObjectSchema.superRefine(
|
||||
"header_location",
|
||||
]);
|
||||
checkName(section.name, ["sections", index, "name"]);
|
||||
if (section.file_backing === "file")
|
||||
const hasFileBytes =
|
||||
section.type !== "SHT_NOBITS" && section.type !== "SHT_NULL";
|
||||
if (section.file_backing !== (hasFileBytes ? "file" : "none"))
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["sections", index, "file_backing"],
|
||||
message:
|
||||
"File backing must follow the reported section type; NOBITS and unused headers have no file content.",
|
||||
});
|
||||
if (hasFileBytes)
|
||||
check(section.offset, section.size, ["sections", index]);
|
||||
}
|
||||
for (const [index, segment] of value.segments.entries()) {
|
||||
|
||||
Reference in new issue
Block a user