Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

RUSTSEC-2021-0076 bump libsecp256k1 #9391

Merged
15 commits merged into from
Aug 16, 2021
Merged

Conversation

trevor-crypto
Copy link
Contributor

libsecp256k1 allows overflowing signatures
https://rustsec.org/advisories/RUSTSEC-2021-0076

Changes were made to conform to libsecp256k1 version differences.

Closes #9356

@bkchr bkchr added B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit A0-please_review Pull request needs code review. labels Jul 20, 2021
@bkchr bkchr requested a review from sorpaas July 20, 2021 09:31
@bkchr
Copy link
Member

bkchr commented Jul 20, 2021

@sorpaas please check if that is the right way. I remember that you said something about some migration.

Ok((
secp256k1::Signature::parse_slice(&x.0[0..64]).expect("hardcoded to 64 bytes; qed"),
secp256k1::RecoveryId::parse(x.0[64]).map_err(|_| ())?,
libsecp256k1::Signature::parse_standard_slice(&x.0[0..64]).expect("hardcoded to 64 bytes; qed"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
libsecp256k1::Signature::parse_standard_slice(&x.0[0..64]).expect("hardcoded to 64 bytes; qed"),
libsecp256k1::Signature::parse_overflowing_slice(&x.0[0..64]).expect("hardcoded to 64 bytes; qed"),

We still need this as parse_overflowing_slice for now, then move to parse_standard_slice through a migration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reasoning behind this? (just for my own education)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I see. Some preexisting Signatures may be overflowing so we need to parse them with that

Copy link
Member

@sorpaas sorpaas Jul 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would otherwise be an actual security advisory for Substrate.

Parsing overflowing slice is not dangerous and by itself is safe. The security advisory arises if there are multiple clients being maintained and all of them need to conform to a standard way.

If we change this to parse_standard_slice in Substrate now we need to mark it as a critical security upgrade for Substrate and ask everyone to upgrade, and during this period an attacker can split the chain. On the other hand, if we do it via a migration then it's completely safe, and we can do the migration in our own pace without any security concerns.

The drawback for the later, of course, is that parse_overflowing_slice will exist in Substrate at least for years to come (until when old blocks no longer need to be re-processed by anyone). However, given that the method is actually safe, but just non-standard, it shouldn't be of any problems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you mean by a migration?

Isn't the problem only the old runtimes? So we should introduce a new host function?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. We're on the same page.

sorpaas
sorpaas previously approved these changes Jul 20, 2021
@bkchr
Copy link
Member

bkchr commented Jul 20, 2021

@sorpaas shouldn't we directly introduce the new host function? Host functions support versioning and we already use this versioning for a similar problem with schnorrkel.

@sorpaas
Copy link
Member

sorpaas commented Jul 20, 2021

@bkchr Yeah we should do it.

@bkchr
Copy link
Member

bkchr commented Jul 20, 2021

@trevor-crypto check this out https://github.com/paritytech/substrate/blob/master/primitives/io/src/lib.rs#L599-L600

@trevor-crypto We would need to do something similar here and use parse_overflowing_slice() in the version 1 and version 2 would use parse_standard_slice()

@trevor-crypto
Copy link
Contributor Author

trevor-crypto commented Jul 20, 2021

@bkchr thanks! Found my way there already by furiously grepping for 'host functions". I'm wondering how something like this will work with the TryFrom trait impl, since that is one place where parse_overflowing/standard_slice() needs to be used.

Edit: might be better to just remove the TryFrom impl and usage

@bkchr
Copy link
Member

bkchr commented Jul 20, 2021

@trevor-crypto basically you need to revert c653284 because everything from now need to use the new function. Only the old host function needs to use the old function.

@trevor-crypto
Copy link
Contributor Author

Added version 2 for ecdsa_verify. Please check carefully 🙏

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

primitives/core/src/ecdsa.rs Outdated Show resolved Hide resolved
@bkchr
Copy link
Member

bkchr commented Jul 20, 2021

@sorpaas please also check another time.

@bkchr bkchr dismissed sorpaas’s stale review July 20, 2021 19:01

please review again

}

#[cfg(feature = "full_crypto")]
fn parse_signature(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to parse_standard_signature and parse_overflowing_signature and similarly for all the above verify_ public functions? The priority here should be make sure that all library users get to deliberately choose whether they want standard or overflowing, so we shouldn't be using the same old name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't change the trait fn names, but I changed verify_deprecated to verify_overflowing

Copy link
Member

@sorpaas sorpaas Jul 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't do much unfortunately. If you can't change the other name for standard then I suggest putting the overflowing one back to deprecated.

I don't have huge problems keeping it as is, but we do need to be slightly careful here since misusing overflowing vs standard may be a source of trouble.

Alternatively, we can create a separate structure for the OverflowingSignature and rename the current one to StandardSignature. That would be the best for clarity, but just that it may be a lot of work -- so I guess it's optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sorpaas ok thanks. I will leave it as verify_deprecated, since it also coincides with the names of the other versioned host functions in primitives/io/src/lib.rs.

@trevor-crypto
Copy link
Contributor Author

Rebased with master hoping that the tests would pass 😖

@girazoki
Copy link
Contributor

I wanted to jump in because I see that

fn secp256k1_ecdsa_recover(
also uses secp256k1::Signature::parse_slice. Is there a reason why it does not need to get this change?

Copy link
Member

@sorpaas sorpaas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah @girazoki is right. This PR still misses a few version bumps.

@trevor-crypto
Copy link
Contributor Author

Thanks @girazoki

I guess I missed other places as well like bumping libp2p since libp2p-core uses libsecp256k1 too.

bin/node/browser-testing/Cargo.toml Outdated Show resolved Hide resolved
primitives/core/src/ecdsa.rs Outdated Show resolved Hide resolved
primitives/core/src/ecdsa.rs Outdated Show resolved Hide resolved
@bkchr
Copy link
Member

bkchr commented Aug 16, 2021

bot merge

@ghost
Copy link

ghost commented Aug 16, 2021

Waiting for commit status.

@trevor-crypto
Copy link
Contributor Author

@bkchr Thanks for applying those fixes!

@ghost
Copy link

ghost commented Aug 16, 2021

Merge aborted: Checks failed for 00e976a

@bkchr
Copy link
Member

bkchr commented Aug 16, 2021

bot merge force

@ghost
Copy link

ghost commented Aug 16, 2021

Trying merge.

@ghost ghost merged commit 08cac00 into paritytech:master Aug 16, 2021
Neopallium pushed a commit to PolymeshAssociation/substrate that referenced this pull request Sep 2, 2021
* RUSTSEC-2021-0076 bump libsecp256k1

libsecp256k1 allows overflowing signatures
https://rustsec.org/advisories/RUSTSEC-2021-0076

Changes were made to conform to libsecp256k1 version differences.

Closes paritytech#9356

* parse_standard_slice() -> parse_overflowing_slice()

* Added v2 host function for ecdsa_verify

* Add feature tag over helpers

* Added ecdsa_verify v2 to test runner

* PR feedback

- Spaces -> tabs
- renamed two helper functions

* Fixed imports after rebasing

* Bump rest of libsecp256k1

* Add version2 for ecdsa pubkey recovery

* Update primitives/core/src/ecdsa.rs

* Update primitives/core/src/ecdsa.rs

* Update Cargo.lock

Co-authored-by: Bastian Köcher <[email protected]>
gilescope pushed a commit that referenced this pull request Sep 6, 2021
* RUSTSEC-2021-0076 bump libsecp256k1

libsecp256k1 allows overflowing signatures
https://rustsec.org/advisories/RUSTSEC-2021-0076

Changes were made to conform to libsecp256k1 version differences.

Closes #9356

* parse_standard_slice() -> parse_overflowing_slice()

* Added v2 host function for ecdsa_verify

* Add feature tag over helpers

* Added ecdsa_verify v2 to test runner

* PR feedback

- Spaces -> tabs
- renamed two helper functions

* Fixed imports after rebasing

* Bump rest of libsecp256k1 (and libp2p)

libp2p also uses libsecp256k1 so it is required to be bumped too, along
with all the version difference changes.

* Add version2 for ecdsa pubkey recovery

* libp2p rebase master fixes

* Fix test panic when non Behaviour event is returned

* Update bin/node/browser-testing/Cargo.toml

* Update primitives/core/src/ecdsa.rs

* Update primitives/core/src/ecdsa.rs

* Update Cargo.lock

Co-authored-by: Bastian Köcher <[email protected]>
adamdossa pushed a commit to PolymeshAssociation/substrate that referenced this pull request Sep 6, 2021
* RUSTSEC-2021-0076 bump libsecp256k1

libsecp256k1 allows overflowing signatures
https://rustsec.org/advisories/RUSTSEC-2021-0076

Changes were made to conform to libsecp256k1 version differences.

Closes paritytech#9356

* parse_standard_slice() -> parse_overflowing_slice()

* Added v2 host function for ecdsa_verify

* Add feature tag over helpers

* Added ecdsa_verify v2 to test runner

* PR feedback

- Spaces -> tabs
- renamed two helper functions

* Fixed imports after rebasing

* Bump rest of libsecp256k1

* Add version2 for ecdsa pubkey recovery

* Update primitives/core/src/ecdsa.rs

* Update primitives/core/src/ecdsa.rs

* Update Cargo.lock

Co-authored-by: Bastian Köcher <[email protected]>
bkchr added a commit that referenced this pull request Sep 7, 2021
* RUSTSEC-2021-0076 bump libsecp256k1 (#9391)

* RUSTSEC-2021-0076 bump libsecp256k1

libsecp256k1 allows overflowing signatures
https://rustsec.org/advisories/RUSTSEC-2021-0076

Changes were made to conform to libsecp256k1 version differences.

Closes #9356

* parse_standard_slice() -> parse_overflowing_slice()

* Added v2 host function for ecdsa_verify

* Add feature tag over helpers

* Added ecdsa_verify v2 to test runner

* PR feedback

- Spaces -> tabs
- renamed two helper functions

* Fixed imports after rebasing

* Bump rest of libsecp256k1 (and libp2p)

libp2p also uses libsecp256k1 so it is required to be bumped too, along
with all the version difference changes.

* Add version2 for ecdsa pubkey recovery

* libp2p rebase master fixes

* Fix test panic when non Behaviour event is returned

* Update bin/node/browser-testing/Cargo.toml

* Update primitives/core/src/ecdsa.rs

* Update primitives/core/src/ecdsa.rs

* Update Cargo.lock

Co-authored-by: Bastian Köcher <[email protected]>

* Use coherent prost crate  versions (#9676)

* Bump node-browser-testing deps on prost

Co-authored-by: Trevor Arjeski <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: Andreas Doerr <[email protected]>
@trevor-crypto trevor-crypto deleted the libsecp-rustsec branch September 7, 2021 19:58
cmichi pushed a commit that referenced this pull request Sep 9, 2021
* RUSTSEC-2021-0076 bump libsecp256k1 (#9391)

* RUSTSEC-2021-0076 bump libsecp256k1

libsecp256k1 allows overflowing signatures
https://rustsec.org/advisories/RUSTSEC-2021-0076

Changes were made to conform to libsecp256k1 version differences.

Closes #9356

* parse_standard_slice() -> parse_overflowing_slice()

* Added v2 host function for ecdsa_verify

* Add feature tag over helpers

* Added ecdsa_verify v2 to test runner

* PR feedback

- Spaces -> tabs
- renamed two helper functions

* Fixed imports after rebasing

* Bump rest of libsecp256k1 (and libp2p)

libp2p also uses libsecp256k1 so it is required to be bumped too, along
with all the version difference changes.

* Add version2 for ecdsa pubkey recovery

* libp2p rebase master fixes

* Fix test panic when non Behaviour event is returned

* Update bin/node/browser-testing/Cargo.toml

* Update primitives/core/src/ecdsa.rs

* Update primitives/core/src/ecdsa.rs

* Update Cargo.lock

Co-authored-by: Bastian Köcher <[email protected]>

* Use coherent prost crate  versions (#9676)

* Bump node-browser-testing deps on prost

Co-authored-by: Trevor Arjeski <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
Co-authored-by: Andreas Doerr <[email protected]>
apopiak pushed a commit that referenced this pull request Sep 13, 2021
* RUSTSEC-2021-0076 bump libsecp256k1

libsecp256k1 allows overflowing signatures
https://rustsec.org/advisories/RUSTSEC-2021-0076

Changes were made to conform to libsecp256k1 version differences.

Closes #9356

* parse_standard_slice() -> parse_overflowing_slice()

* Added v2 host function for ecdsa_verify

* Add feature tag over helpers

* Added ecdsa_verify v2 to test runner

* PR feedback

- Spaces -> tabs
- renamed two helper functions

* Fixed imports after rebasing

* Bump rest of libsecp256k1 (and libp2p)

libp2p also uses libsecp256k1 so it is required to be bumped too, along
with all the version difference changes.

* Add version2 for ecdsa pubkey recovery

* libp2p rebase master fixes

* Fix test panic when non Behaviour event is returned

* Update bin/node/browser-testing/Cargo.toml

* Update primitives/core/src/ecdsa.rs

* Update primitives/core/src/ecdsa.rs

* Update Cargo.lock

Co-authored-by: Bastian Köcher <[email protected]>
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RUSTSEC-2021-0076 and libsecp256k1 version in sp-core
5 participants