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

Scratch buffer data leakages #1399

Open
xermicus opened this issue Jun 26, 2023 · 0 comments
Open

Scratch buffer data leakages #1399

xermicus opened this issue Jun 26, 2023 · 0 comments
Labels
bug Something isn't working polkadot Concerns the Polkadot target

Comments

@xermicus
Copy link
Contributor

The scratch buffer is (re)used very often in emit (at least in the substrate target). This might lead to unwanted data leakage, exposing access to bogus data in memory from Solidity. This code:

contract A {
    function setVars(address _contract, uint256 _num) public payable returns(bytes ret) {
        (bool ok, ret) =_contract.call(abi.encodeWithSignature("setVars(uint256)", _num));
        // Oh no, forgot to assert on ok 
    }
}

Results in the following behaviour, if the input to the setVars function is invalid:

grafik

While sema does emit a warning about the unused variable. It can still be ignored, or it the check can be erroneous.

We can do better here. We should identify all locations in emit with this issue (the problem might be in other places too). Possible solutions inlcude

  • using alloca wherever the buffer size is small or known beforehand (performance overhead should be negligible)
  • bzero8ing out the buffer before using it (costly).
  • only clear it if the call failed. But: On 2 subsequent scratch buf usages, where both were "successful" and hence the scratch buf is not cleared. Given during one usage, less data was written. Then we still end up with bogus data in the scratch buf. I'm not yet convinced that this is ultimately secure in all cases.
@xermicus xermicus added the bug Something isn't working label Jun 26, 2023
@xermicus xermicus added the polkadot Concerns the Polkadot target label Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working polkadot Concerns the Polkadot target
Projects
None yet
Development

No branches or pull requests

1 participant