netapp: fix heap-buffer-overflow in ONTAP TLV label parsing - #3816
Merged
Conversation
The TLV parser in netapp_get_ontap_labels() trusts the length field from the C2 log data without bounds checking. A crafted log with a large TLV length (e.g. 0xFFFF) causes out-of-bounds reads when computing offsets for subsequent TLV entries. Add bounds checks after each TLV length computation to ensure offsets stay within ONTAP_C2_LOG_SIZE. Also cap the copy length in ontap_labels_to_str() to ONTAP_LABEL_LEN-1 to prevent destination buffer overflow. Signed-off-by: Utkarsh Singh <utsingh@redhat.com>
Collaborator
|
Thanks! TBH this parser should be completely rewritten, but then there is much more fun stuff to do :) |
Contributor
Author
|
TS :-) |
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.
The TLV parser in
netapp_get_ontap_labels()trusts the length field from theC2 vendor log data without bounds checking. A crafted or corrupted log with a
large TLV length (e.g.
0xFFFF) causes out-of-bounds heap reads when computingoffsets for subsequent TLV entries (
netapp-nvme.c:232).Additionally,
ontap_labels_to_str()passes the uncheckedlabel_lendirectlyas the copy count, which can overflow the fixed-size
ONTAP_LABEL_LEN(260 byte)destination buffer.
Fix
within
ONTAP_C2_LOG_SIZE(4096)size_tbefore multiplying by 4 to prevent integer overflowontap_labels_to_str()toONTAP_LABEL_LEN - 1label_len,i,jfrominttosize_tfor unsigned arithmeticVerification
Tested with a crafted 4096-byte C2 log binary with
*(uint16_t *)&log_data[34] = 0xFFFF(TLV length = 0xFFFF * 4 = 262140):netapp_get_ontap_labels()— 210,232 bytes past the allocated block