Bound KEXINIT name-list parsing to prevent pre-auth CPU DoS#1062
Open
yosuke-wolfssl wants to merge 1 commit into
Open
Bound KEXINIT name-list parsing to prevent pre-auth CPU DoS#1062yosuke-wolfssl wants to merge 1 commit into
yosuke-wolfssl wants to merge 1 commit into
Conversation
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1062
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
GetNameListRawparsed peer-supplied SSH name-lists with no per-field byte or token-count limit. For every comma-delimited token it calledNameToId, which does a linear scan of the ~55-entryNameIdMap(aWSTRLEN+XMEMCMPper entry). Repeated unknown tokens are never stored inidList(only the first is kept), so the existing "no more space" guard never trips and the loop keeps scanning every token.A single
SSH_MSG_KEXINITcan carry name-list fields up toMAX_PACKET_SZ, andDoKexInitparses eight of them — before authentication. A field ofa,a,a,…(≈16K single-char tokens in 32 KB) yields O(tokens × map) work per field, measured at ~5.3 ms CPU per max-size KEXINIT. Sustained flooding from parallel connections can saturate a server core without ever completing user auth.This is a pre-authentication algorithmic-complexity DoS addressed by f_5726.
Fix
Cap each parsed name-list in
GetNameListRaw:WOLFSSH_MAX_NAMELIST_SZ(4096) — per-field byte limit, rejected up front.WOLFSSH_MAX_NAMELIST_CNT(64) — per-field name-count limit, checked before eachNameToIdcall.Either limit exceeded returns
WS_BUFFER_E. Both caps are#ifndef-guarded so they remain tunable.The caps sit well above any legitimate list:
NameIdMaphas fewer than 64 entries, and the built-in canned algorithm lists are a few hundred bytes — so real handshakes are unaffected. The bound applies to every list parsed through this function (the canned lists are far under the caps).Tests
Added
TestKexInitNameListCaps()intests/regress.c, driving crafted KEXINIT payloads through the existingwolfSSH_TestDoKexInit→GetNameList→GetNameListRawpath. The tokens are unknown (a,a,…) soidListnever fills for an unrelated reason — the cap is the only thing under test. Both boundaries are locked in:WS_MATCH_KEX_ALGO_EWS_BUFFER_EWS_MATCH_KEX_ALGO_EWS_BUFFER_EVerification
./configure --enable-all+ fullmake check(10 suites) — all PASS.-fsanitize=address,undefined; fullmake check— all PASS, no ASan/UBSan reports. (macOS: LeakSanitizer unsupported, so leak detection disabled; the new test pairs everyWMALLOCwith aWFREEon all paths.)-1050(WS_MATCH_KEX_ALGO_E) instead of-1004(WS_BUFFER_E) and the test failed as expected — confirming it catches the regression.Files changed
wolfssh/internal.h— addWOLFSSH_MAX_NAMELIST_SZ/WOLFSSH_MAX_NAMELIST_CNT.src/internal.c— enforce both caps inGetNameListRaw.tests/regress.c— addTestKexInitNameListCaps()and helpers.