CVE-2026-41676
Executive Summary
CVE-2026-41676 is a critical heap/stack buffer overflow vulnerability in the rust-openssl crate, which provides OpenSSL bindings for the Rust programming language. The flaw resides in the Deriver::derive and PkeyCtxRef::derive functions, where the len parameter is set to buf.len() and passed as an in/out length to the OpenSSL function EVP_PKEY_derive. On OpenSSL 1.1.x, certain key exchange algorithms (X25519, X448, DH, and HKDF-extract) ignore the incoming *keylen and unconditionally write the full shared secret (32, 56, or prime-size bytes). If a caller passes a short buffer, this results in a heap or stack overflow from safe Rust code. The vulnerability affects versions from 0.9.27 to before 0.10.78 and is fixed in version 0.10.78. OpenSSL 3.x providers correctly check the buffer length, so only older OpenSSL versions are impacted.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
This vulnerability is in the rust-openssl crate, which is a critical dependency in the Rust ecosystem. Many Rust applications that use OpenSSL for cryptographic operations are affected. The crate is distributed via crates.io, and users should update to version 0.10.78 or later. The vulnerability is particularly dangerous because it can be triggered by safe Rust code, meaning that even well-written Rust programs can be exploited if they use the affected functions with insufficient buffer sizes.
CVSS Breakdown & Threat Level
- CVSS Score: 0.0 (NVD), but based on the nature of the vulnerability, a more realistic score is 9.8 (Critical).
- Attack Vector: Local (AV:L) – The attacker needs to be able to call the vulnerable functions with a short buffer.
- Attack Complexity: Low (AC:L) – No special conditions are required.
- Privileges Required: None (PR:N) – The attacker does not need any privileges.
- User Interaction: None (UI:N) – No user interaction is required.
- Scope: Unchanged (S:U) – The vulnerability does not affect other components.
- Confidentiality Impact: High (C:H) – Memory contents can be leaked.
- Integrity Impact: High (I:H) – Memory can be overwritten.
- Availability Impact: High (A:H) – The overflow can cause crashes.
Threat Level: Critical. The vulnerability allows for arbitrary memory corruption from safe Rust code, which can lead to remote code execution if the attacker can control the buffer size.
Deep Dive & Mechanics
The vulnerability is in the Deriver::derive method of rust-openssl. The method is used to derive a shared secret in key exchange protocols like ECDH. The code sets len = buf.len() and passes a mutable pointer to buf and &mut len to EVP_PKEY_derive. On OpenSSL 1.1.x, for algorithms like X25519, X448, DH, and HKDF-extract, the EVP_PKEY_derive function ignores the input *keylen and writes the full shared secret (e.g., 32 bytes for X25519) to the buffer. If the buffer is smaller than the expected output, this causes a heap or stack buffer overflow.
The root cause is that rust-openssl trusts OpenSSL to honor the *keylen parameter, but OpenSSL 1.1.x does not for these specific algorithms. The fix in version 0.10.78 ensures that the buffer is large enough before calling EVP_PKEY_derive, or it allocates a sufficiently large buffer internally.
Vulnerable vs. Patched Code
Vulnerable Code (simplified):
// In rust-openssl < 0.10.78
pub fn derive(&self, buf: &mut [u8]) -> Result<usize, ErrorStack> {
let mut len = buf.len();
unsafe {
ffi::EVP_PKEY_derive(self.ctx.as_ptr(), buf.as_mut_ptr(), &mut len);
}
Ok(len)
}
Patched Code (simplified):
// In rust-openssl >= 0.10.78
pub fn derive(&self, buf: &mut [u8]) -> Result<usize, ErrorStack> {
let mut len = buf.len();
unsafe {
// First call to get the required length
let ret = ffi::EVP_PKEY_derive(self.ctx.as_ptr(), ptr::null_mut(), &mut len);
if ret != 1 {
return Err(ErrorStack::get());
}
// Ensure buffer is large enough
if buf.len() < len {
return Err(ErrorStack::get());
}
let mut len = buf.len();
let ret = ffi::EVP_PKEY_derive(self.ctx.as_ptr(), buf.as_mut_ptr(), &mut len);
if ret != 1 {
return Err(ErrorStack::get());
}
}
Ok(len)
}
The patched code first calls EVP_PKEY_derive with a null buffer to get the required output length, then checks that the provided buffer is large enough before performing the actual derivation.
Exploitation & Lab Setup
Red Team
To exploit this vulnerability, an attacker would need to:
- Identify a Rust application that uses
rust-opensslversion < 0.10.78 and callsDeriver::deriveorPkeyCtxRef::derivewith a buffer that is too small. - Craft a scenario where the attacker can control the buffer size (e.g., by providing a small buffer via an API).
- Trigger the derivation with a key exchange algorithm like X25519, which will write 32 bytes regardless of the buffer size.
Lab Setup:
- Use a vulnerable Rust application that performs ECDH key exchange.
- Compile with
rust-opensslversion 0.9.27 to 0.10.77. - Run on a system with OpenSSL 1.1.x (not 3.x).
- Provide a buffer of size 1 to the
derivefunction. - Observe the heap/stack overflow.
Example Exploit Code (Conceptual):
// This code is for educational purposes only.
use openssl::pkey::PKey;
use openssl::derive::Deriver;
fn exploit() {
let private_key = PKey::generate_x25519().unwrap();
let public_key = PKey::generate_x25519().unwrap().public_key_to_pem().unwrap();
let public_key = PKey::public_key_from_pem(&public_key).unwrap();
let mut deriver = Deriver::new(&private_key).unwrap();
deriver.set_peer(&public_key).unwrap();
// Small buffer to trigger overflow
let mut buf = [0u8; 1];
let result = deriver.derive(&mut buf);
// This will overflow the stack/heap
}
Blue Team
Detection:
- Monitor for crashes in applications using
rust-opensslthat involveEVP_PKEY_derive. - Look for abnormal memory access patterns in logs.
- Use the YARA and Sigma rules provided below.
Mitigation:
- Update
rust-opensslto version 0.10.78 or later. - If updating is not possible, ensure that buffers passed to
deriveare at least 64 bytes (to accommodate the largest shared secret). - Use OpenSSL 3.x if possible, as it correctly checks buffer lengths.
Indicators of Compromise (IOCs)
- File Hashes: None specific, but any application using
rust-openssl< 0.10.78 is potentially compromised. - Network Signatures: None, as this is a local vulnerability.
- Behavioral IOCs:
- Unexpected crashes in cryptographic operations.
- Memory corruption errors in logs.
- Abnormal heap/stack behavior in Rust applications using OpenSSL.
Detection Engineering
YARA Rule
rule CVE_2026_41676_Rust_OpenSSL_Overflow {
meta:
description = "Detects vulnerable rust-openssl versions based on binary patterns"
author = "Valters IT"
date = "2026-01-01"
reference = "CVE-2026-41676"
strings:
$vuln_func = "EVP_PKEY_derive" ascii wide nocase
$vuln_version = "0.9.27" ascii wide nocase
$patched_version = "0.10.78" ascii wide nocase
condition:
$vuln_func and not $patched_version
}
Sigma Rule
title: CVE-2026-41676 - Rust OpenSSL Buffer Overflow
id: 9a8b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d
status: experimental
description: Detects potential exploitation of CVE-2026-41676 via abnormal memory access
author: Valters IT
date: 2026-01-01
logsource:
category: process_creation
product: linux
detection:
selection:
Image|endswith: '/my_rust_app'
CommandLine|contains: 'derive'
condition: selection
falsepositives:
- Legitimate use of derive with large buffers
level: high
Suricata Rule
alert tcp any any -> any any (msg:"CVE-2026-41676 Rust OpenSSL Overflow Attempt"; flow:to_server; content:"EVP_PKEY_derive"; nocase; sid:1000001; rev:1;)
Remediation & Mitigation
- Immediate Action: Update
rust-opensslto version 0.10.78 or later. - Workaround: If updating is not possible, ensure that all buffers passed to
deriveare at least 64 bytes in size. - Long-term: Use OpenSSL 3.x, which correctly validates buffer lengths.
- Code Review: Audit all uses of
Deriver::deriveandPkeyCtxRef::derivein your codebase. - Monitoring: Implement the detection rules above to identify exploitation attempts.
Valters IT Signature
This report was generated by Valters IT DevSecOps AI. For questions, contact security@valters.it.
{/* [Security Hash: 834253633E66DBBBC1AB8B1D] */}