examples/client: add cert-name length bounds check in ParseRFC6187#1052
Open
yosuke-wolfssl wants to merge 1 commit into
Open
examples/client: add cert-name length bounds check in ParseRFC6187#1052yosuke-wolfssl wants to merge 1 commit into
yosuke-wolfssl wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request hardens the examples/client RFC6187 parsing logic by adding a missing length bounds check in ParseRFC6187, preventing out-of-bounds reads when handling attacker-controlled certificate name lengths in SSH host-key blobs. This brings the examples/client/common.c implementation back in sync with the existing guarded version in apps/wolfssh/common.c.
Changes:
- Add a post-
ato32()bounds check for the peer-supplied RFC6187 name lengthlbefore advancing the parse offsetm. - Return
WS_BUFFER_Eimmediately on oversizedlto avoid unsigned underflow in laterinSz - mchecks.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1052
Scan targets checked: wolfssh-bugs, wolfssh-src
No new issues found in the changed files. ✅
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.
Summary
ParseRFC6187inexamples/client/common.cread the peer-supplied RFC6187 name lengthlwithato32()and then advancedm += l + sizeof(word32)without validatinglagainstinSz. Becauselis attacker-controlled (the leading length field of the SSH host-key blob), a value larger thaninSzpushedmpastinSz. The subsequentinSz - munsigned subtraction then underflowed to a large value, so the< sizeof(word32)bounds test passed andato32(in + m, &count)read past the end of thepubKeybuffer.This adds the same bounds check the sibling
apps/wolfssh/common.ccopy already has, restoring parity between the two implementations.Addressed by f_6267.
Changes
examples/client/common.c: inParseRFC6187, rejectl > inSz - sizeof(word32)withWS_BUFFER_Eimmediately after readingl, before computingm.Why it is correct
inSz < sizeof(word32)check guaranteesinSz - sizeof(word32)cannot underflow.lkeepsm <= inSz, so the laterinSz - msubtractions stay in range and the existing bounds tests work as intended.