OpenSBI mpxy: base_attr_id + attr_count can wrap and bypass range checks
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- c
- Domain
- operating-systems, security
Research direction
Read the range handling in lib/sbi/sbi_mpxy.c at sbi_mpxy_read_attrs() and sbi_mpxy_write_attrs(), then compare it with the corresponding helpers in lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c. Exercise caller-controlled base_attr_id and attr_count values near the u32 limit; done means invalid wrapped ranges are rejected before attribute indexing or copying can occur.
Written by the indexing model from the issue text.
Description
Title: OpenSBI mpxy: base_attr_id + attr_count can wrap and bypass range checks
Current upstream OpenSBI master (checked in a local clone at 6d5b2b9 on 2026-03-21) still computes attribute end IDs in u32 and then uses the result for range checks:
- lib/sbi/sbi_mpxy.c: sbi_mpxy_read_attrs() and sbi_mpxy_write_attrs()
- lib/utils/mpxy/fdt_mpxy_rpmi_mbox.c: mpxy_mbox_read_attributes() and mpxy_mbox_write_attributes()
The core pattern is:
u32 end_id = base_attr_id + attr_count - 1;
if (end_id >= MAX_ID)
return SBI_EBAD_RANGE;
or equivalent. The problem is that both base_attr_id and attr_count are caller-controlled u32 values. When base_attr_id is close to UINT32_MAX and attr_count is greater than 1, the addition wraps before the range check runs. That can make end_id look small even though the requested range is actually huge. In the mpxy helpers, the code then uses attr_id2index(base_attr_id) and copies attributes from or to the array starting at that wrapped index, so the overflowed range check can lead to out-of-bounds access in the message-protocol attribute array.
The current sanity check only validates that attr_count is non-zero and not larger than the shared-memory size in units of ATTR_SIZE. It does not prevent wraparound in base_attr_id + attr_count - 1, so the bug is still present in current head.
Expected behavior: the range calculation should use overflow-safe arithmetic, or the code should explicitly check base_attr_id > MAX - (attr_count - 1) before adding.
Actual behavior: the u32 addition can wrap and allow a bogus range to pass the bounds check, which then drives out-of-bounds attribute indexing/copying.
This looks like a security-relevant memory-safety bug in the OpenSBI mpxy path.
- Dominant language
- C
- Stars
- 1.6k
- Forks
- 734
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing 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.
More from riscv-software-src/opensbi
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
riscv-software-src/opensbi#425 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
riscv-software-src/opensbi#424 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
riscv-software-src/opensbi#439 ·
-
sbi_trap_redirect() does not clear SPELP when the interrupted context had no landing pad expectedOpen
Difficulty 3/5 1-2 days Newbie friendliness 67/100
riscv-software-src/opensbi#438 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
riscv-software-src/opensbi#436 · 3 comments ·
All issues in riscv-software-src/opensbi
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
libreswan/libreswan#3185 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
category:port-update
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
llvm:instcombine
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
llvm/llvm-project#246503 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day