Skip to content

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

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

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.

@michaelrsweet michaelrsweet self-assigned this Jul 26, 2026
@michaelrsweet michaelrsweet added bug Something isn't working priority-low labels Jul 26, 2026
@michaelrsweet michaelrsweet added this to the Stable milestone Jul 26, 2026
@michaelrsweet

Copy link
Copy Markdown
Member

I would argue this is API misuse, but agree that we shouldn't crash.

@michaelrsweet

Copy link
Copy Markdown
Member

[master fbb707d] Only store signature when the length fits (Issue #155)

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

Labels

bug Something isn't working priority-low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants