Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible use after free in TxRmtDriver #285

Open
schurwanzn-stabl opened this issue Aug 4, 2023 · 2 comments
Open

Possible use after free in TxRmtDriver #285

schurwanzn-stabl opened this issue Aug 4, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@schurwanzn-stabl
Copy link

When TxRmtDriver::write_items is called with block = false

esp-idf-hal/src/rmt.rs

Lines 607 to 613 in 29806af

fn write_items<S>(&mut self, signal: &S, block: bool) -> Result<(), EspError>
where
S: Signal,
{
let items = signal.as_slice();
esp!(unsafe { rmt_write_items(self.channel(), items.as_ptr(), items.len() as i32, block) })
}

the called function rmt_write_items will keep reading from the passed pointer until the transmission is completed. The borrow on the S: Signal though "expires" once write_items returns.
For example when calling the TxRmtDriver::start function

esp-idf-hal/src/rmt.rs

Lines 589 to 597 in 29806af

/// Start sending the given signal without blocking.
///
/// `signal` is captured for safety so that the user can't change the data while transmitting.
pub fn start<S>(&mut self, signal: S) -> Result<(), EspError>
where
S: Signal,
{
self.write_items(&signal, false)
}

the ESP-IDF may access dropped memory.


Aside from that the documentation of rm_write_items states to "please [?] do not use the memory allocated from psram when calling rmt_write_items". This restriction is not enforced either.
Should I create a separate issue for this?

@ivmarkov
Copy link
Collaborator

Can you actually contribute a Pr that fixes this? I admit I did not review carefully the RMT driver at the time, and it was a contribution.

@schurwanzn-stabl
Copy link
Author

Fixing the code seems a bit more involved and we currently do not use the non-blocking function.
Thus I can't contribute a fix for now, sorry.

@Vollbrecht Vollbrecht added the bug Something isn't working label Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

3 participants