Skip to content

Security fixes: trace buffer, exec buffer, debug IP layout (leet audit) - #10018

Open
stsoe wants to merge 5 commits into
Xilinx:masterfrom
stsoe:leet
Open

Security fixes: trace buffer, exec buffer, debug IP layout (leet audit)#10018
stsoe wants to merge 5 commits into
Xilinx:masterfrom
stsoe:leet

Conversation

@stsoe

@stsoe stsoe commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Problem solved by the commit

Four security vulnerabilities identified by internal AI-assisted security
audit (leet campaign, reporter: obittner).

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

  • AIESW-42831 xrt/xrt++/xrtexec.cpp: exec_cu_command::add() wrote
    past a fixed 4096-byte exec BO when idx >= ~1019 — no bounds check on
    the caller-supplied register index.
  • AIESW-42830 xrt/xrt++/xrtexec.cpp: exec_write_command::add()
    pre-incremented ert_pkt->count past the 1024-word exec buffer after
    512 calls — no check that two more words fit before writing.
  • AIESW-42778 core/pcie/linux/shim.cpp: xclReadTraceData() used a
    fixed-size stack VLA but iterated numSamples * wordsPerSample words
    with no bound against the buffer capacity; xclGetTraceBufferInfo()
    passed the device-supplied sample count unclamped.
  • AIESW-42777 core/pcie/linux/debug.cpp: getIPCountAddrNames()
    iterated map->m_count entries (xclbin-controlled uint16_t) from a
    64 KiB stack buffer with no check against actual bytes read from sysfs.

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

  • 42831/42830: Throw before writing when the exec buffer is full, using
    bo_cache::bo_size to derive the word limit at compile time.
  • 42778: Clamp traceSamples to MAX_TRACE_NUMBER_SAMPLES_FIFO in
    xclGetTraceBufferInfo() and clamp numWords to traceBufWordSz in
    xclReadTraceData(). Note: the primary caller already clamps upstream;
    these are defence-in-depth guards at the shim boundary.
  • 42777: Derive max_entries from bytes_read using offsetof() and
    sizeof(debug_ip_data); clamp loop to min(m_count, max_entries).

Risks (if any) associated the changes in the commit

Low. All changes add guards on paths that are either off by default
(trace profiling) or require a crafted xclbin to trigger. Happy paths
are unaffected.

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

Compile-verified. Please run exec command tests and debug IP status
tests (xclDebugReadIPStatus) on PCIe devices.

Documentation impact (if any)

None.

stsoe and others added 5 commits August 28, 2026 09:46
Reject indices that exceed the 4096-byte exec buffer capacity before
writing. Uses bo_cache::bo_size to derive the word limit at compile time.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Soren Soe <2106410+stsoe@users.noreply.github.com>
Reject add() calls that would exceed the 4096-byte exec buffer before
pre-incrementing count and writing addr/value. Guards both the buffer
bound and the 11-bit ert_pkt::count field wrap.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Soren Soe <2106410+stsoe@users.noreply.github.com>
Clamp traceSamples to MAX_TRACE_NUMBER_SAMPLES_FIFO in
xclGetTraceBufferInfo() and clamp numWords to traceBufWordSz in
xclReadTraceData() before the read loop.

The primary caller (TraceFifoFull::readTrace()) already clamps nSamples
to TRACE_NUMBER_SAMPLES (8192) before calling either function, so the
overflow is not reachable through that path. The clamps are retained as
defence-in-depth at the shim boundary for any future or direct callers
that do not apply the same guard upstream.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Soren Soe <2106410+stsoe@users.noreply.github.com>
Clamp iteration count to the number of debug_ip_data entries that
actually fit within the bytes read from sysfs. Uses offsetof() to
compute the header size and derives max_entries from bytes_read, then
takes std::min with the xclbin-supplied m_count before looping.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Soren Soe <2106410+stsoe@users.noreply.github.com>
Fix signed/unsigned type mismatches in shim.cpp and xrtexec.cpp.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Soren Soe <2106410+stsoe@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

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

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.

1 participant