Skip to content

modules: SEGGER_RTT: Invalid re-use of RAM memory allocated for SEGGER RTT #58150

@MarekPieta

Description

@MarekPieta

Describe the bug
By default the RTT data structures are placed in bss memory region. After an application-triggered reboot, the RAM region used for the RTT data structures may be instantly re-used by the bootloader. The bootloader may use the RAM for completely different purpose, so that reading this region may eventually put the connected RTT host computer into strange state and lead to an unexpected behavior.

On my desk, the host eventually wrote an invalid value to the RdOff (value of 215615629) of terminal’s up buffer after RTT initialization was completed on device’s end. The invalid value caused crash later on when RTT was used by the application (application accessed wrong memory address which triggered fault; the application uses SEGGER RTT for logging).

Expected behavior
There needs to be a way to inform the RTT connected host computer that the RTT data is no longer valid and should not be read (to prevent the RTT host from entering invalid state). Currently there seem to be no SEGGER API that would allow to uninit the RTT terminal so we may need to expand the API.
Alternatively we may provide a separate RAM region which could be used exclusively for the RTT Terminal. The region needs to be known for both application and bootloader (we may place the region at the end of device's RAM to mitigate chance that an incompatible bootloader would accidentally use it for a other purpose).

Impact
Unexpected crash of device working in debug mode. The crash may appear randomly and is hard to investigate.

Additional context
I checked the following with gdb to make sure about the root cause:

  • If I set breakpoint on main function call, the garbage RdOff is already there (rest of the RTT structure is properly zero-initialized). Setting the RdOff manually to 0 using gdb's set successfully prevents the application's crash.
  • If I set breakpoint on SEGGER_RTT_Init the spurious set of RdOff seems to happen before the RTT structure initialization. In that case, the SEGGER_RTT_Init properly initializes the structure after the spurious write which prevents the issue from happening.

Metadata

Metadata

Assignees

Labels

area: Segger RTTSEGGER RTT (Real Time Transfer)bugThe issue is a bug, or the PR is fixing a bugpriority: lowLow impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions