You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BoringSSL does not hang except when priv == 0. @davidben
Hmm, I'm not able to repro this. To make sure I'm trying the right thing, this is if I use the test program, but replacing the priv_key line with BN_dec2bn(&priv_key, "0");?
Thanks for the ping, Guido, and apologies for the breakage. Our tree has
a workaround in place now.
This particular example prints X since we happen to hit a 1 < q check,
but it's easy to get it to hang on LibreSSL, too (e.g., with q = 2). All
three projects share very similar code here, so I suspect we all end up
computing s as 0 (the examples I found had x * r = 0 (mod q), but I
haven't had the chance to look very closely) and goto redo indefinitely.
So I think Boring is doing the right thing by limiting the lengths of q
(we have such checks elsewhere). I suppose it would also make sense to
impose a lower limit len parameter of DSA_sign(), too. After all, a hash
function of lower security strength than the one implied by p and q
should not be used. Finally, I don't see why we would want to redo
indefinitely (here and in ECDSA_sign()). At some point we should
probably just give up and throw an error.
Is there more to it than that?
This reminded me that @hannob had reported something similar way back, but it slipped through, so that series also fixes that report. On the BoringSSL side, I think there were a few things going on:
First, we allowed the private key to be zero on import. Even though the "domain parameters" are valid, we still need to do this check because, as you found, zero private key + zero hash will never converge. So that series fixes that in our DSA and ECDSA implementations.
Second, there's deeper problem with how the DSA was specificied. DSA and ECDSA have important preconditions in what FIPS 186-4 and 186-5 calls "domain parameters". When those preconditions aren't met, all assumptions in the algorithms go out the window, including whether the retry loop converges. Unfortunately, the 186 documents were catastrophic failures in how to define cryptography, particularly in DSA. By failing to pick parameters, they force every system account for arbitrary domain parameters, despite the important differences they have from key material.
This notion empirically did not get through to folks. X.509 encodes DSA domain parameters by coefficients, and has a mode where it does the same for ECDSA. OpenSSL's APIs treat domain parameters as just one of many things you can parse or manually configure. This was all incorrect. As a result, it is very easy for untrusted domain parameters flow into a system. And thus we have this infinite loop, and previously OpenSSL had CVE-2022-0778.
The right way to do this would have been to do everything a la ECDSA named curves: named, well-known DSA parameters, with no mechanism for arbitrary domain parameters at all. But that's not what happened, and the specification made it very hard to do this.
While priv == 0 isn't a loop from invalid domain parameters, there are other infinite loop cases BoringSSL which are. As @botovq suggests, there's no real reason to retry indefinitely. (Really there's no real reason to retry at all. For valid groups, needing to retry even once happens with negligible probability.) So while the root cause is, IMO, elsewhere, it's too late to fix the root cause, so we're going to cap the loop in (EC)DSA.
Activity
davidben commentedon Feb 11, 2023
Hmm, I'm not able to repro this. To make sure I'm trying the right thing, this is if I use the test program, but replacing the
priv_keyline withBN_dec2bn(&priv_key, "0");?davidben commentedon Feb 11, 2023
Oh, it's not doing anything because we reject any q values that aren't exactly 160-, 224-, or 256-bit, as of https://boringssl-review.googlesource.com/c/boringssl/+/42504
If I adjust q to be in size and then put g in bounds, I can repro. Looking...
botovq commentedon Feb 11, 2023
davidben commentedon Feb 13, 2023
Fixes for BoringSSL:
This reminded me that @hannob had reported something similar way back, but it slipped through, so that series also fixes that report. On the BoringSSL side, I think there were a few things going on:
First, we allowed the private key to be zero on import. Even though the "domain parameters" are valid, we still need to do this check because, as you found, zero private key + zero hash will never converge. So that series fixes that in our DSA and ECDSA implementations.
Second, there's deeper problem with how the DSA was specificied. DSA and ECDSA have important preconditions in what FIPS 186-4 and 186-5 calls "domain parameters". When those preconditions aren't met, all assumptions in the algorithms go out the window, including whether the retry loop converges. Unfortunately, the 186 documents were catastrophic failures in how to define cryptography, particularly in DSA. By failing to pick parameters, they force every system account for arbitrary domain parameters, despite the important differences they have from key material.
This notion empirically did not get through to folks. X.509 encodes DSA domain parameters by coefficients, and has a mode where it does the same for ECDSA. OpenSSL's APIs treat domain parameters as just one of many things you can parse or manually configure. This was all incorrect. As a result, it is very easy for untrusted domain parameters flow into a system. And thus we have this infinite loop, and previously OpenSSL had CVE-2022-0778.
The right way to do this would have been to do everything a la ECDSA named curves: named, well-known DSA parameters, with no mechanism for arbitrary domain parameters at all. But that's not what happened, and the specification made it very hard to do this.
While priv == 0 isn't a loop from invalid domain parameters, there are other infinite loop cases BoringSSL which are. As @botovq suggests, there's no real reason to retry indefinitely. (Really there's no real reason to retry at all. For valid groups, needing to retry even once happens with negligible probability.) So while the root cause is, IMO, elsewhere, it's too late to fix the root cause, so we're going to cap the loop in (EC)DSA.
Reject zero ECDSA keys in EC_KEY_set_private_key
Add more DSA consistency checks.
Cap the number of ECDSA and DSA sign iterations.
guidovranken commentedon Feb 23, 2023
Now that the patches have been merged, I have confirmed that there are no more issues with DSA in BoringSSL.
Fix infinite loops in DSA sign code.
47 remaining items
Fix infinite loops in DSA sign code.
Make DSA_sign() test for negative p,q,g values.
Fix infinite loops in DSA sign code.
Make DSA_sign() test for negative p,q,g values.
Fix infinite loops in DSA sign code.
Make DSA_sign() test for negative p,q,g values.
Consistently reject large p and large q in DH
Consistently reject large p and large q in DH
Consistently reject large p and large q in DH
Consistently reject large p and large q in DH
Fix infinite loops in DSA sign code.
Make DSA_sign() test for negative p,q,g values.
Fix infinite loops in DSA sign code.
Make DSA_sign() test for negative p,q,g values.
Fix infinite loops in DSA sign code.