Bug 1731324 (CVE-2019-13115)

Summary: CVE-2019-13115 libssh2: integer overflow in kex_method_diffie_hellman_group_exchange_sha256_key_exchange in kex.c leads to out-of-bounds write
Product: [Other] Security Response Reporter: Dhananjay Arunesh <darunesh>
Component: vulnerabilityAssignee: Red Hat Product Security <security-response-team>
Status: CLOSED ERRATA QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: unspecifiedCC: djuran, kdudka, paul
Target Milestone: ---Keywords: Security
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: libssh2 1.9.0 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-10-27 10:46:54 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1731325, 1732662, 1732663, 1732664, 1732666    
Bug Blocks: 1731326    

Description Dhananjay Arunesh 2019-07-19 06:12:16 UTC
A vulnerability was discovered in libssh2 before 1.9.0, kex_method_diffie_hellman_group_exchange_sha256_key_exchange in kex.c has an integer overflow that could lead to an out-of-bounds write in the way packets are read from the server. A remote attacker who compromises a SSH server may be able to execute code on the client system when a user connects to the server. This is related to an _libssh2_check_length mistake, and is different from the various issues fixed in 1.8.1, such as CVE-2019-3855.

Reference:
https://libssh2.org/changes.html
https://github.com/libssh2/libssh2/pull/350
https://github.com/libssh2/libssh2/compare/02ecf17...42d37aa
https://blog.semmle.com/libssh2-integer-overflow/

Comment 1 Dhananjay Arunesh 2019-07-19 06:13:05 UTC
Created libssh2 tracking bugs for this issue:

Affects: fedora-all [bug 1731325]

Comment 3 Huzaifa S. Sidhpurwala 2019-07-24 04:51:35 UTC
External References:

https://blog.semmle.com/libssh2-integer-overflow/

Comment 4 Huzaifa S. Sidhpurwala 2019-07-24 05:06:47 UTC
This is an out-of-bounds read flaw in libssh2, which can be triggered by a malicious MITM SSH server. The flaw can be triggered during the initial Diffie-Hellman key change, therefore no authentication is required by the attacker. This flaw can cause applications compiled with libssh2 to crash. 

However, I believe that a more carefully chosen offset could lead to an information disclosure as it appears that the memory which is read is subsequently returned to the server. The exploitability will depend on the heap layout. 

In libssh2 versions after 1.8.2 the flaw exists in the function  _libssh2_check_length(). Older versions however have no bounds checking at all, and the flaw manifests itself at: https://github.com/libssh2/libssh2/blob/02ecf17a6d5f9837699e8fb3aad0c804caa67eeb/src/kex.c#L1675

The problem is that p_len contains an untrusted value, so the subsequent reads from s could be out-of-bounds.

Comment 9 Kamil Dudka 2019-07-24 13:02:11 UTC
(In reply to Huzaifa S. Sidhpurwala from comment #2)
> Upstream patch at:
> https://github.com/doorsdown/libssh2/commit/
> 7e7189e013db15c6306fab0ddb38c020c0de81ed

The above URL refers to some non-authoritative fork of the project.  This seems to be the actual upstream commit:

https://github.com/libssh2/libssh2/commit/ff1b1557