|
From: openocd-gerrit <ope...@us...> - 2026-07-28 19:06:29
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via da3920b0a52dc2d394afb222c688dac7e57acc1b (commit)
from 4b97bf85807ad5242b14a87fcd2bc77b7b0624f0 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit da3920b0a52dc2d394afb222c688dac7e57acc1b
Author: Zane Leung <zhe...@sp...>
Date: Wed Jun 24 18:26:01 2026 +0800
target/riscv: add hart index bounds checking
dm013_select_hart() writes to dmcontrol.hartsel which is WARL.
Prevent attempting to access a hart that don't exist on the
debug module. Add coreid validation against actual hart count.
Change-Id: If3638eb9fd3ff8f60018c070b3c024d1c5579787
Signed-off-by: Zane Leung <zhe...@sp...>
Reviewed-on: https://review.openocd.org/c/openocd/+/9755
Tested-by: jenkins
Reviewed-by: Tomas Vanek <va...@fb...>
Reviewed-by: Evgeniy Naydanov <eu...@gm...>
diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c
index 34df26696..c730b68e4 100644
--- a/src/target/riscv/riscv-013.c
+++ b/src/target/riscv/riscv-013.c
@@ -1972,9 +1972,8 @@ static int examine_dm(struct target *target)
get_field(dmcontrol, DM_DMCONTROL_HARTSELLO);
/* Before doing anything else we must first enumerate the harts. */
- const int max_hart_count = MIN(RISCV_MAX_HARTS, hartsel + 1);
if (dm->hart_count < 0) {
- for (int i = 0; i < max_hart_count; ++i) {
+ for (uint32_t i = 0; i <= hartsel; ++i) {
/* TODO: This is extremely similar to
* riscv013_get_hart_state().
* It would be best to reuse the code.
@@ -2087,6 +2086,14 @@ static int examine(struct target *target)
if (result != ERROR_OK)
return result;
+ dm013_info_t *dm = get_dm(target);
+ if (target->coreid >= dm->hart_count) {
+ LOG_TARGET_ERROR(target, "Hart index %d is too large. The maximum"
+ " index for this Debug Module is %d",
+ target->coreid, dm->hart_count - 1);
+ return ERROR_FAIL;
+ }
+
result = dm013_select_target(target);
if (result != ERROR_OK)
return result;
diff --git a/src/target/riscv/riscv.h b/src/target/riscv/riscv.h
index 2a0a9b95f..ff584e140 100644
--- a/src/target/riscv/riscv.h
+++ b/src/target/riscv/riscv.h
@@ -17,7 +17,6 @@ struct riscv_program;
#define RISCV_COMMON_MAGIC 0x52495356U
-#define RISCV_MAX_HARTS ((int)BIT(20))
#define RISCV_MAX_TRIGGERS 32
#define RISCV_MAX_HWBPS 16
#define RISCV_MAX_DMS 100
-----------------------------------------------------------------------
Summary of changes:
src/target/riscv/riscv-013.c | 11 +++++++++--
src/target/riscv/riscv.h | 1 -
2 files changed, 9 insertions(+), 3 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|