riscv-software-src / riscv-software-src/opensbi
OpenSBI fdt_mailbox_rpmi_shmem.c copies reg-names into fixed 16-byte queue names without bounds checks
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 1.5k
- Forks
- 712
- PR merge metrics
- No merged PRs in 30d
Description
Title: OpenSBI fdt_mailbox_rpmi_shmem.c copies reg-names into fixed 16-byte queue names without bounds checks
Current upstream OpenSBI master still copies device-tree reg-names strings into a fixed-size queue-name buffer without validating the length first. In lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c, rpmi_shmem_mbox_init() gets each queue name with fdt_stringlist_get(fdt, nodeoff, "reg-names", qid, &len) and then copies it directly with:
sbi_memcpy(qctx->name, name, len);
The destination is struct smq_queue_ctx::name, which is defined as char name[RPMI_NAME_CHARS_MAX], and RPMI_NAME_CHARS_MAX is 16 in include/sbi_utils/mailbox/rpmi_msgprot.h. The only check before the copy is that the property exists and that len is non-negative. There is no check that len fits in the 16-byte destination and no explicit NUL-termination step.
Because qctx is one entry inside the queue_ctx_tbl array, an oversized reg-names entry can overwrite the following members of that struct, including headptr, tailptr, buffer, and queue_id, before the mailbox controller is fully initialized. This makes the bug more than a cosmetic string issue; it is a real memory corruption condition during device-tree parsing.
Expected behavior: the code should reject or clamp reg-names values so that queue names fit in RPMI_NAME_CHARS_MAX and remain NUL-terminated.
Actual behavior: the code copies the full device-tree string length into the fixed 16-byte field with no local bound.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/utils/mailbox/fdt_mailbox_rpmi_shmem.c at rpmi_shmem_mbox_init(), then inspect smq_queue_ctx::name and RPMI_NAME_CHARS_MAX in include/sbi_utils/mailbox/rpmi_msgprot.h. Trace how reg-names length is obtained and verify that an oversized value cannot overwrite adjacent queue context fields and that accepted names remain terminated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- operating-systems, security
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100