bound openssh public key parse to its declared length#472
Open
basavaraj-sm05 wants to merge 1 commit into
Open
bound openssh public key parse to its declared length#472basavaraj-sm05 wants to merge 1 commit into
basavaraj-sm05 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.
The OpenSSH v1 private key parser reads the length prefix of the public-key section into
len, and the comment there says it means to limit the parse to that length, but nothing actually applies it. buf_get_pub_key() runs against the whole key blob, so the public-key parse isn't confined to its declared length and can walk past the public-key field into the private-key material that follows. I noticed it while reading the block, since the "restore full length" line right after only makes sense if the length had been narrowed first. It's reachable through dropbearconvert when importing an untrusted OpenSSH key: a file whose public-key length field disagrees with the actual encoded key is accepted rather than rejected. The fix checks len against the bytes remaining and narrows blobbuf with buf_setlen before the parse, then the existing restore puts it back for the private-key half. Valid keys of every type still convert to byte-identical output, and a key with a corrupted public-key length is now turned away.