Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Automatic canary-based stack overflow detection #33

Merged
merged 1 commit into from
Aug 28, 2020
Merged

Conversation

jonas-schievink
Copy link
Contributor

Fixes #31

@jacobrosenthal
Copy link

jacobrosenthal commented Aug 25, 2020

I have a repo that I think I overflow pretty easily by changing window size from 16 to 64 .
https://github.com/jacobrosenthal/dsp-discoveryf4-rust/blob/master/lab4/examples/4_11_stft_accelerometer.rs
using probe-run 0.1.3 it would just hang at resetting device.

So wanted to try this. Oddly enough I get

$ cargo run --release --example 4_11_stft_accelerometer_microfft
    Finished release [optimized + debuginfo] target(s) in 0.06s
     Running `probe-run --chip STM32F407VGTx target/thumbv7em-none-eabihf/release/examples/4_11_stft_accelerometer_microfft`
flashing program ..
DONE
resetting device
Error: RTT control block not found in target memory. Make sure RTT is initialized on the target.

Note I actually get the same message in main now so its not this PR necessarily

@jonas-schievink
Copy link
Contributor Author

@jacobrosenthal Thanks for the report, we might need to put a delay in the RTT connection loop.

Copy link
Member

@japaric japaric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great! left some comments about the logic but nothing of concern

rtt = Some(entry.value() as u32);
match name {
"_SEGGER_RTT" => rtt = Some(entry.value() as u32),
"__rust_alloc" | "__rg_alloc" | "__rdl_alloc" | "malloc" if !uses_heap => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't __rust_alloc an implementation detail? for now it will make do though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it is

match region {
MemoryRegion::Ram(ram) => {
if let Some(old) = &ram_region {
log::debug!("multiple RAM regions found ({:?} and {:?}), stack canary will not be available", old, ram);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the device may have two regions but the application may only use one; this logic will exclude that kind of applications
this is ok for now but should we file a ticket to tweak the logic further to allow those apps? (not sure what that logic would look like though)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I've filed #39.

@jonas-schievink jonas-schievink merged commit 01e02dd into main Aug 28, 2020
@jonas-schievink jonas-schievink deleted the autocanary branch August 28, 2020 14:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Approximated stack overflow detection via stack canaries
3 participants