fix out-of-bounds write in make_signature for mismatched EC key#155
Open
tanjiroK-coder wants to merge 1 commit into
Open
fix out-of-bounds write in make_signature for mismatched EC key#155tanjiroK-coder wants to merge 1 commit into
tanjiroK-coder wants to merge 1 commit into
Conversation
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.
make_signaturebuilds the raw ECDSA signature by writing each coordinate into a fixedsignaturebuffer whose halves are sized from the algorithm (32 bytes forES256), but the coordinate lengths come from the key's curve.find_keyonly matches EC keys byktyand theES256-ES512range, and thekidlookup ignores the algorithm entirely, so nothing stops aP-521key being used forES256. When that happensBN_num_bytes(r)is up to 66 whilesig_lenis 32, soBN_bn2bin(r, signature + sig_len - r_len)writes 34 bytes before the buffer and corrupts the stack frame ofcupsJWTSign. I hit it feeding a P-521 key fromcupsJWTMakePrivateKey(CUPS_JWA_ES512)intocupsJWTSign(jwt, CUPS_JWA_ES256, jwk)under asan, which faults insidecupsJWTSign. This rejects the signature when either coordinate is larger than the algorithm's half so a mismatched key fails cleanly, and I made the GnuTLS branch bail the same way for consistency. Added atestjwtcase that crashed before the change and passes after.