Unratedcrates.ioPublished
Unsound API in secp256k1 allows use-after-free and invalid deallocation from safe code
GHSA-969w-q74q-9j8v
- Affected
- crates.io secp256k1 >= 0.14.0, < 0.22.2; >= 0.23.0, < 0.23.5; >= 0.24.0, < 0.24.2
- Fixed in
- 0.24.20.22.20.23.5· Vendor fix available
- Issue
- Because of incorrect bounds on method Secp256k1::preallocatedgennew it was possible to cause use-after-free from safe consumer code. It was also possible to "free" memory not allocated by the appropriate allocator. The method takes a place for storing the context as a mutable reference and returns context containing that reference. Because the code internally uses unsafe and the bounds were incorrect it was possible to create a context that outlived the passed reference (e.g. 'static). Because the context can alternatively carry heap-allocated pointer freed on drop it was possible to "deallocate" a pointer that wasn't returned from appropriate allocator. The code decides whether to free the memory based on type parameter but because of missing bound it was possible to construct the context with invalid parameter. You are unaffected if you either don't call Secp256k1::preallocatedgennew manually checked that your usage of the method is sound upgraded to the patched version of…
Recommended action: Upgrade to 0.24.2, 0.23.5 or 0.22.2 by release line, then redeploy and verify.A vendor fix does not resolve your finding until you verify it in your own systems.