7
31
Fork
You've already forked blackmagic
23

Stack buffer overflow in riscv_debug.c when accessing 128-bit CSRs #2239

Closed
opened 2026年04月26日 12:57:11 +02:00 by mTOTm · 0 comments
Contributor
Copy link

Environment

  • OS: Ubuntu 22.04
  • BMDA Version: v2.0.0-534-g488f2f90-dirty
  • Debug Probe: Black Magic Probe (ST-Link/v2)
  • Target: HPM RISC-V chip (Andes Tech RISC-V DTM, ID: 0x1000563d)

Description

BMDA crashes with "stack smashing detected" when attempting to identify RISC-V targets
that have 4+ data registers, which triggers 128-bit CSR access mode.

Steps to Reproduce

  1. Connect to an HPM RISC-V target via ST-Link v2
  2. Run: ./build_stlink/blackmagic -tj
  3. Crash occurs during target identification

log

./build_stlink/blackmagic -tj
Black Magic Debug App v2.0.0-530-g5057f2fd-dirty
 for Black Magic Probe, ST-Link v2 and v3, CMSIS-DAP, J-Link, FTDI (MPSSE) and WCH-Link
Using 1d50:6018 DFD496DE Black Magic Debug
 Black Magic Probe (ST-Link/v2) v2.0.0-503-gd8d74921-dirty
Running in Test Mode
Target voltage: 3.31V
Speed set to 6.000MHz for JTAG
Resetting TAP
Change state to Shift-DR
Scanning out ID codes
Return to Run-Test/Idle
Change state to Shift-IR
Scanning out IRs
Return to Run-Test/Idle
Change state to Shift-DR
Return to Run-Test/Idle
ID code 0x1000563d: Andes Tech RISC-V DTM.
RISC-V debug v0.13/v1.0 DMI
RISC-V debug v0.13 DM
Hart has 4 data registers and 8 progbuf registers
Attempting 128-bit read on misa
CSR access failed: 2
CSR access failed: 2
CSR access failed: 2
CSR access failed: 2
*** stack smashing detected ***: terminated
Aborted (core dumped)
### Environment - **OS**: Ubuntu 22.04 - **BMDA Version**: v2.0.0-534-g488f2f90-dirty - **Debug Probe**: Black Magic Probe (ST-Link/v2) - **Target**: HPM RISC-V chip (Andes Tech RISC-V DTM, ID: 0x1000563d) ### Description BMDA crashes with "stack smashing detected" when attempting to identify RISC-V targets that have 4+ data registers, which triggers 128-bit CSR access mode. ### Steps to Reproduce 1. Connect to an HPM RISC-V target via ST-Link v2 2. Run: `./build_stlink/blackmagic -tj` 3. Crash occurs during target identification ### log ```bash ./build_stlink/blackmagic -tj Black Magic Debug App v2.0.0-530-g5057f2fd-dirty for Black Magic Probe, ST-Link v2 and v3, CMSIS-DAP, J-Link, FTDI (MPSSE) and WCH-Link Using 1d50:6018 DFD496DE Black Magic Debug Black Magic Probe (ST-Link/v2) v2.0.0-503-gd8d74921-dirty Running in Test Mode Target voltage: 3.31V Speed set to 6.000MHz for JTAG Resetting TAP Change state to Shift-DR Scanning out ID codes Return to Run-Test/Idle Change state to Shift-IR Scanning out IRs Return to Run-Test/Idle Change state to Shift-DR Return to Run-Test/Idle ID code 0x1000563d: Andes Tech RISC-V DTM. RISC-V debug v0.13/v1.0 DMI RISC-V debug v0.13 DM Hart has 4 data registers and 8 progbuf registers Attempting 128-bit read on misa CSR access failed: 2 CSR access failed: 2 CSR access failed: 2 CSR access failed: 2 *** stack smashing detected ***: terminated Aborted (core dumped) ```
Sign in to join this conversation.
No Branch/Tag specified
main
fix/pre-bmp-v3-cross-file-cleanup
feature/bmda-remote-comms
ALTracer/feature/aarch64-ident
feature/better-meson-optimisation-handling
feature/am335x-support
feature/esp32-c3-support
feature/cortex-ar-software-breakpoints
feature/unit-testing
feature/windows-usb-serial-interface-naming
fix/bmp-external-spi
ALTracer/feature/bluepillplus-platform
ALTracer/feature/at32f43x-unrdp
feature/const-correctness
ALTracer/feature/fault_handlers
ALTracer/feature/hazard3-ice40-support
fix/ci-cleanup
ALTracer/fix/gdb-10-12-thread
ALTracer/feature/blackpill-f4-adc
ALTracer/fix/cortex-desc-allocfail-report
ALTracer/feature/spi-perf
ALTracer/feature/calibrate_swd
ALTracer/feature/blank-check
feature/avr
v2.0
v1.9
v1.10
v1.8
v2.1.0-rc1
v2.0.0
v2.0.0-rc2
v2.0.0-rc1
v1.9.3
v1.10.2
v1.10.1
v1.10.0
v1.10.0-rc1
v1.10.0-rc0
v1.9.2
v1.8.3
v1.9.1
v1.9.0
v1.9.0-rc1
v1.9.0-rc0
v1.8.2
v1.8.1
v1.8.0
v1.7.1
v1.7
v1.6.2-rc1
1.6.2-rc0
v1.6.1
v1.6
v1.6-rc1
v1.6-rc0
production_01
production_00
Labels
Clear labels
BMD App
Black Magic Debug App (aka. PC hosted) (not firmware)
BMP Firmware
Black Magic Probe Firmware (not PC hosted software)
Bug
Confirmed bug
Build system
Build system
Can't reproduce
Maintainers can't reproduce this problem
CI
Continuous Integration System
Contribution wanted
User contributions welcome
Documentation
Project documentation
Draft
Work in progress draft
Duplicate
This issue or pull request already exists
Enhancement
General project improvement
Feedback wanted
Requires additional submitter feedback
Foreign Host Board
Non Native hardware to runing Black Magic firmware on
GDB
Issue/PR related to GDB
Good first issue
Good for newcommers
HwIssue Mitigation
Solving or mitigating a Hardware issue in Software
Information Needed
Maintainers need more information
NativeHardware
Official Black Magic Debug Hardware
New Host Board
New hardware to run Black Magic firmware on
New Target
New debug target
Off Topic
Something that does not involve the project in any way
Potential Bug
A potential, unconfirmed or very special circumstance bug
Regression
Bug caused by a regression
User Interest Needed
More user interest required before consideration
User Testing Needed
Looking for user testing reports
Won't fix
Outside of the project scope or works as intended
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
blackmagic-debug/blackmagic#2239
Reference in a new issue
blackmagic-debug/blackmagic
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?