Repository navigation
Conversation
from_components_inner builds Montgomery parameters and (for the 2-prime case) an O(bits^2) product of the supplied primes before any validation runs. On the public-key path PublicKey::new rejects a modulus over MAX_SIZE first, so that heavy work is bounded; the private component-construction API applied no such bound, letting from_components run seconds of CPU on an attacker-sized modulus before rejecting it (CPU-exhaustion DoS on untrusted private-key import). Reject n over PublicKey::MAX_SIZE in from_components_inner, before the heavy path. RustCrypto#793 applies the same bound at the PKCS#1 decode layer; this covers the direct component-construction API (from_components / _with_large_exponent / _with_wide_primes) too.
Author
|
Closing this — on reflection this DoS residual (reachable in released 0.10.0) is better routed through the project's security reporting than a public PR. Will re-raise via the appropriate private channel. Apologies for the noise. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The public-key path caps the modulus size —
PublicKey::newrejects a modulus abovePublicKey::MAX_SIZE(8192 bits) withError::ModulusTooLargebefore doing any heavy work. The private-key component-construction path does not.PrivateKey::from_components/from_p_q/from_primes(the shared private constructor insrc/private_key.rs, ~line 240) proceed straight intoBoxedMontyParams::new(n)(Montgomery setup) and theO(bits²)prime-product check on a caller-supplied modulus of any size, before validation can reject it.So an application that constructs a
PrivateKeyfrom untrusted components (e.g. a key-management or import surface that accepts rawn, e, d, primes) can be made to burn unbounded CPU/memory on an attacker-sized modulus — a DoS — even though the equivalent public modulus would be rejected immediately.Honest scope
masteras90fb187) already caps the PKCS#1 / PKCS#8 decode path. This PR is not that; it covers the direct component-construction API (from_components*/from_p_q/from_primes), which Bound PKCS#1 modulus sizes before bigint conversion #793 does not touch.Residual confirmed present on
master90fb187: the onlyModulusTooLargereference inprivate_key.rsis a test ofPublicKey::new; the private constructor has no size guard.Change
Adds the same bound the public path uses, early in the private component constructor, before the Montgomery setup and product:
Tests
from_components_rejects_oversized_modulus— a 9000-bit modulus (>MAX_SIZE8192) passed tofrom_componentsreturnsErr(Error::ModulusTooLarge)before the heavy work runs.cargo test --lib: 69 passed, 0 failed.One file,
src/private_key.rs. MirrorsPublicKey::new; reuses the existingError::ModulusTooLargevariant.Opened as a draft for maintainer review. Reported by Portll john@portll.net.