CodeQL Fix OOB reads in SectionVenderMetadata - #9965
Closed
stsoe wants to merge 1 commit into
Closed
Conversation
#### Problem solved by the commit Three CWE-125 heap OOB reads in SectionVenderMetadata.cxx where attacker-controlled vender_metadata mpo_name and image offset/size fields were used without bounds checking: - AIESW-41110: mpo_name used as raw pointer offset in the TRACE block of copyBufferUpdateMetadata() without going through bounded_mpo_cstr(), unlike writeMetadata() which already used it correctly. - AIESW-41108/41109: m_image_offset and m_image_size used to read image data at line 140 with no bounds check against _origSectionSize. #### Bug / issue (if any) fixed, which PR introduced the bug, how it was discovered Jira: - AIESW-41108 - AIESW-41109 - AIESW-41110 CodeQL alerts Xilinx#154-Xilinx#156 (amd-psirt/xclbin-parser-oob, HIGH severity). Missed by bb1791f (SWSPLAT-30717) which fixed writeMetadata() but left the TRACE path and image copy in copyBufferUpdateMetadata() unguarded, and writeObjImage() without image bounds checking. #### How problem was solved, alternative solutions (if any) and why they were rejected TRACE path: replaced raw `pHdr + mpo_name` with bounded_mpo_cstr(pHdr, pHdr->mpo_name, _origSectionSize). sDefault fallback string: replaced raw `pHdr + sizeof(vender_metadata) + mpo_name` with bounded_mpo_cstr(pHdr, pHdr->mpo_name, _origSectionSize), also fixing the same double-offset bug found in all other Section* files where sizeof(struct) was incorrectly added on top of already-absolute mpo offsets. Image copy: added overflow-safe uint64_t bounds check before the _buffer.write() in copyBufferUpdateMetadata() and writeObjImage(). #### Risks (if any) associated the changes in the commit Low. Only rejects malformed xclbins; behavior for well-formed inputs is unchanged. #### What has been tested and how, request additional testing if necessary Built xclbinutil successfully. #### Documentation impact (if any) None Signed-off-by: Soren Soe <2106410+stsoe@users.noreply.github.com> Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
|
clang-tidy review says "All clean, LGTM! 👍" |
xfreid
approved these changes
Aug 5, 2026
Collaborator
Author
|
Replaced by #9966 |
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.
Problem solved by the commit
Three CWE-125 heap OOB reads in SectionVenderMetadata.cxx where attacker-controlled vender_metadata mpo_name and image offset/size fields were used without bounds checking:
AIESW-41110: mpo_name used as raw pointer offset in the TRACE block of copyBufferUpdateMetadata() without going through bounded_mpo_cstr(), unlike writeMetadata() which already used it correctly.
AIESW-41108/41109: m_image_offset and m_image_size used to read image data at line 140 with no bounds check against _origSectionSize.
Bug / issue (if any) fixed, which PR introduced the bug, how it was discovered
Jira:
CodeQL alerts #154-#156 (amd-psirt/xclbin-parser-oob, HIGH severity). Missed by bb1791f (SWSPLAT-30717) which fixed writeMetadata() but left the TRACE path and image copy in copyBufferUpdateMetadata() unguarded, and writeObjImage() without image bounds checking.
How problem was solved, alternative solutions (if any) and why they were rejected
TRACE path: replaced raw
pHdr + mpo_namewithbounded_mpo_cstr(pHdr, pHdr->mpo_name, _origSectionSize).
sDefault fallback string: replaced raw `pHdr + sizeof(vender_metadata)
Image copy: added overflow-safe uint64_t bounds check before the _buffer.write() in copyBufferUpdateMetadata() and writeObjImage().
Risks (if any) associated the changes in the commit
Low. Only rejects malformed xclbins; behavior for well-formed inputs is unchanged.
What has been tested and how, request additional testing if necessary
Built xclbinutil successfully.
Documentation impact (if any)
None