pkcs12: limit PBKDF iteration count to prevent CPU exhaustion#343
pkcs12: limit PBKDF iteration count to prevent CPU exhaustion#343mohammadmseet-hue wants to merge 1 commit intogolang:masterfrom
Conversation
The PKCS#12 PBKDF iteration count is read directly from the input file with no upper bound. A crafted .p12 file (83 bytes) with iterations set to MaxInt32 causes pkcs12.Decode() to block indefinitely. Add a maximum iteration count of 1 million. This is well above typical values (2048-10000) used by real PKCS#12 implementations while preventing malicious files from causing CPU exhaustion. The check is applied in both verifyMac (MAC verification) and pbDecrypterFor (content decryption), which are the two entry points that call pbkdf with the attacker-controlled iteration count.
|
This PR (HEAD: 008f0a8) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/crypto/+/759900. Important tips:
|
|
Message from Gopher Robot: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/759900. |
|
Message from Gopher Robot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/759900. |
The PKCS#12 PBKDF iteration count is read directly from the input file with no upper bound. A crafted .p12 file (83 bytes) with
iterationsset toMaxInt32causespkcs12.Decode()to block indefinitely.Fix: Add a maximum iteration count of 1 million (well above typical values of 2048-10000) in both
verifyMacandpbDecrypterFor, which are the two entry points that callpbkdfwith the attacker-controlled iteration count.Impact: An 83-byte crafted PKCS#12 file blocks
pkcs12.Decode()permanently. Scaling: 1 iteration = 64µs, 10M iterations = 936ms, MaxInt32 = estimated 596,000+ hours.Comparison: Other PBKDF implementations enforce similar limits:
PKCS5_MAX_PBKDF2_ITERATIONS(10M)x/crypto/scryptvalidates its parametershashlib.pbkdf2_hmachas a built-in iteration limit