Conversation
rpmi_shmem_transport_init() copies a device-tree reg-names string into qctx->name (char[RPMI_NAME_CHARS_MAX=16]) using sbi_memcpy() without validating the length first. If the device tree supplies a reg-names string longer than 15 characters, the copy overflows the fixed-size buffer. Clamp the copy length to RPMI_NAME_CHARS_MAX - 1 and ensure explicit null termination. Fixes: 91f46fb ("lib/utils: Add RPMI messaging protocol and shared memory transport support") Closes: riscv-software-src#417 Signed-off-by: Yudistira Putra <pyudistira519@gmail.com>
Yudis-bit
force-pushed
the
fix/rpmi-shmem-name-bounds
branch
from
September 9, 2026 06:22
7044a03 to
065cae7
Compare
Contributor
Author
|
A correction to the description: The proposal bounds the stored name and explicitly terminates it. Would maintainers prefer truncating an overlong queue name, as proposed here, or rejecting it as invalid input? The validation limitation in the description still applies: no cross-build or runtime validation is reported. I also note the mailing-list submission requirement in |
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
rpmi_shmem_transport_init()copies a device-treereg-namesstring intoqctx->name(achar[RPMI_NAME_CHARS_MAX=16]buffer) usingsbi_memcpy(qctx->name, name, len)without validating the length. If the device tree supplies areg-namesstring longer than 15 characters, the copy overflows the fixed-size 16-byte buffer.This is the same class of buffer-length issue as #416.
Reproduction
A device-tree node with a
reg-namesentry longer than 15 characters (e.g.,"a2p-db-and-shmem"at 17 bytes including null) will overflow the 16-byteqctx->namebuffer.Fix
Add a length clamp before the
sbi_memcpy:The name is truncated if it exceeds 15 characters, and the buffer is always null-terminated.
Test
The RPMI mailbox subsystem does not have a standalone unit-test suite, but the fix is validated by review against the existing pattern in the codebase (e.g., the
rpmi_shmem_transport_init()function itself already validates thereg-namescount againstRPMI_QUEUE_IDX_MAX_COUNT).Limitations
RPMI_NAME_CHARS_MAXconstant is defined ininclude/sbi_utils/mailbox/rpmi_msgprot.has 16. The existing code already uses this constant for the buffer declaration.