rust-openssl Unchecked Callback Length Memory Leak
The rust-openssl crate versions 0.9.24 prior to 0.10.78 are vulnerable to memory leaks due to unchecked callback lengths in PSK/cookie trampolines, potentially leading to buffer overflows.
The rust-openssl crate, a Rust wrapper for the OpenSSL library, is susceptible to a high-severity vulnerability due to unchecked callback lengths within the FFI trampolines used by several functions related to PSK (Pre-Shared Key) and cookie generation. Specifically, versions 0.9.24 up to (but not including) 0.10.78 are affected. The vulnerable functions include SslContextBuilder::set_psk_client_callback, set_psk_server_callback, set_cookie_generate_cb, and set_stateless_cookie_generate_cb. The issue arises because the user-provided closure’s returned usize (size) value is directly passed to OpenSSL without validation against the size of the &mut [u8] buffer provided to the closure, resulting in potential buffer overflows and memory leaks. This allows an attacker to potentially leak adjacent memory regions to a peer.
Attack Chain
- An attacker crafts a malicious application or exploits an existing application using the vulnerable
rust-opensslcrate. - The attacker triggers one of the vulnerable callback functions (
set_psk_client_callback,set_psk_server_callback,set_cookie_generate_cb, orset_stateless_cookie_generate_cb). - The vulnerable callback function executes the user-provided closure.
- The user-provided closure returns a
usizevalue indicating the intended length of the data to be written to the output buffer. - The FFI trampoline forwards this
usizevalue directly to OpenSSL, bypassing bounds checking against the actual buffer size. - If the returned
usizeexceeds the allocated buffer size, OpenSSL writes beyond the buffer boundary, leading to a buffer overflow. - The buffer overflow allows the attacker to read adjacent memory regions or overwrite data, potentially leaking sensitive information or corrupting program state.
- Successful exploitation could lead to information disclosure, denial of service, or potentially arbitrary code execution.
Impact
Successful exploitation of this vulnerability could lead to information disclosure, denial of service, or potentially arbitrary code execution. Given the widespread use of the rust-openssl crate in various applications, the impact could be significant, affecting numerous services and potentially exposing sensitive data. The vulnerability allows for memory leakage to peers which could have broad consequences.
Recommendation
- Upgrade to
rust-opensslversion 0.10.78 or later to patch the vulnerability (reference: https://github.com/rust-openssl/rust-openssl/releases/tag/openssl-v0.10.78). - Implement input validation and sanitization within user-provided closures to ensure that the returned
usizevalue does not exceed the allocated buffer size, mitigating the risk even in vulnerable versions.
Detection coverage 2
Detect rust-openssl PSK/Cookie Callback Length Mismatch
highDetects potential exploitation attempts by identifying inconsistencies between the expected and actual buffer lengths in PSK or Cookie callbacks within rust-openssl applications. This can indicate an attempt to trigger the GHSA-hppc-g8h3-xhp3 vulnerability leading to memory corruption or information disclosure.
Detect rust-openssl Memory Access Violation
criticalThis rule detects potential memory access violations during rust-openssl operations. This may indicate an attempt to exploit vulnerabilities such as GHSA-hppc-g8h3-xhp3, where unchecked callback lengths lead to buffer overflows.
Detection queries are kept inside the platform. Get full rules →