lib: utils: mailbox: clamp RPMSI shmem queue name to RPMI_NAME_CHARS_MAX - #423
Open
Yudis-bit wants to merge 1 commit into
Open
lib: utils: mailbox: clamp RPMSI shmem queue name to RPMI_NAME_CHARS_MAX#423Yudis-bit wants to merge 1 commit into
Yudis-bit wants to merge 1 commit into
Conversation
The rpmi_shmem_transport_init() function copies a device-tree reg-names string into qctx->name (char[RPMI_NAME_CHARS_MAX=16]) without validating the length. If the device tree supplies a reg-names string longer than 15 characters, the sbi_memcpy overflows the fixed-size buffer. Clamp the copy length to RPMI_NAME_CHARS_MAX - 1 and ensure null termination. Fixes: riscv-software-src#417 Signed-off-by: Yudistira Putra <85178972+Yudis-bit@users.noreply.github.com>
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.