CVE-2018-5407 fix: ECC ladder#7593
CVE-2018-5407 fix: ECC ladder#7593bbbrumley wants to merge 3 commits intoopenssl:OpenSSL_1_0_2-stablefrom
Conversation
|
Tagging @romen for review |
| t = ((a->flags ^ b->flags) & BN_FLG_CONSTTIME) & condition; | ||
| a->flags ^= t; | ||
| b->flags ^= t; | ||
|
|
There was a problem hiding this comment.
@mattcaswell I don't know what this new flag BN_FLG_FIXED_TOP is. Should we be swapping it here, too?
There was a problem hiding this comment.
BN_FLG_FIXED_TOP indicates that we haven't called bn_correct_top() on the data, so the d array may be padded with additional 0 values (i.e. top could be greater than the minimal value that it could be). So I think we should be swapping it. Does that suggest we need to make an equivalent change in master/1.1.1?
There was a problem hiding this comment.
Yes, it's the right thing to do. Just in case for reference, BN_FLG_FIXED_TOP is a very special debugging flag and is customarily zero. So that production builds won't be affected. It's not suggestion to not resolve this, only explanation to how it can go unnoticed.
There was a problem hiding this comment.
Thanks @dot-asm ! I'll open a PR for master.
There was a problem hiding this comment.
While we are at it, and while you'll be at it, I'd like to suggest to a) reformat commentary prior BN_consttime_swap to fit 80 chars; b) omit switch at the end and replace it with straight loop. Rationale for b) is that compilers are in better position to decide how to handle loops, nor are straight loops hopeless on contemporary processors. I mean straight loop in machine code is not unlikely to perform better than the current loop-switch combo.
There was a problem hiding this comment.
While we are at it, and while you'll be at it, I'd like to suggest
#7599 is ready, but I'll follow up on another PR on master with your suggested changes after the merge.
The larger issue is the BN_consttime_swap API is not right. It should have a return value, and return errors instead of asserts.
|
FWIW I checked the code paths in |
|
We should wait for @romen to review too. |
romen
left a comment
There was a problem hiding this comment.
Code looks good to me, and I double checked again in gdb that ec_mul_consttime gets called when it's expected and skipped on the verify codepath.
There is the issue of performance loss, that in 1.1.1 was addressed later on by adding scaffolding for specialized implementations of the ladder step: the issue backporting that to 1.0.2 is that it requires altering some of the structs to add new function pointers in the method structures.
Given that the structures in 1.0.2 are not opaque, we might want to think twice about altering those structures to avoid obscure compatibility issues.
Anyway, I believe the scope of this PR should be limited to the security fix backport, and performance should be addressed by a different "feature" PR.
I will delay merge until tomorrow afternoon (let's say 14:00 UTC) to allow other reviewers to dissent on this and comment on the performance issue. (ping @mattcaswell and @paulidale )
| */ | ||
| static int ec_mul_consttime(const EC_GROUP *group, EC_POINT *r, | ||
| const BIGNUM *scalar, const EC_POINT *point, | ||
| BN_CTX *ctx) |
There was a problem hiding this comment.
As a sidenote, in 1.1.1 we also renamed ec_mul_consttime to a more fitting ec_scalar_mul_ladder (during #6690): I believe that, to be consistent with the current status of 1.1.0-stable, it's a good thing to keep ec_mul_consttime for now and replace it when backporting the "ladder scaffold" for specialized implementations.
This way, after merging this PR as it is now:
- 1.0.2 & 1.1.0:
ec_mul_consttime-- only generic ladder (based on rawEC_POINT_dbl+EC_POINT_add); - 1.1.1 & master:
ec_scalar_mul_ladder-- generic ladder + optional specialized implementations
More about performanceAfter this PR gets merged, at some point in the future (right now I don't have enough time available), I plan to open a separate PR to backport the following:
About binary curves, we might want to discuss if we really want to additionally backport #6070 (to unify the scalar multiplication path for prime and binary curves) and then the Lopez-Dahab specialized implementation from #6690. Until we backport the performance improvements we can expect performance degradation similar to what was reported for 1.1.1 during the beta development cycle (e.g., #6512). ConclusionI will hold the merge for one more day to let @paulidale and @mattcaswell comment on this and on the |
|
Note to self: verify what is the status about backport to 1.0.2 of #6116 for future work. Also, if @mattcaswell and @paulidale agree that the current status of this PR is ok and matches its "bug fix" scope, after merging I plan to open a separate issue to track my progress in backporting the above-mentioned PRs and discuss the further backports plan. |
|
Sounds good to me. |
|
Fine by me. I'm less clear about backporting the performance changes. Can you quantify for me the scale of the performance loss - I don't remember? |
|
@mattcaswell , probably we should discuss if we want to backport the performance improvements in a separate issue, but anyway, as a single data point, examining NIST P-384 ECDH using From your comment I would assume you agree on merging this and then figuring out separately if we want to backport the performance improvements, but anyway, I will wait for explicit reapproval from you before merging this. Detailed outputWith current Rebasing #7593 on current |
|
Once this is merged I'll send out a security advisory for it |
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Paul Dale <paul.dale@oracle.com> Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com> (Merged from #7593)
|
Merged as b18162a . Thank you all! |
Low severity timing vulnerability in ECC calculations impacting ECDSA and ECDH. Publicly disclosed but unreleased, pending OpenSSL 1.0.1q Ref: https://www.openssl.org/news/secadv/20181112.txt Ref: openssl/openssl#7593 Upstream: openssl/openssl@b18162a7c Original commit message: CVE-2018-5407 fix: ECC ladder Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Paul Dale <paul.dale@oracle.com> Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com> (Merged from openssl/openssl#7593)
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Paul Dale <paul.dale@oracle.com> Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com> (Merged from openssl/openssl#7593) Gbp-Pq: Name CVE-2018-5407+2018-0735.patch
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Paul Dale <paul.dale@oracle.com> Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com> (Merged from openssl/openssl#7593) Gbp-Pq: Name CVE-2018-5407+2018-0735.patch
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Paul Dale <paul.dale@oracle.com> Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com> (Merged from openssl/openssl#7593) Gbp-Pq: Name CVE-2018-5407+2018-0735.patch
This is a backport of #6009 #6535 #6648 to 1.0.2. In the context of CVE-2018-5407, this changes the code path for generic curves over prime fields from wNAF to ladder scalar multiplication.
Read the technical details.