Skip to content

Harden index XML parsing against malformed input - #614

Open
matejk wants to merge 2 commits into
LinearTapeFileSystem:release/v2.4.9.0from
matejk:fix/index-parsing-hardening
Open

Harden index XML parsing against malformed input#614
matejk wants to merge 2 commits into
LinearTapeFileSystem:release/v2.4.9.0from
matejk:fix/index-parsing-hardening

Conversation

@matejk

@matejk matejk commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Defects reachable from a crafted or truncated index while mounting a cartridge. Two commits:

  • Recursion depth bound: _xml_parse_dirtree recurses once per directory level and the index reader sets XML_PARSE_HUGE, which removes libxml2's own nesting limit, so deeply nested <directory> elements could overflow the C stack during mount. The bound (5051) is a stack-safety guard, not an LTFS format limit — the format defines no maximum depth — and is set well above any tree that fits in a conventional PATH_MAX.
  • NULL dereferences and unchecked allocations: xml_next_tag passed a possibly-NULL libxml2 node name to strcmp; decode_entry_name wrote to an allocation of attacker-controlled size without a NULL check; the glob_patterns growth dereferenced an unchecked realloc; an ltfs.vendor.IBM.immutable/appendonly xattr with an empty self-closing value passed NULL to strcmp when deciding WORM flags, crashing the mount.

@matejk
matejk force-pushed the fix/index-parsing-hardening branch from d031cd7 to 9293668 Compare June 17, 2026 20:35

@vandelvan vandelvan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thank you for your contributions

@madjesc madjesc left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🔥 💀

@rangelmx
rangelmx changed the base branch from main to release/v2.4.9.0 July 29, 2026 19:49
@matejk
matejk force-pushed the fix/index-parsing-hardening branch from 9293668 to 8d3c6e3 Compare August 17, 2026 20:10
matejk added 2 commits August 17, 2026 22:21
XML_PARSE_HUGE disables libxml2's nesting limit, so a crafted index could
overflow the C stack. Stack-safety bound, not a format limit.
NULL node name in xml_next_tag, unchecked malloc in decode_entry_name,
unchecked realloc of glob_patterns, NULL value of the WORM xattrs.
@matejk
matejk force-pushed the fix/index-parsing-hardening branch 2 times, most recently from 09c786e to 9effc58 Compare August 17, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants