bcachefs: guard dirent to_text against unvalidated names - #1202
Open
matthiasgoergens wants to merge 2 commits into
Open
bcachefs: guard dirent to_text against unvalidated names#1202matthiasgoergens wants to merge 2 commits into
matthiasgoergens wants to merge 2 commits into
Conversation
bch2_dirent_to_text() may be called on unvalidated keys: the sb validation error path prints a corrupt clean section's journal entries, and a dirent key with a truncated value or an inflated name length reached the printer, which then read past the key in prt_bytes(). Return early with an invalid marker when the key header is truncated (bkey_val_u64s() underflows when u64s < BKEY_U64s, so the header length is checked explicitly) or the value is smaller than struct bch_dirent, and check the name and lookup-name extents against the value bounds before printing. The extent guards check the length against the value size before computing the sum: qstr.len is u32 and bch2_dirent_name_bytes() can underflow to 0xffffffff, so the sum would wrap in 32-bit arithmetic. The guards bound extents against the key's declared u64s; the callers' walkers bound the declared extent to actual storage. Found by fuzzing the offline tools with AFL++/ASAN.
This was referenced Aug 17, 2026
Tests the truncated-key, underflowed-name, and casefold overrun paths, all of which previously crashed.
matthiasgoergens
force-pushed
the
fix/dirent-to-text-guards
branch
from
August 18, 2026 09:28
eec0523 to
2a53d33
Compare
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.
bch2_dirent_to_text() may be called on unvalidated keys: the sb
validation error path prints a corrupt clean section's journal entries,
and a dirent key with a truncated value or an inflated name length read
past the key in prt_bytes().
Return early with an invalid marker for truncated keys, and check the
name and lookup-name extents against the value bounds before printing.
The extent guards check the length before computing the sum, so the sum
cannot wrap (qstr.len is u32 and bch2_dirent_name_bytes() can underflow).
Adds kunit tests for the truncated, underflowed-name, and casefold
overrun paths, passing under UML.
Found by fuzzing the offline tools with AFL++/ASAN.
The bcachefs-tools tree has the same fix in
koverstreet/bcachefs-tools#877.