Skip to content

lib: utils/mailbox: clamp RPMI shmem queue name to RPMI_NAME_CHARS_MAX - #423

Open
Yudis-bit wants to merge 1 commit into
riscv-software-src:masterfrom
Yudis-bit:fix/rpmi-shmem-name-bounds
Open

Yudis-bit wants to merge 1 commit into
riscv-software-src:masterfrom
Yudis-bit:fix/rpmi-shmem-name-bounds

Conversation

@Yudis-bit

@Yudis-bit Yudis-bit commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem

rpmi_shmem_transport_init() copies a device-tree reg-names entry into the 16-byte qctx->name buffer. fdt_stringlist_get() reports the string length without its terminating NUL. A 16-character name fills the buffer without a terminator; a name longer than 16 characters writes past it. The copy currently has no length check.

Fix

Copy at most RPMI_NAME_CHARS_MAX - 1 bytes and terminate the stored name. Longer entries are truncated. This bounds the write without changing queue selection, which uses the queue index.

Validation

Closes #417.

OpenSBI asks for patches on its mailing list. This PR is a discussion link; the patch is being prepared for that review path.

@Yudis-bit
Yudis-bit force-pushed the fix/rpmi-shmem-name-bounds branch from 7044a03 to 065cae7 Compare September 9, 2026 06:22
@Yudis-bit Yudis-bit changed the title lib: utils: mailbox: clamp RPMSI shmem queue name to RPMI_NAME_CHARS_MAX lib: utils/mailbox: clamp RPMI shmem queue name to RPMI_NAME_CHARS_MAX Sep 9, 2026
@Yudis-bit

Copy link
Copy Markdown
Contributor Author

A correction to the description: a2p-db-and-shmem is 16 characters, and fdt_stringlist_get() returns a length excluding the terminating NUL. That example fills the 16-byte destination without terminating it; it does not itself demonstrate a write past the buffer. I should have distinguished those cases in the report.

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 docs/contributing.md; this GitHub discussion does not replace that review.

fdt_stringlist_get() returns a reg-names length without the terminating
NUL. Copying it into the 16-byte queue name buffer leaves no terminator
when the name is exactly 16 bytes long and overwrites adjacent memory
when it is longer.

Copy at most 15 bytes and terminate the stored name. This preserves the
existing queue setup while bounding the write for malformed device trees.

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
Yudis-bit force-pushed the fix/rpmi-shmem-name-bounds branch from 065cae7 to 80ce3a3 Compare September 29, 2026 10:11
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.

OpenSBI fdt_mailbox_rpmi_shmem.c copies reg-names into fixed 16-byte queue names without bounds checks

1 participant