Summary
A denial-of-service vulnerability in the RustCrypto Elliptic Curves crate affects the SM2 public-key encryption (PKE) decrypt() implementation, where untrusted ciphertext is split into slices without proper length checks.
By sending undersized or carefully malformed SM2 ciphertext, an attacker can trigger bounds-check panics in Rust, causing the calling thread or process to crash and potentially disrupting dependent services.
Affected context
This issue occurs in applications that use the RustCrypto Elliptic Curves crate's SM2 PKE decrypt() functionality, specifically in versions 0.14.0-pre.0 and 0.14.0-rc.0.
It is relevant when:
- SM2 ciphertext is accepted from untrusted or partially trusted sources (e.g., network input, external clients, or other services), and
- The application treats panic or thread termination in the crypto code path as a recoverable or normal failure, but in practice it brings down the process or critical worker.
The vulnerability manifests in the buffer handling logic that derives internal slices from attacker-controlled ciphertext or DER-encoded structures.
Exploit preconditions
- Attack surface: Any SM2 PKE decryption endpoint or code path exposed to untrusted ciphertext (e.g., TLS-like protocols, custom SM2-based APIs, message decryption services).
- Required access: Ability to supply arbitrary SM2 ciphertext to the decrypt() API (usually remote network access, but could also be IPC or queued messages).
- Trigger point: Invocation of the vulnerable decrypt() implementation on malformed or undersized ciphertext that leads to invalid slice boundaries.
- Why exploitation is possible: The decrypt() logic performs unchecked
slice::split_atoperations and related slicing on lengths derived directly from the ciphertext/DER content, allowing crafted inputs to cause Rust bounds-check failures that panic the thread or process.
Why this happens
The root cause is insufficient input validation in the SM2 decrypt() implementation, where internal slice operations assume that the ciphertext has a minimum structure and length.
Instead of robustly verifying buffer sizes and DER structure before performing split_at and related slicing, the code relies on the input being well-formed.
When an attacker provides shorter-than-expected ciphertext or malformed DER components, the computed offsets exceed the actual buffer length, triggering Rust's runtime bounds checks.
This maps to CWE-20: Improper Input Validation, in which untrusted data is not sufficiently checked before it is used to drive memory and control-flow decisions in cryptographic parsing logic.
Potential impact
- Application or service crash when decrypting malicious SM2 ciphertext
- Termination of worker threads or async tasks handling cryptographic operations
- Denial of service for APIs, microservices, or endpoints that rely on SM2 decryption
- Potential cascading failures in distributed systems if decryption is part of a critical request path or authentication flow
General mitigation guidance
Mitigation centers on strengthening input validation and hardening cryptographic parsing paths against malformed data:
- Ensure all ciphertext and DER-encoded fields are length-checked before any slicing or structural parsing.
- Treat all externally sourced ciphertext as untrusted and validate minimum sizes, expected structure, and field boundaries early in the decryption pipeline.
- Prefer safe parsing routines that return structured errors rather than relying on panics to signal invalid input.
- Design application architecture such that a panic in cryptographic code cannot bring down the entire process, for example by isolating risky parsing in separate workers or processes where feasible.
- Apply defensive coding guidelines to cryptographic libraries, emphasizing constant-time behavior where needed and robust handling of malformed inputs that fails closed with explicit errors instead of crashes.
How teams detect issues like this
Organizations can detect and monitor similar issues using multiple approaches:
- Static analysis and code scanning: Look for slice operations (
split_at, indexing, slicing) where offsets or indices are derived from untrusted input without prior explicit length checks. - Manual code review: Pay special attention to cryptographic parsing code, DER decoding routines, and buffer handling logic, verifying clear preconditions on buffer sizes and structural invariants before slicing.
- Fuzz testing: Apply fuzzers to SM2 decryption and other cryptographic entry points, targeting malformed, truncated, and oversized ciphertexts to identify panic-inducing paths.
- Runtime monitoring: Track panics and crashes in production, correlating them with specific request types or crypto operations, and treat recurring panics on invalid input as potential denial-of-service vectors.
- Policy enforcement: Incorporate secure coding guidelines for buffer management and input validation into CI/CD pipelines, with checks to prevent new code that slices based on unchecked external input.

