Repository navigation
wincng: validate Diffie-Hellman public value in ssh2_dh_secret - #2645
Closed
abdul-khaliq-khalid wants to merge 1 commit into
Closed
abdul-khaliq-khalid wants to merge 1 commit into
abdul-khaliq-khalid wants to merge 1 commit into
Conversation
vszakats
reviewed
Oct 2, 2026
Member
|
This triggered a clang-tidy report: |
Member
Since the code isn't touched by this PR, it may be that the touched part indirectly may cause a zero length passed here, or there is new code that checks for a zero length, which makes the analyzer think the same may happen in this other function. Maybe a separate patch is necessary before this one, to tackle it? → PR #2649 |
vszakats
added a commit
that referenced
this pull request
Oct 4, 2026
- check `wcng_bn_resize()` success. The only call where this check was missing. - check if bignum length is non-zero before calling resize. To fix this clang-tidy warning after applying pending PR #2645: ``` src/wincng.c:157:14: error: Call to 'realloc' has an allocation size of 0 bytes [clang-analyzer-optin.portability.UnixAPI,-warnings-as-errors] 157 | bignum = realloc(bn->bignum, length); | ^ [...] src/wincng.c:255:27: note: Value assigned to 'offset' 255 | ret = BCryptEncrypt(hKey, bignum, length, NULL, NULL, 0, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 256 | r->bignum, (ULONG)r->length, &offset, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 257 | BCRYPT_PAD_NONE); | ~~~~~~~~~~~~~~~~ [...] src/wincng.c:259:21: note: Taking true branch 259 | if(BCRYPT_SUCCESS(ret)) | ^ src/wincng.c:260:43: note: Passing value via 2nd parameter 'length' 260 | wcng_bn_resize(r, offset); | ^~~~~~ src/wincng.c:260:25: note: Calling 'wcng_bn_resize' 260 | wcng_bn_resize(r, offset); | ^~~~~~~~~~~~~~~~~~~~~~~~~ [...] src/wincng.c:157:14: note: Call to 'realloc' has an allocation size of 0 bytes 157 | bignum = realloc(bn->bignum, length); | ^ ~~~~~~ ``` Ref: https://github.com/libssh2/libssh2/actions/runs/37005655840/job/110833185040?pr=2645#step:8:62 Bug: #2645 (comment) Closes #2649
vszakats
force-pushed
the
wincng-dh-validate-f
branch
from
October 4, 2026 18:41
cfd8a85 to
01c2ea9
Compare
Member
|
Thanks! (merged the casing nit and fixed the clang-tidy issue via #2649). Tests pass after rebasing to master. |
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.
ssh2_dh_secret() in the Windows CNG backend uses the server's Diffie-Hellman public value f without the range check the other four backends apply through ssh2_dh_validate(), so a malicious server can send f of 0, 1 or p-1 and push the shared secret into a trivial subgroup that openssl, libgcrypt, mbedtls and os400qc3 all reject with LIBSSH2_ERROR_PROTO. This adds a WinCNG ssh2_dh_validate() that enforces 1 < f < p-1 and the same minimum-set-bits check on the big-endian value, and calls it at the top of ssh2_dh_secret() like the other backends do. The shared test_ssh2_dh_validate() in tests/test_simple.c was stubbed out on WinCNG only because the function did not exist, so it now runs against the real implementation too.
Reported-by: yaotushaozhu on github
Ref: GHSA-m9rg-h9jv-9gvh
Follow-up to fcf8307 #2239