fs/cromfs: Fix stale cache read in read() fast path - #19811
Merged
Conversation
cromfs_read()'s fast path decompresses a block directly into the caller's buffer whenever a read reaches a block at its start and the caller has room for the whole decompressed block, bypassing the per-file decompression cache (ff_buffer). It nonetheless marked that block as cached by setting ff_offset, without ever writing ff_buffer itself. A later read of the same block that fell onto the slow path trusted that false cache tag, skipped decompression, and copied from ff_buffer without it ever having been populated for that block. A repeated identical fast-path read of the same block hit the same false tag and skipped decompression entirely, leaving the caller's buffer untouched and returning whatever was already there. Fixed by having the fast path only read the cache, never populate it: reuse ff_buffer when a prior slow-path read already cached the same block, otherwise decompress straight into the caller's buffer without touching ff_offset/ff_buffer. Co-authored-by: Pavlo Assisted-by: Claude Code:claude-sonnet-5 Signed-off-by: alexcekay <alexander@auterion.com>
alexcekay
requested review from
Donny9,
davids5,
pkarashchenko and
xiaoxiang781216
as code owners
August 12, 2026 13:27
xiaoxiang781216
approved these changes
Aug 12, 2026
acassis
approved these changes
Aug 12, 2026
Contributor
|
@alexcekay could you please add this cromfs_test to apps/testing/ ? |
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.
Summary
cromfs_read()'s fast path decompresses a block directly into the caller's buffer whenever a read reaches a block at its start and the caller has room for the whole decompressed block, bypassing the per-file decompression cache (ff_buffer). It nonetheless marked that block as cached by setting ff_offset, without ever writing ff_buffer itself.
A later read of the same block that fell onto the slow path trusted that false cache tag, skipped decompression, and copied from ff_buffer without it ever having been populated for that block. A repeated identical fast-path read of the same block hit the same false tag and skipped decompression entirely, leaving the caller's buffer untouched and returning whatever was already there.
Fixed by having the fast path only read the cache, never populate it: reuse ff_buffer when a prior slow-path read already cached the same block, otherwise decompress straight into the caller's buffer without touching ff_offset/ff_buffer.
Detection
Impact
Testing
file_size: Usestatto check that CROMFS reports correct file sizefull_read: Read the whole CROMFS file into one buffer and check that it contains the expected datachunked_read: Read file with different chunk sizes and check the chunks contain the expected dataseek_and_reread: Seek to various offsets and do a chunked read. Check that chunks contain the expected dataregression_double_visit: Read using the fast path, afterwards using the slow path and afterwards using the fast path again. Checks that the fast path correctly uses the cache set by the slow pathregression_repeated_fast_path: Read the same block twice using the fast path. Ensure that this does not cause cache problemseof_handling: Read and seek near EOFTest result without fix:
Test result with fix: