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

[Bug/Security] Out-of-memory (OOM) panic while reading a circuit (MemoryBlock) #228

Closed
1 task
pventuzelo opened this issue Apr 25, 2023 · 2 comments
Closed
1 task
Labels
bug Something isn't working

Comments

@pventuzelo
Copy link

Aim

We (@FuzzingLabs & @lambdaclass) found an out-of-memory issue in acvm 0.9.0 while reading a circuit.

Expected behavior

It should not crash.

Bug

Root cause

memory allocation of 167607452400 bytes failed
[1]    3680483 abort (core dumped

Related code:

let mut trace = Vec::with_capacity(len as usize);

This issue occurs when reading a MemoryBlock. Before calling Vec::with_capacity, the len value should be checked and sanitized.

This issue is similar to #187 and a similar fix using try_reserve_exact can be used here.

Detailed behavior

(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007ffff7c4c859 in __GI_abort () at abort.c:79
#2  0x00005555555ac4d7 in std::sys::unix::abort_internal () at library/std/src/sys/unix/mod.rs:350
#3  0x000055555555ddd7 in std::process::abort () at library/std/src/process.rs:2138
#4  0x00005555555ac94e in std::alloc::rust_oom () at library/std/src/alloc.rs:356
#5  0x00005555555ac957 in std::alloc::_::__rg_oom () at library/std/src/alloc.rs:351
#6  0x00005555555c0f47 in alloc::alloc::handle_alloc_error::rt_error () at library/alloc/src/alloc.rs:385
#7  0x000055555555eec7 in alloc::alloc::handle_alloc_error () at library/alloc/src/alloc.rs:389
#8  0x0000555555560589 in alloc::raw_vec::RawVec<T,A>::allocate_in (capacity=698364385, init=alloc::raw_vec::AllocInit::Uninitialized, alloc=...) at /rustc/a266f11990d9544ee408e213e1eec8cc9eb032b7/library/alloc/src/raw_vec.rs:190
#9  0x000055555556a7e7 in alloc::raw_vec::RawVec<T,A>::with_capacity_in () at /rustc/a266f11990d9544ee408e213e1eec8cc9eb032b7/library/alloc/src/raw_vec.rs:131
#10 alloc::vec::Vec<T,A>::with_capacity_in () at /rustc/a266f11990d9544ee408e213e1eec8cc9eb032b7/library/alloc/src/vec/mod.rs:675
#11 alloc::vec::Vec<T>::with_capacity (capacity=698364385) at /rustc/a266f11990d9544ee408e213e1eec8cc9eb032b7/library/alloc/src/vec/mod.rs:482
#12 0x00005555555630c1 in acir::circuit::opcodes::MemoryBlock::read (reader=0x7fffffffd3c0) at /home/scop/Documents/aztec/acvm/acir/src/circuit/opcodes.rs:41
#13 0x000055555556414b in acir::circuit::opcodes::Opcode::read (reader=0x7fffffffd3c0) at /home/scop/Documents/aztec/acvm/acir/src/circuit/opcodes.rs:299
#14 0x000055555556ba0b in acir::circuit::Circuit::read (reader=...) at /home/scop/Documents/aztec/acvm/acir/src/circuit/mod.rs:100
#15 0x000055555556bd8e in noir_fuzzing::oom_circuit_read_memoryblock () at src/main.rs:37
#16 0x000055555556bd56 in noir_fuzzing::main () at src/main.rs:8

To reproduce

Testing program:

use acvm::acir::circuit::Circuit;

fn oom_circuit_read_memoryblock() {
    let data = b"\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x02\x02\x00\x0b\x00\x00\x00\x00\x00\x00\x00\xff\x7f\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x80\x00\x00\x00\x04\x00\x00\x00\x00\x04\x00\x00\x00\x00\x0b\x04\x00\xff\xff\xff\x04\x30\x64\x4e\x72\xe1\x31\xa0\x29\x00\x00\x00\x01\x00\x00";
    let circuit = Circuit::read(&data[..]);
}

Versions

  • acvm = "0.9.0" (00282dc)
  • cargo 1.70.0-nightly (15d090969 2023-03-21)
  • Ubuntu 20.04

Additional context

No response

Submission Checklist

  • Once I hit submit, I will assign this issue to the Project Board with the appropriate tags.
@pventuzelo pventuzelo added the bug Something isn't working label Apr 25, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Apr 25, 2023
@kevaundray
Copy link
Contributor

Thanks for reporting this -- we plan to switch to using serde to prevent issues like this

@kevaundray
Copy link
Contributor

Closing as we have now moved to serde which mitigates the issues we were having with manual serialization

@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir May 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

2 participants