Fix intermittent VCI signature failure in cart coherency MAM#623
Closed
implr wants to merge 1 commit into
Closed
Conversation
tape_set_cart_coherency() builds the Volume Coherency Information MAM
parameter in an uninitialized stack buffer and writes byte 36 (the byte
right after the 4-char "LTFS" signature) nowhere. The signature is copied
with arch_strncpy(coh_data + 32, "LTFS", 5, 4), which on POSIX is
strncpy(dst, "LTFS", 4); since the count equals strlen("LTFS"), no
terminating NUL is written, leaving byte 36 as uninitialized stack data.
tape_get_cart_coherency() validates the signature with
strncmp(coh_data + 32, "LTFS", sizeof("LTFS")), i.e. 5 bytes, so it
requires byte 36 to be 0x00. When the leftover stack byte happens to be
non-zero, the read-back fails with LTFS12062W, the coherency data for the
partition is discarded (LTFS11016W/LTFS11017W), and the next mount falls
back to a full medium consistency check. Because the value depends on
stack contents at write time, the failure is intermittent.
This was introduced in commit 1f1ee3c (LinearTapeFileSystem#575), which replaced the previous
NUL-terminating copy with the 4-byte strncpy. Windows is unaffected
because arch_strncpy maps to strncpy_s, which NUL-terminates.
Zero the buffer before populating it so byte 36 (and any other gap) is
deterministic, restoring a valid signature on the medium.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PqvvYQzkFL6nNFgbJ9kSuq
Member
|
Thanks for reporting Claude's finding, we'll go with @Piloalucard 's approach on PR #624 This issue could have been a good learning experience and good first issue for human committers to get a PR merged, Gen AI tools can be great to do these sort of findings but there is no experience earned if you let it do all the work. Kindly complete the PR Template for the next time. |
Author
|
Ouch, I did not intend to submit this without de-sloppifying it first, it was an accident. Sincere apologies for wasting your time. |
Member
|
No worries at all, and sorry if my message seemed a bit harsh.
I'm gonna start using that term haha! please consider contributing with de-sloppified PRs 😄 |
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.
tape_set_cart_coherency() builds the Volume Coherency Information MAM parameter in an uninitialized stack buffer and writes byte 36 (the byte right after the 4-char "LTFS" signature) nowhere. The signature is copied with arch_strncpy(coh_data + 32, "LTFS", 5, 4), which on POSIX is strncpy(dst, "LTFS", 4); since the count equals strlen("LTFS"), no terminating NUL is written, leaving byte 36 as uninitialized stack data.
tape_get_cart_coherency() validates the signature with strncmp(coh_data + 32, "LTFS", sizeof("LTFS")), i.e. 5 bytes, so it requires byte 36 to be 0x00. When the leftover stack byte happens to be non-zero, the read-back fails with LTFS12062W, the coherency data for the partition is discarded (LTFS11016W/LTFS11017W), and the next mount falls back to a full medium consistency check. Because the value depends on stack contents at write time, the failure is intermittent.
This was introduced in commit 1f1ee3c (#575), which replaced the previous NUL-terminating copy with the 4-byte strncpy. Windows is unaffected because arch_strncpy maps to strncpy_s, which NUL-terminates.
Zero the buffer before populating it so byte 36 (and any other gap) is deterministic, restoring a valid signature on the medium.
Claude-Session: https://claude.ai/code/session_01PqvvYQzkFL6nNFgbJ9kSuq
Summary of changes
This pull request includes following changes or fixes.
Description
Please include relevant motivation and context. List any dependencies that are required for this change.
Fixes #issue_no
Type of change
Please delete items that are not relevant.
Checklist: