diff --git a/docs/elf-notes.md b/docs/elf-notes.md index 95e28b775d..4e12308352 100644 --- a/docs/elf-notes.md +++ b/docs/elf-notes.md @@ -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 diff --git a/docs/guides/native/elf-debug-link.md b/docs/guides/native/elf-debug-link.md index c96a959adf..892e6f08f5 100644 --- a/docs/guides/native/elf-debug-link.md +++ b/docs/guides/native/elf-debug-link.md @@ -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 diff --git a/src/domain/native/elfDebugLink.ts b/src/domain/native/elfDebugLink.ts index e0342f7c27..46d3a0857f 100644 --- a/src/domain/native/elfDebugLink.ts +++ b/src/domain/native/elfDebugLink.ts @@ -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", ), diff --git a/src/domain/native/elfNotes.ts b/src/domain/native/elfNotes.ts index dab6359055..aa9858adc1 100644 --- a/src/domain/native/elfNotes.ts +++ b/src/domain/native/elfNotes.ts @@ -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", ), diff --git a/src/native/elf/ElfDebugLink.test.ts b/src/native/elf/ElfDebugLink.test.ts index 369c4fa352..c14d7e0048 100644 --- a/src/native/elf/ElfDebugLink.test.ts +++ b/src/native/elf/ElfDebugLink.test.ts @@ -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( diff --git a/src/native/elf/ElfNoteParser.test.ts b/src/native/elf/ElfNoteParser.test.ts index decf84c4b6..3eb62e83ba 100644 --- a/src/native/elf/ElfNoteParser.test.ts +++ b/src/native/elf/ElfNoteParser.test.ts @@ -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);