Skip to content

heap: support glibc >= 2.43 (fastbins were removed) - #1231

Merged
hugsy merged 2 commits into
hugsy:mainfrom
nkbeast:fix/glibc-2.43-no-fastbins
Aug 20, 2026
Merged

hugsy merged 2 commits into
hugsy:mainfrom
nkbeast:fix/glibc-2.43-no-fastbins

Conversation

@nkbeast

@nkbeast nkbeast commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1225

Problem

glibc 2.43 removed the fastbin infrastructure (upstream commit bb5a4f5),
so struct malloc_state no longer contains fastbinsY[NFASTBINS] nor
have_fastchunks. GEF's GlibcArena.malloc_state_t() was still parsing
the old layout, so on glibc >= 2.43 every heap command reading the arena
showed garbage (heap arenas with wrong top/last_remainder, broken
heap bins, ...).

Fix

Made the arena layout version-aware:

  • GlibcArena.has_fastbins(): fastbins exist only on glibc < 2.43
  • GlibcArena.malloc_state_t(): no longer defines fastbinsY /
    have_fastchunks on glibc >= 2.43
  • GlibcArena.fastbinsY returns an empty array, fastbin() returns
    None, so existing callers behave safely
  • heap bins fast exits with a clear message instead of parsing
    corrupted data

Tests

Added HeapCommandNoFastbins (tests/commands/heap.py): it forces
gef.libc._version = (2, 43) regardless of the host glibc and verifies
the 2.43 arena layout has no fastbins and heap bins fast reports them
as unsupported.

The initial CI run failed on fedora-rawhide (glibc 2.44) for two
reasons, both fixed in the follow-up commit:

  • HeapCommandFastBins::test_cmd_heap_bins_fast was missing the
    skipif(is_glibc_ge(2, 43)) marker that all the other fastbin tests
    use, and failed on a real no-fastbins glibc
  • CanaryCommand::test_cmd_canary asserted that the stack canary equals
    the AT_RANDOM-derived value; on glibc >= 2.44 the canary is no
    longer derived from AT_RANDOM, so the test is skipped there (the
    canary command itself still reads the right value from the TLS slot)

Verified locally against glibc 2.41 (Debian), 2.43 (fedora:44) and
2.44 (fedora:rawhide) containers, plus pre-commit run --all-files.

glibc 2.43 removed the fastbins from the malloc implementation (commit
bb5a4f5). The malloc_state struct no longer contains the fastbinsY
array nor the have_fastchunks field, so every heap command parsing the
arena layout (heap arenas, heap bins, ...) was reading the fields at
wrong offsets and displaying garbage.

This commit makes the arena layout version-aware:

- GlibcArena.malloc_state_t() no longer defines fastbinsY/have_fastchunks
  on glibc >= 2.43
- GlibcArena.fastbinsY returns an empty array and fastbin() returns None
  when fastbins are not supported
- "heap bins fast" fails gracefully with a clear message instead of
  parsing corrupted data

Fixes hugsy#1225
@github-actions

Copy link
Copy Markdown

🤖 Coverage update for a9be982 🟢

Old New
Commit 87f359b a9be982
Score 70.1989% 70.1989% (0)

hugsy
hugsy previously approved these changes Aug 14, 2026

@hugsy hugsy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Nicely done ! LGTM if all tests pass

…ad canary)

- tests/commands/heap.py: skip test_cmd_heap_bins_fast on glibc >= 2.43,
  matching the other fastbin tests skipped since the fastbins were removed
- tests/commands/canary.py: skip test_cmd_canary on glibc >= 2.44, where
  the stack canary is no longer derived from AT_RANDOM (the canary value
  at fs+0x28 is now random and no longer matches original_canary)
- gef.py: fix ruff-format line length in GlibcHeapFastbinsYCommand
@github-actions

Copy link
Copy Markdown

🤖 Coverage update for 961c7e6 🟢

Old New
Commit 87f359b 961c7e6
Score 70.1989% 70.1989% (0)

Copilot AI 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.

Pull request overview

This PR updates GEF’s glibc heap arena parsing to handle glibc ≥ 2.43 where fastbins were removed, preventing incorrect malloc_state decoding that previously caused heap commands (arenas/bins) to display corrupted data on newer glibc versions.

Changes:

  • Add a version-aware GlibcArena.has_fastbins() gate and update malloc_state_t() so fastbinsY / have_fastchunks are not parsed on glibc ≥ 2.43.
  • Make heap bins fast explicitly unsupported when fastbins are absent, avoiding mis-parsing.
  • Adjust/extend tests: skip fastbin tests on glibc ≥ 2.43, add coverage for the no-fastbins layout, and skip the canary derivation assertion on glibc ≥ 2.44.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
gef.py Makes arena layout parsing conditional on glibc version and blocks heap bins fast on glibc ≥ 2.43.
tests/commands/heap.py Skips fastbin test on glibc ≥ 2.43 and adds a new test class validating the “no fastbins” behavior/layout.
tests/commands/canary.py Skips test_cmd_canary on glibc ≥ 2.44 due to changed canary derivation assumptions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@hugsy

hugsy commented Aug 20, 2026

Copy link
Copy Markdown
Owner

All good, merging. Thanks @nkbeast

@hugsy
hugsy merged commit 49c07dc into hugsy:main Aug 20, 2026
14 checks passed
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.

[Bug] Glibc 2.43 removed fastbins

3 participants