Skip to content

CodeQL Fix OOB reads in SectionAIEResourcesBin - #9961

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

CodeQL Fix OOB reads in SectionAIEResourcesBin#9961
stsoe wants to merge 1 commit into
Xilinx:masterfrom
stsoe:codeql-xclbinutil-1

Conversation

@stsoe

@stsoe stsoe commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Problem solved by the commit

Four CWE-125 heap OOB reads in copyBufferUpdateMetadata() where aie_resources_bin mpo_* fields (mpo_name, mpo_version, m_start_column, m_num_columns) were used as raw pointer offsets without bounds checking when computing sDefault fallback strings, bypassing the bounded_mpo_cstr() guard added in bb1791f.

Two additional CWE-125 OOB reads where m_image_offset and m_image_size were used without bounds checking in both copyBufferUpdateMetadata() and writeObjImage() before reading image data.

Bug / issue (if any) fixed, which PR introduced the bug, how it was discovered

Jira tickets:

  • AIESW-41124
  • AIESW-41125
  • AIESW-41126
  • AIESW-41127
  • AIESW-41128
  • AIESW-41129

CodeQL alerts #135-#140 (amd-psirt/xclbin-parser-oob, HIGH severity). The sDefault reads were missed by bb1791f (SWSPLAT-30717), which protected the TRACE() and writeMetadata() paths but not the fallback default value paths in copyBufferUpdateMetadata(). The image offset/size checks were never added to writeObjImage().

How problem was solved, alternative solutions (if any) and why they were rejected

Replaced the four raw sDefault pointer calculations with bounded_mpo_cstr(pHdr, pHdr->field, origSectionSize). This also fixes a pre-existing double-offset bug in the original code: the sDefault expressions incorrectly added sizeof(aie_resources_bin) on top of the mpo* field value, but mpo_* fields already store absolute offsets from pHdr (sizeof is baked in at write time), so the fallback pointer was pointing past the actual string.

Added explicit uint64_t overflow-safe bounds checks for m_image_offset + m_image_size against section size in both copyBufferUpdateMetadata() and writeObjImage().

Risks (if any) associated the changes in the commit

Low. The sDefault path is only taken when the JSON metadata stream omits a key; the double-offset bug meant the fallback was producing wrong values anyway. The image bounds checks only reject malformed xclbins.

What has been tested and how, request additional testing if necessary

Built xclbinutil successfully. Recommend testing xclbinutil --input with a crafted xclbin containing OOB mpo offsets and verifying it throws rather than reading past the buffer.

Documentation impact (if any)

None

 #### Problem solved by the commit
Four CWE-125 heap OOB reads in copyBufferUpdateMetadata() where
aie_resources_bin mpo_* fields (mpo_name, mpo_version, m_start_column,
m_num_columns) were used as raw pointer offsets without bounds
checking when computing sDefault fallback strings, bypassing the
bounded_mpo_cstr() guard added in bb1791f.

Two additional CWE-125 OOB reads where m_image_offset and m_image_size
were used without bounds checking in both copyBufferUpdateMetadata()
and writeObjImage() before reading image data.

 #### Bug / issue (if any) fixed, which PR introduced the bug, how it was discovered
Jira tickets:
- AIESW-41124
- AIESW-41125
- AIESW-41126
- AIESW-41127
- AIESW-41128
- AIESW-41129

CodeQL alerts Xilinx#135-Xilinx#140 (amd-psirt/xclbin-parser-oob, HIGH severity).
The sDefault reads were missed by bb1791f (SWSPLAT-30717), which
protected the TRACE() and writeMetadata() paths but not the fallback
default value paths in copyBufferUpdateMetadata(). The image
offset/size checks were never added to writeObjImage().

 #### How problem was solved, alternative solutions (if any) and why they were rejected
Replaced the four raw sDefault pointer calculations with
bounded_mpo_cstr(pHdr, pHdr->field, _origSectionSize). This also
fixes a pre-existing double-offset bug in the original code: the
sDefault expressions incorrectly added sizeof(aie_resources_bin) on
top of the mpo_* field value, but mpo_* fields already store absolute
offsets from pHdr (sizeof is baked in at write time), so the fallback
pointer was pointing past the actual string.

Added explicit uint64_t overflow-safe bounds checks for
m_image_offset + m_image_size against section size in both
copyBufferUpdateMetadata() and writeObjImage().

 #### Risks (if any) associated the changes in the commit
Low. The sDefault path is only taken when the JSON metadata stream
omits a key; the double-offset bug meant the fallback was producing
wrong values anyway. The image bounds checks only reject malformed
xclbins.

 #### What has been tested and how, request additional testing if necessary
Built xclbinutil successfully. Recommend testing xclbinutil --input
with a crafted xclbin containing OOB mpo offsets and verifying it
throws rather than reading past the buffer.

 #### 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 21:10
@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