mirror of
https://github.com/morluto/rea.git
synced 2026-11-18 20:53:00 +00:00
fix(elf): admit distribution glibc within the default note budget (#11847)
inspect_elf_notes and inspect_elf_debug_link now examine up to 128 note entries by default instead of 32; the ceiling stays 256. Ubuntu 26.04's libc.so.6 is examined as 85 entries, 79 of them SystemTap probes, and both tools refused it with default arguments.
This commit is contained in:
6 files changed
+49
-5
No files matched your search
+2
-1
@@ -72,7 +72,8 @@ the image never carried notes in another container or overlay.
|
||||
## Limits and failures
|
||||
|
||||
The selected file is limited to 64 MiB by default (512 MiB maximum). At most
|
||||
32 note entries are examined by default across every table. Retained note
|
||||
128 note entries are examined by default across every table (256 maximum), which
|
||||
admits distribution glibc builds and their SystemTap probe notes. Retained note
|
||||
names, section names, GNU descriptor text, core dump string representations, and Android ident strings share a scan budget based on
|
||||
the source bytes plus any decoded section-name table, capped at
|
||||
`max_file_bytes`. The raw source and decoded table must also fit together
|
||||
|
||||
@@ -101,7 +101,8 @@ followed by raw build-id bytes.
|
||||
The image is limited to 64 MiB by default (512 MiB maximum). The same
|
||||
`max_file_bytes` bounds how much of a candidate is decoded, not how much is
|
||||
hashed. At most
|
||||
32 note entries are examined by default while reading build-ids. A debuglink
|
||||
128 note entries are examined by default while reading build-ids (256 maximum),
|
||||
which admits distribution glibc builds and their SystemTap probe notes. A debuglink
|
||||
or debugaltlink name longer than 4096 bytes is not copied. A build-id longer
|
||||
than 256 bytes is not copied. Malformed image ELF headers and exhausted image
|
||||
note budgets fail without partial success. Whole-file gzip, xz, and zstd
|
||||
|
||||
@@ -13,6 +13,8 @@ const buildIdHex = z.string().regex(/^(?:[0-9a-f]{2}){1,256}$/u);
|
||||
export const MAX_INSPECT_ELF_DEBUG_LINK_FILE_BYTES = 536870912;
|
||||
/** Hard ceiling on note entries read while collecting GNU build-ids. */
|
||||
export const MAX_INSPECT_ELF_DEBUG_LINK_ENTRIES = 256;
|
||||
/** Default note entry budget; admits distribution glibc and its SystemTap probe notes. */
|
||||
export const DEFAULT_INSPECT_ELF_DEBUG_LINK_ENTRIES = 128;
|
||||
/** Retained debuglink and debugaltlink file-name length. */
|
||||
export const MAX_ELF_DEBUG_LINK_NAME_BYTES = 4096;
|
||||
/** Retained build-id length for debugaltlink and GNU notes. */
|
||||
@@ -185,7 +187,7 @@ export const inspectElfDebugLinkInputSchema = z.strictObject({
|
||||
.int()
|
||||
.min(1)
|
||||
.max(MAX_INSPECT_ELF_DEBUG_LINK_ENTRIES)
|
||||
.default(32)
|
||||
.default(DEFAULT_INSPECT_ELF_DEBUG_LINK_ENTRIES)
|
||||
.describe(
|
||||
"Maximum note entries to examine while reading GNU build-ids; an image exceeding the budget fails without partial success, and a candidate exceeding it leaves its build-id check unavailable",
|
||||
),
|
||||
|
||||
@@ -10,6 +10,13 @@ const range = z.strictObject({ offset: uint, bytes: uint });
|
||||
export const MAX_INSPECT_ELF_NOTE_FILE_BYTES = 536870912;
|
||||
/** Hard ceiling on decoded note entries across every declared table. */
|
||||
export const MAX_INSPECT_ELF_NOTE_ENTRIES = 256;
|
||||
/**
|
||||
* Default note entry budget. Distribution glibc builds carry dozens of
|
||||
* SystemTap `.note.stapsdt` probes. Ubuntu 26.04's libc.so.6 has 82 distinct
|
||||
* notes, examined as 85 entries because its allocated notes appear in both the
|
||||
* program and section tables; the default admits that with room to spare.
|
||||
*/
|
||||
export const DEFAULT_INSPECT_ELF_NOTE_ENTRIES = 128;
|
||||
|
||||
export const ELF_NOTE_TYPE_NAMES = [
|
||||
"gnu_abi_tag",
|
||||
@@ -106,7 +113,7 @@ export const inspectElfNotesInputSchema = z.strictObject({
|
||||
.int()
|
||||
.min(1)
|
||||
.max(MAX_INSPECT_ELF_NOTE_ENTRIES)
|
||||
.default(32)
|
||||
.default(DEFAULT_INSPECT_ELF_NOTE_ENTRIES)
|
||||
.describe(
|
||||
"Maximum note entries to examine across every table; exceeding the budget fails without partial success",
|
||||
),
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
elfDebugLinkSchema,
|
||||
inspectElfDebugLinkInputSchema,
|
||||
} from "../../domain/native/elfDebugLink.js";
|
||||
import { gnuBuildIdNote } from "./ElfNotes.fixture.js";
|
||||
import { elfNote, gnuBuildIdNote } from "./ElfNotes.fixture.js";
|
||||
import { parseElfNotes } from "./ElfNoteParser.js";
|
||||
import { readElfImage } from "../../domain/native/elfImage.js";
|
||||
import {
|
||||
@@ -263,6 +263,24 @@ it("fails the note entry budget instead of returning a partial build-id", () =>
|
||||
).toThrow(ParseFailureError);
|
||||
});
|
||||
|
||||
it("reads the build-id beside glibc's SystemTap probe notes by default", () => {
|
||||
const probes = Array.from({ length: 79 }, () =>
|
||||
elfNote("stapsdt", 3, Buffer.alloc(40)),
|
||||
);
|
||||
const report = parse(
|
||||
elfDebugLinkFixture({
|
||||
notes: Buffer.concat([
|
||||
gnuBuildIdNote(FIXTURE_BUILD_ID_HEX, true),
|
||||
...probes,
|
||||
]),
|
||||
}),
|
||||
);
|
||||
expect(report.build_id).toMatchObject({
|
||||
status: "observed",
|
||||
hex: FIXTURE_BUILD_ID_HEX,
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves parent-directory segments and omits a slash name", () => {
|
||||
const preserved = parse(elfDebugLinkFixture(), {}, "/var/tmp/../lib/prog");
|
||||
expect(
|
||||
|
||||
@@ -664,6 +664,21 @@ it("fails when the entry budget is exhausted", () => {
|
||||
).toThrow(ParseFailureError);
|
||||
});
|
||||
|
||||
it("reads a glibc-sized note table with the default entry budget", () => {
|
||||
// Ubuntu's libc.so.6 has 79 SystemTap probe notes beside its build-id, ABI
|
||||
// tag and GNU property notes; this table has the first two and the probes.
|
||||
const probes = Array.from({ length: 79 }, () =>
|
||||
elfNote("stapsdt", 3, Buffer.alloc(40)),
|
||||
);
|
||||
const report = parse(
|
||||
elfNoteFixture({
|
||||
ownership: "section",
|
||||
notes: Buffer.concat([gnuBuildIdNote(), gnuAbiTagNote(), ...probes]),
|
||||
}),
|
||||
);
|
||||
expect(report.entries).toHaveLength(81);
|
||||
});
|
||||
|
||||
it("keeps unsafe table offsets ahead of unsupported extended numbering", () => {
|
||||
const bytes = elfExtendedSectionCountFixture();
|
||||
bytes.writeBigUInt64LE(0xffffffffffffffffn, 32);
|
||||
|
||||
Reference in new issue
Block a user