Repository navigation
Conversation
PairingMulNAggregatePkInG1/G2 rejected randBits > 256 but not negative
values. randBits is a signed int passed to C as C.size_t(randBits), so a
negative value wraps to a huge size_t that slips past the signed compare
and reaches POINTonE{1,2}_mult_w5, which then reads past the 32-byte rand
scalar. Extend the guard to reject randBits < 0, matching the <= 0 checks
the other Go nbits entry points already use.
Collaborator
|
Thanks! |
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.
PairingMulNAggregatePkInG1 and PairingMulNAggregatePkInG2 reject randBits > 256 but not negative values. randBits is a signed int handed to C as C.size_t(randBits), so a negative value such as -1 wraps to SIZE_MAX, slips past the signed
> 256comparison, and reaches blst_pairing_chk_n_mul_n_aggr_pk_in_g{1,2} and in turn POINTonE{1,2}_mult_w5. That routine reads the scalar at byte offset about (nbits-1)/8, far past the 32-byte rand Scalar, an out-of-bounds read. The other nbits entry points in the binding already reject non-positive values (MultAssign, MultNAccumulate, P1AffinesMult/P2AffinesMult), so these two were the odd ones out. The fix addsrandBits < 0to the existing guard in the blst_px.tgo template and regenerates blst.go, covering both the PkInG1 and PkInG2 forms.Added a regression test that calls both functions with randBits = -1. It fails on master, where the call falls through the guard, and passes with the fix, which panics with the existing "scalar length mismatch" message. go test in bindings/go stays green.