DBTR: avoid unsigned range-check wraparound in sbi_dbtr_read_trig()
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- c
- Domain
- operating-systems, security
Research direction
Start at sbi_dbtr_read_trig() and inspect how its range validation feeds shared-memory mapping and entry iteration. Run the local RV64 QEMU virt test with DBTR enabled, including the normal and overflow-inducing boundary cases. Done means requests beyond hs->total_trigs or with an unrepresentable endpoint are rejected before mapping or iteration, with endpoint semantics consistent with the DBTR specification.
Written by the indexing model from the issue text.
Description
Problem
sbi_dbtr_read_trig() currently validates the requested trigger range with:
if (trig_idx_base >= hs->total_trigs ||
trig_idx_base + trig_count >= hs->total_trigs)
return SBI_ERR_INVALID_PARAM;
Both trig_idx_base and trig_count are unsigned values. Their addition can wrap before the comparison, allowing an out-of-range request to pass the guard.
The function then uses trig_count for shared-memory mapping and entry iteration.
Observed result
In a local RV64 QEMU virt test with DBTR enabled, the normal control case returned successfully. An overflow-inducing boundary case passed the range check and subsequently caused an M-mode store access fault while writing DBTR shared memory.
Expected result
A request whose range exceeds hs->total_trigs, or whose endpoint cannot be represented, should be rejected before shared-memory mapping or iteration.
Suggested fix
Avoid forming the unchecked sum. After validating trig_idx_base, compare trig_count against hs->total_trigs - trig_idx_base, or use an equivalent checked-add helper.
The endpoint comparison should also be kept consistent with the intended DBTR specification semantics.
Scope
I have validated the firmware fault behavior on QEMU. I am not claiming a broader impact beyond this memory-safety and availability issue.
- 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