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

fix(security)!: avoid DoS on malicious insert to memory #1099

Merged
merged 2 commits into from
May 4, 2023

Conversation

Oppen
Copy link
Contributor

@Oppen Oppen commented May 3, 2023

This avoids panics on allocation failure and integer overflow during calls to Memory::insert.

Fixes #798
Closes #805

Checklist

  • Linked to Github Issue
  • Unit tests added
  • Integration tests added.
  • This change requires new documentation.
    • Documentation has been added/updated.
    • CHANGELOG has been updated.

@codecov
Copy link

codecov bot commented May 3, 2023

Codecov Report

Merging #1099 (b69b183) into main (c17aa23) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1099   +/-   ##
=======================================
  Coverage   98.15%   98.15%           
=======================================
  Files          85       85           
  Lines       34534    34553   +19     
=======================================
+ Hits        33897    33916   +19     
  Misses        637      637           
Impacted Files Coverage Δ
src/vm/vm_memory/memory.rs 98.87% <100.00%> (+0.01%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Oppen Oppen force-pushed the fix/try_reserve_memory branch from 99e9e0a to 0116d04 Compare May 3, 2023 17:26
@github-actions
Copy link

github-actions bot commented May 3, 2023

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 17.109 ± 0.086 16.944 17.281 1.00
head blake2s_integration_benchmark 17.217 ± 0.078 17.125 17.354 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 5.208 ± 0.068 5.162 5.393 1.00
head compare_arrays_200000 5.237 ± 0.039 5.185 5.311 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 3.273 ± 0.035 3.232 3.342 1.00
head dict_integration_benchmark 3.286 ± 0.014 3.266 3.313 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base factorial_multirun 5.510 ± 0.021 5.483 5.555 1.00 ± 0.00
head factorial_multirun 5.490 ± 0.015 5.476 5.516 1.00
Command Mean [s] Min [s] Max [s] Relative
base fibonacci_1000_multirun 4.891 ± 0.041 4.844 4.983 1.00
head fibonacci_1000_multirun 4.936 ± 0.070 4.864 5.094 1.01 ± 0.02
Command Mean [ms] Min [ms] Max [ms] Relative
base field_arithmetic_get_square_benchmark 213.3 ± 26.8 203.0 289.4 1.03 ± 0.13
head field_arithmetic_get_square_benchmark 206.1 ± 2.1 204.2 211.3 1.00
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 15.987 ± 0.124 15.858 16.297 1.00 ± 0.01
head integration_builtins 15.943 ± 0.092 15.848 16.159 1.00
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 17.134 ± 0.221 17.030 17.757 1.00
head keccak_integration_benchmark 17.319 ± 0.166 17.096 17.644 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base linear_search 5.228 ± 0.091 5.162 5.480 1.00
head linear_search 5.272 ± 0.085 5.214 5.453 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 3.592 ± 0.048 3.556 3.722 1.00
head math_cmp_and_pow_integration_benchmark 3.594 ± 0.015 3.575 3.630 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 3.295 ± 0.018 3.279 3.335 1.00
head math_integration_benchmark 3.303 ± 0.016 3.285 3.333 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 2.917 ± 0.009 2.908 2.938 1.00
head memory_integration_benchmark 2.929 ± 0.008 2.916 2.940 1.00 ± 0.00
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 3.262 ± 0.020 3.242 3.307 1.00
head operations_with_data_structures_benchmarks 3.273 ± 0.012 3.261 3.301 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base pedersen 1.041 ± 0.002 1.039 1.045 1.00 ± 0.00
head pedersen 1.040 ± 0.003 1.038 1.047 1.00
Command Mean [s] Min [s] Max [s] Relative
base poseidon_integration_benchmark 1.744 ± 0.004 1.740 1.753 1.00
head poseidon_integration_benchmark 1.747 ± 0.005 1.739 1.756 1.00 ± 0.00
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 3.965 ± 0.012 3.956 3.991 1.00
head secp_integration_benchmark 3.998 ± 0.064 3.971 4.179 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base set_integration_benchmark 2.029 ± 0.009 2.017 2.048 1.00
head set_integration_benchmark 2.034 ± 0.009 2.025 2.048 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 10.275 ± 0.027 10.237 10.331 1.00
head uint256_integration_benchmark 10.275 ± 0.052 10.238 10.413 1.00 ± 0.01

Copy link
Contributor

@fmoletta fmoletta left a comment

Choose a reason for hiding this comment

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

Nice!

@fmoletta fmoletta added this pull request to the merge queue May 4, 2023
Merged via the queue into main with commit 913aa49 May 4, 2023
@fmoletta fmoletta deleted the fix/try_reserve_memory branch May 4, 2023 20:36
kariy pushed a commit to dojoengine/cairo-rs that referenced this pull request Jun 23, 2023
…1099)

Co-authored-by: Pedro Fontana <fontana.pedro93@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug/Security] 'capacity overflow' panic during Memory insertion (segment.resize)
3 participants