Skip to content

fix(amdsmi): keep the memory partition name inside the caller's buffer - #12986

Merged
adam360x merged 3 commits into
developfrom
users/adam360x/ROCM-30433
Oct 8, 2026
Merged

adam360x merged 3 commits into
developfrom
users/adam360x/ROCM-30433

Conversation

@adam360x

@adam360x adam360x commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

  • TheRock's ASAN nightly aborts amdsmitst in GpuFunctionalReadWrite.TestMemoryPartitionReadWrite with a stack-buffer-overflow (MI325X). The test passes a 2-byte buffer to amdsmi_get_gpu_memory_partition() and expects "insufficient size".
  • The bug is in the library, not the test: rsmi_dev_memory_partition_get() copied up to len characters and then wrote the terminator after them, so any buffer of len bytes or less got one byte written past its end.
  • Present since 2023 in both copies of the function: amd-smi's bundled rocm_smi and rocm-smi-lib.

Technical Details

  • rocm_smi.cc in amd-smi and in rocm-smi-lib: copy at most len - 1 characters, as the compute-partition getter already does. Status codes are unchanged; a short buffer still gets "insufficient size", now with a truncated, terminated name.
  • New read-only test GpuFunctionalReadOnly.TestMemoryPartitionRead
    • On each GPU that reports a memory partition, reads it into buffers of 1, 2, name-length and name-length + 1 bytes, each followed by a guard byte, and checks the status, the terminator and the guard byte.
    • Needs no root, so non-privileged runs include it (unlike the read-write test, which changes partitions). GPUs without memory partitions are skipped.
  • rocm-smi-lib's memory partition test: the existing 2-byte check now has a guard byte after the buffer and checks that the name is terminated inside it.
  • Does not touch amd-smi's read-write test file, which open PR test(amdsmi): stop partition tests staging NPS modes #12472 reworks.
  • CHANGELOG: one Resolved Issues entry.

Issue Tracking

JIRA ID: ROCM-30433

Test Plan

  • 8x MI308X (memory partition NPS1, amdgpu 7.1.9), as a normal user, read-only. BEFORE = this PR with only the library line reverted, AFTER = this PR; Release and ASAN builds.
  • ASAN harness making the same call as the read-write test (2-byte stack buffer, len 2), BEFORE and AFTER.
  • All GpuFunctionalReadOnly tests on the MI308X box, BEFORE and AFTER.
  • Full amdsmitst locally (gfx1030 + gfx1100, no memory partitions), Release and ASAN with the AMDSMI ASAN workflow's options.
  • rocm-smi-lib: the strengthened check, run from a small program against the library BEFORE and AFTER on the MI308X box (the test itself needs root and changes partitions); rsmitst build.
  • amdsmi and rocm-smi-lib pre-commit hooks.

Test Result

  • New test: BEFORE fails on all 8 GPUs (guard byte overwritten for the 1-, 2- and 4-byte buffers); AFTER passes. Same in Release and ASAN builds.
  • Harness BEFORE: stack-buffer-overflow, WRITE of size 1, 'smallBuffer' ... overflows this variable, at rocm_smi.cc:6788 in rsmi_dev_memory_partition_get (the report from the issue). AFTER: no report; "insufficient size" with buffer "N".
  • Read-only suite on MI308X: 22 tests. BEFORE 21 passed, 1 failed (the new test); AFTER 22 passed.
  • rocm-smi-lib check: BEFORE fails on all 8 GPUs (guard byte overwritten, no terminator); AFTER passes.
  • Local full suite: 269 tests, 243 passed, 26 skipped, 0 failed, no sanitizer reports. The new test skips both local GPUs (no memory partitions).

Submission Checklist

- Copy at most len - 1 characters before the terminator, as the compute
  partition getter already does. A buffer too small for the name had its
  terminator written one byte past its end
- Apply the same one-line fix to the rocm-smi-lib copy of the function
- Add a read-only test that reads the partition into short, exact-fit
  and larger buffers with a guard byte after each. It needs no root and
  skips GPUs without memory partitions
- Add a CHANGELOG entry

Signed-off-by: Adam360x <Adam.pryor@amd.com>
@therock-pr-bot

therock-pr-bot Bot commented Oct 7, 2026

Copy link
Copy Markdown

✅ All Policy Checks Passed

Check Status Details
📝 PR Description ✅ Pass —
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ✅ Pass —
🚫 Draft PR 🔜 To Be Enabled —
🚩 Feature Flag 🔜 To Be Enabled —
📊 Code Coverage 🔜 To Be Enabled —

🎉 All policy checks passed!

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

🙋 Wish to Override Policy?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The independently maintained rocm-smi-lib implementation lacks regression coverage capable of detecting the fixed overflow.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes memory-partition reads so truncated names remain null-terminated within caller-provided buffers.

Changes:

  • Limits copies to len - 1 in both library implementations.
  • Adds guard-byte regression coverage for amd-smi.
  • Documents the resolved overflow.
File Description
projects/​rocm-smi-lib/​src/​rocm_smi.cc Fixes bounded memory-partition copying.
projects/​amdsmi/​rocm_smi/​src/​rocm_smi.cc Applies the same fix to amd-smi’s bundled implementation.
projects/​amdsmi/​tests/​amd_smi_test/​main.cc Registers the read-only regression test.
projects/​amdsmi/​tests/​amd_smi_test/​functional/​gpu/​partition/​memorypartition_read.h Declares the new test fixture.
projects/​amdsmi/​tests/​amd_smi_test/​functional/​gpu/​partition/​memorypartition_read_test.cc Tests truncation, termination, status, and guard preservation.
projects/​amdsmi/​CHANGELOG.md Records the resolved overflow.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread projects/rocm-smi-lib/src/rocm_smi.cc Resolved
- Add a guard byte after the 2-byte buffer and check that the name is
  terminated inside it, so the rocm-smi-lib test fails if the copy
  writes past the caller's buffer again
- Drop the size check, which compared the buffer with itself

Signed-off-by: Adam360x <Adam.pryor@amd.com>
@adam360x

adam360x commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

…M-30433

# Conflicts:
#	projects/amdsmi/CHANGELOG.md

Co-authored-by: adam360x <61172547+adam360x@users.noreply.github.com>

Copilot AI commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Resolved in 2308eb4 by merging develop and retaining both changelog entries. The buffer fixes and regression tests are unchanged. Diff checks and review passed; local test configuration was blocked by missing libdrm, and CodeQL timed out.

@adam360x
adam360x merged commit f70492f into develop Oct 8, 2026
135 of 137 checks passed
@adam360x
adam360x deleted the users/adam360x/ROCM-30433 branch October 8, 2026 17:57
@systems-assistant

Copy link
Copy Markdown
Contributor

TheRock Submodule Bump Activity

Newest first

anujshuk-amd pushed a commit that referenced this pull request Oct 12, 2026
#12986)

## Motivation

- TheRock's ASAN nightly aborts `amdsmitst` in
`GpuFunctionalReadWrite.TestMemoryPartitionReadWrite` with a
stack-buffer-overflow (MI325X). The test passes a 2-byte buffer to
`amdsmi_get_gpu_memory_partition()` and expects "insufficient size".
- The bug is in the library, not the test:
`rsmi_dev_memory_partition_get()` copied up to `len` characters and then
wrote the terminator after them, so any buffer of `len` bytes or less
got one byte written past its end.
- Present since 2023 in both copies of the function: amd-smi's bundled
rocm_smi and rocm-smi-lib.


Signed-off-by: Adam360x <Adam.pryor@amd.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants