Skip to content

Integer overflow in the "v2g_incoming_v2gtp" function

Critical
Pietfried published GHSA-8g9q-7qr9-vc96 Jul 10, 2024

Package

No package listed

Affected versions

< 2024.6.0

Patched versions

2024.3.1 , 2024.6.0

Description

Summary

An integer overflow in the "v2g_incoming_v2gtp" function in the v2g_server.cpp implementation can allow a remote attacker to overflow the process' heap

Details

In the V2G server implemented in "modules\EvseV2G\v2g_server.cpp" the "v2g_incoming_v2gtp" function appears to contain an integer overflow after reading the V2GTP 4-bytes header:

rv = read_v2gtpHeader(conn->buffer, &conn->payload_len);
if (rv == -1) {
    dlog(DLOG_LEVEL_ERROR, "Invalid v2gtp header");
    return -1;
}

if (conn->payload_len + V2GTP_HEADER_LENGTH > DEFAULT_BUFFER_SIZE) {
    dlog(DLOG_LEVEL_ERROR, "payload too long: have %d, would need %d", DEFAULT_BUFFER_SIZE,
         conn->payload_len + V2GTP_HEADER_LENGTH);

    /* we have no way to flush/discard remaining unread data from the socket without reading it in chunks,
     * but this opens the chance to bind us in a "endless" read loop; so to protect us, simply close the connection
     */

    return -1;
}
/* read request */
rv = connection_read(conn, &conn->buffer[V2GTP_HEADER_LENGTH], conn->payload_len);

Providing any value between [0xFFFF FFF8, 0xFFFF FFFF] in these 4 bytes as part of the V2GTP header will cause the check in line 165 to pass.
And since that large length is later passed to "connection_read", the server will accept any number of bytes to the heap buffer "con->buffer",
thereby overflowing the heap.

PoC

This can reproduced when the EvseV2G module is running and sending the following nc command will trigger the bug (IPv6 address may change of course)

$ python3 -c "import sys; sys.stdout.buffer.write(b'\x01\xFE\x80\x01\xFF\xFF\xFF\xFF' + b'A'*0x3000)" | nc -6 -v fe80::215:5dff:fe2e:ea25%2 61341

Impact

Remote code execution is definitely possible from overwriting the heap in a standard Linux process, exploitation feasibility is still being investigated however an immediate crash can be observed by triggering the vulnerability with the nc command specified above.
Because of that, "Attack Complexity" is marked as "High" for the CVSS 3.1 score

Patch

This vulnerability has been fixed with f73620c which is included in the releases https://github.com/EVerest/everest-core/releases/tag/2024.3.1 and https://github.com/EVerest/everest-core/releases/tag/2024.6.0 .

Credits

Shaked Delarea of Argus Cyber Security

Severity

Critical

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
High
Privileges required
None
User interaction
None
Scope
Changed
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:C/C:H/I:H/A:H

CVE ID

CVE-2024-37310

Credits