Niska

Vyper's external calls can overflow return data to return input buffer

  • Ujawniono: 02.02.2024
  • Aktualizacja: 11.10.2026 15:17

Summary

When calls to external contracts are made, we write the input buffer starting at byte 28, and allocate the return buffer to start at byte 0 (overlapping with the input buffer). When checking RETURNDATASIZE for dynamic types, the size is compared only to the minimum allowed size for that type, and not to the returned value's length. As a result, malformed return data can cause the contract to mistake data from the input buffer for returndata.

This advisory is given a severity of "Low" because when the called contract returns invalid ABIv2 encoded data, the calling contract can read different invalid data (from the dirty buffer) than the called contract returned.

Details

When arguments are packed for an external call, we create a buffer of size max(args, return_data) + 32. The input buffer is placed in this buffer (starting at byte 28), and the return buffer is allocated to start at byte 0. The assumption is that we can reuse the memory becase we will not be able to read past RETURNDATASIZE.

python
if fn_type.return_type is not None:
    return_abi_t = calculate_type_for_external_return(fn_type.return_type).abi_type

    # we use the same buffer for args and returndata,
    # so allocate enough space here for the returndata too.
    buflen = max(args_abi_t.size_bound(), return_abi_t.size_bound())
else:
    buflen = args_abi_t.size_bound()

buflen += 32  # padding for the method id

When data is returned, we unpack the return data by starting at byte 0. We check that RETURNDATASIZE is greater than the minimum allowed for the returned type:

python
if not call_kwargs.skip_contract_check:
    assertion = IRnode.from_list(
        ["assert", ["ge", "returndatasize", min_return_size]],
        error_msg="returndatasize too small",
    )
    unpacker.append(assertion)

This check ensures that any dynamic types returned will have a size of at least 64. However, it does not verify that RETURNDATASIZE is as large as the length word of the dynamic type.

As a result, if a contract expects a dynamic type to be returned, and the part of the return data that is read as length includes a size that is larger than the actual RETURNDATASIZE, the return data read from the buffer will overrun the actual return data size and read from the input buffer.

Proof of Concept

This contract calls an external contract with two arguments. As the call is made, the buffer includes:

  • byte 28: method_id
  • byte 32: first argument (0)
  • byte 64: second argument (hash)

The return data buffer begins at byte 0, and will return the returned bytestring, up to a maximum length of 96 bytes.

python
interface Zero:
    def sneaky(a: uint256, b: bytes32) -> Bytes[96]: view

@external
def test_sneaky(z: address) -> Bytes[96]:
    return Zero(z).sneaky(0, keccak256("oops"))

On the other side, imagine a simple contract that does not, in fact, return a bytestring, but instead returns two uint256s. I've implemented it in Solidity for ease of use with Foundry:

solidity
function sneaky(uint a, bytes32 b) external pure returns (uint, uint) {
    return (32, 32);
}

The return data will be parsed as a bytestring. The first 32 will point us to byte 32 to read the length. The second 32 will be perceived as the length. It will then read the next 32 bytes from the return data buffer, even though those weren't a part of the return data.

Since these bytes will come from byte 64, we can see above that the hash was placed there in the input buffer.

If we run the following Foundry test, we can see that this does in fact happen:

solidity
function test__sneakyZeroReturn() public {
    ZeroReturn z = new ZeroReturn();
    c = SuperContract(deployer.deploy("src/loose/", "ret_overflow", ""));
    console.logBytes(c.test_sneaky(address(z)));
}
md
Logs:
  0xd54c03ccbc84dd6002c98c6df5a828e42272fc54b512ca20694392ca89c4d2c6

Patches

Patched in https://github.com/vyperlang/vyper/pull/3925, https://github.com/vyperlang/vyper/pull/4091, https://github.com/vyperlang/vyper/pull/4144, https://github.com/vyperlang/vyper/pull/4060.

Impact

Malicious or mistaken contracts returning the malformed data can result in overrunning the returned data and reading return data from the input buffer.

Czego dotyczy

Kliknij technologię, aby zobaczyć wszystkie dotyczące jej podatności.

PlatformaPaczkaPodatne wersjePoprawka w wersji
Python (PyPI) vyper < 0.4.0 0.4.0

Odnośniki

Ocena CVSS 3.7/10
Wektor CVSS
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:N
Słabość (CWE)
CWE-119
Platforma
Python (PyPI)
Paczka
vyper
Ujawniono
02.02.2024
Aktualizacja
11.10.2026 15:17

Źródła i licencje

OSV / GitHub Advisory Database - PYSEC-2024-148 - PyPA Advisory Database; CC BY 4.0

OSV / GitHub Advisory Database - GHSA-gp3w-2v2m-p686 - CC BY 4.0

Historia podatności: vyper

Wszystkie opisane podatności tej paczki (Python (PyPI)), od najnowszej. Widać, czy to jednorazowa wpadka, czy paczka, której trzeba pilnować.

Wszystkie (47) w archiwum
Wszystkich wpisów
47
Pierwsza → ostatnia
03.2020 10.2026
Bez poprawki
5
Wykorzystywana w atakach
0

Rozkład istotności

  • Krytyczna 3
  • Wysoka 14
  • Średnia 20
  • Niska 10

Ujawnienia w latach

  1. 2020: 1
  2. 2021: 5
  3. 2022: 4
  4. 2023: 14
  5. 2024: 14
  6. 2025: 6
  7. 2026: 3
Istotność:
  1. Krytyczna · 9.8 CVE-2024-24563 < 0.4.0 0.4.0
  2. Vyper's external calls can overflow return data to return input buffer ten wpis
    Niska · 3.7 CVE-2024-24560 < 0.4.0 0.4.0
  3. Krytyczna · 9.8 CVE-2024-24561 < 0.4.0 0.4.0
  4. Wysoka · 7.3 CVE-2024-22419 >= 0.3.0, < 0.4.0 0.4.0
  5. Wysoka · 7.5 CVE-2023-46247 < 0.3.8 0.3.8
  6. Wysoka · 8.1 CVE-2023-42443 >= 0.3.4, < 0.3.10 0.3.10
  7. Krytyczna · 8.7 CVE-2023-39363 >= 0.2.15, < 0.3.1 0.3.1
  8. Wysoka · 7.5 CVE-2023-32058 < 0.3.8 0.3.8
  9. Wysoka · 7.5 CVE-2023-30837 < 0.3.8 0.3.8
  10. Wysoka · 7.5 CVE-2023-30629 >= 0.3.1, < 0.3.8 0.3.8
  11. Wysoka · 7.5 CVE-2022-29255 < 0.3.4 0.3.4
  12. Wysoka · 7.1 CVE-2022-24788 < 0.3.2 0.3.2
  13. Wysoka · 7.5 CVE-2022-24787 < 0.3.2 0.3.2
  14. Wysoka ghsa-7f92-rr6w-cq64 >= 0.2.13, < 0.2.15 0.2.15

Dowiedz się, które podatności dotyczą Twojej aplikacji

Po podłączeniu integracji DockRay i włączeniu raportowania oprogramowania DockRay porównuje zgłoszone wersje komponentów ze znanymi podatnościami i powiadamia o potwierdzonych dopasowaniach. Zakres zależy od obsługiwanej technologii i dostępnych biuletynów.

Podłącz swoją aplikację
Newsletter DockRay

Bezpieczeństwo aplikacji w Twojej skrzynce

Najważniejsze podatności, konkretne zalecenia i praktyczne wskazówki dla Twoich aplikacji. Wybierz technologie i śledź to, co ma znaczenie dla Twojego projektu.

  • Codzienne zestawienie nowych podatności, także krytycznych.
  • Powiadomienia o ważnych aktualizacjach.
  • Praktyczne porady o bezpieczeństwie i monitoringu aplikacji.

Pozostaw puste, aby otrzymywać informacje o wszystkich technologiach.

Zapis jest bezpłatny. Wypiszesz się jednym kliknięciem w wiadomości.