Skip to content

fix out-of-bounds write in make_signature for mismatched EC key#155

Open
tanjiroK-coder wants to merge 1 commit into
OpenPrinting:masterfrom
tanjiroK-coder:jwt-sign-curve-overflow
Open

fix out-of-bounds write in make_signature for mismatched EC key#155
tanjiroK-coder wants to merge 1 commit into
OpenPrinting:masterfrom
tanjiroK-coder:jwt-sign-curve-overflow

Conversation

@tanjiroK-coder

Copy link
Copy Markdown

make_signature builds the raw ECDSA signature by writing each coordinate into a fixed signature buffer whose halves are sized from the algorithm (32 bytes for ES256), but the coordinate lengths come from the key's curve. find_key only matches EC keys by kty and the ES256-ES512 range, and the kid lookup ignores the algorithm entirely, so nothing stops a P-521 key being used for ES256. When that happens BN_num_bytes(r) is up to 66 while sig_len is 32, so BN_bn2bin(r, signature + sig_len - r_len) writes 34 bytes before the buffer and corrupts the stack frame of cupsJWTSign. I hit it feeding a P-521 key from cupsJWTMakePrivateKey(CUPS_JWA_ES512) into cupsJWTSign(jwt, CUPS_JWA_ES256, jwk) under asan, which faults inside cupsJWTSign. 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 a testjwt case that crashed before the change and passes after.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant