Skip to content

CodeQL Fix OOB reads in SectionVenderMetadata - #9965

Closed
stsoe wants to merge 1 commit into
Xilinx:masterfrom
stsoe:codeql-xclbinutil-5
Closed

CodeQL Fix OOB reads in SectionVenderMetadata#9965
stsoe wants to merge 1 commit into
Xilinx:masterfrom
stsoe:codeql-xclbinutil-5

Conversation

@stsoe

@stsoe stsoe commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

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 #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_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

 #### 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>
@stsoe
stsoe requested a review from xfreid as a code owner August 5, 2026 22:39
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@stsoe

stsoe commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

Replaced by #9966

@stsoe stsoe closed this Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants