heap: support glibc >= 2.43 (fastbins were removed) - #1231
Merged
Merged
Conversation
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
hugsy
previously approved these changes
Aug 14, 2026
hugsy
left a comment
Owner
There was a problem hiding this comment.
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
hugsy
approved these changes
Aug 18, 2026
There was a problem hiding this comment.
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 updatemalloc_state_t()sofastbinsY/have_fastchunksare not parsed on glibc ≥ 2.43. - Make
heap bins fastexplicitly 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.
Owner
|
All good, merging. Thanks @nkbeast |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1225
Problem
glibc 2.43 removed the fastbin infrastructure (upstream commit
bb5a4f5),so
struct malloc_stateno longer containsfastbinsY[NFASTBINS]norhave_fastchunks. GEF'sGlibcArena.malloc_state_t()was still parsingthe old layout, so on glibc >= 2.43 every heap command reading the arena
showed garbage (
heap arenaswith wrongtop/last_remainder, brokenheap bins, ...).Fix
Made the arena layout version-aware:
GlibcArena.has_fastbins(): fastbins exist only on glibc < 2.43GlibcArena.malloc_state_t(): no longer definesfastbinsY/have_fastchunkson glibc >= 2.43GlibcArena.fastbinsYreturns an empty array,fastbin()returnsNone, so existing callers behave safelyheap bins fastexits with a clear message instead of parsingcorrupted data
Tests
Added
HeapCommandNoFastbins(tests/commands/heap.py): it forcesgef.libc._version = (2, 43)regardless of the host glibc and verifiesthe 2.43 arena layout has no fastbins and
heap bins fastreports themas unsupported.
The initial CI run failed on
fedora-rawhide(glibc 2.44) for tworeasons, both fixed in the follow-up commit:
HeapCommandFastBins::test_cmd_heap_bins_fastwas missing theskipif(is_glibc_ge(2, 43))marker that all the other fastbin testsuse, and failed on a real no-fastbins glibc
CanaryCommand::test_cmd_canaryasserted that the stack canary equalsthe
AT_RANDOM-derived value; on glibc >= 2.44 the canary is nolonger derived from
AT_RANDOM, so the test is skipped there (thecanarycommand 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.