Skip to content

src: check the return value from _libssh2_bn_*() functions - #1354

Merged
vszakats merged 9 commits into
libssh2:masterfrom
MichaelBuckley:check_libssh2_bn_from_bin
Apr 8, 2024
Merged

vszakats merged 9 commits into
libssh2:masterfrom
MichaelBuckley:check_libssh2_bn_from_bin

Conversation

@MichaelBuckley

@MichaelBuckley MichaelBuckley commented Apr 4, 2024 •

Copy link
Copy Markdown
Contributor

Found by oss-fuzz. In diffie_hellman_sha_algo(), we were calling
_libssh2_bn_from_bin() with data recieved by the server without
checking whether that data was zero-length or ridiculously long.
In the OpenSSL backend, this would cause _libssh2_bn_from_bin()
to fail an allocation, which would eventually lead to a NULL
dereference when the bignum was used.

Add the same check for _libssh2_bn_set_word() and
_libssh2_bn_to_bin().

@vszakats vszakats added the bug label Apr 5, 2024
@vszakats vszakats changed the title Check the return value from _libssh2_bn_from_bin src: check the return value from _libssh2_bn_from_bin Apr 5, 2024
Comment thread src/wincng.c Resolved
@vszakats vszakats changed the title src: check the return value from _libssh2_bn_from_bin src: check the return value from _libssh2_bn_from_bin() Apr 5, 2024
Comment thread src/openssl.h Resolved
Comment thread src/kex.c Resolved
@MichaelBuckley

Copy link
Copy Markdown
Contributor Author

I have no further changes for this PR. Thank you so much, @vszakats for pointing out a few issues.

@vszakats vszakats changed the title src: check the return value from _libssh2_bn_from_bin() src: check the return value from _libssh2_bn_*() functions Apr 8, 2024
@vszakats
vszakats merged commit 95c824d into libssh2:master Apr 8, 2024
@vszakats

vszakats commented Apr 8, 2024

Copy link
Copy Markdown
Member

No worries, thank you for the PR!

agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
…#1354)

Found by oss-fuzz. In `diffie_hellman_sha_algo()`, we were calling
`_libssh2_bn_from_bin()` with data recieved by the server without
checking whether that data was zero-length or ridiculously long.
In the OpenSSL backend, this would cause `_libssh2_bn_from_bin()`
to fail an allocation, which would eventually lead to a NULL
dereference when the bignum was used.

Add the same check for `_libssh2_bn_set_word()` and
`_libssh2_bn_to_bin()`.
vszakats added a commit that referenced this pull request Sep 7, 2026
It was returning a non-NULL address on success, which translated to
permanent failure as mapped to this internal crypto API. Fix to match it
with the rest of crypto backends and the expectation of callers.

Reported by Copilot
Bug: #2595 (comment)
Follow-up to 95c824d #1354
Follow-up to c9d40af

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants