DBTR: validate trig_count before mapping shared memory in sbi_dbtr_install_trig()
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 62/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- c
- Domain
- operating-systems, security
Research direction
Start at sbi_dbtr_install_trig() and trace every use of trig_count, especially the shared-memory mapping, cleanup paths, and validation loop. Reproduce the normal and overflow cases on QEMU virt, then verify that oversized counts are rejected before any size calculation or entry iteration and that the control case still succeeds.
Written by the indexing model from the issue text.
Description
Problem
sbi_dbtr_install_trig() uses the caller-provided trig_count to compute the shared-memory range length before checking whether that count is reasonable:
sbi_hart_protection_map_range((unsigned long)shmem_base,
trig_count * sizeof(*entry));
The same trig_count * sizeof(*entry) expression is also used on several cleanup paths. On RV64, a sufficiently large trig_count can make this byte-size calculation wrap, so the mapped range can be smaller than the later loop expects.
The function does check hs->available_trigs < trig_count, but that happens only after the shared-memory mapping and after the first validation loop has already iterated over entries using trig_count.
Observed result
In a local QEMU virt test with DBTR shared memory set up first, the normal control case returned successfully. The overflow case then hit an M-mode trap and did not return before timeout.
Suggested fix
Validate trig_count before using it in the byte-size calculation or in the trigger-entry loop. For example, reject counts larger than the implementation limit before mapping:
if (trig_count > RV_MAX_TRIGGERS)
return SBI_ERR_INVALID_PARAM;
Scope
I have only validated the firmware fault/hang behavior on QEMU. I am not claiming a broader impact beyond this memory-safety/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