RUSTSEC-2020-0006

Source
https://rustsec.org/advisories/RUSTSEC-2020-0006
Import Source
https://github.com/rustsec/advisory-db/blob/osv/crates/RUSTSEC-2020-0006.json
JSON Data
https://api.osv.dev/v1/vulns/RUSTSEC-2020-0006
Aliases
Published
2020-03-24T12:00:00Z
Modified
2023-11-08T04:03:36.095714Z
Severity
  • 7.5 (High) CVSS_V3 - CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N CVSS Calculator
Summary
Flaw in `realloc` allows reading unknown memory
Details

When reallocing, if we allocate new space, we need to copy the old allocation's bytes into the new space. There are old_size number of bytes in the old allocation, but we were accidentally copying new_size number of bytes, which could lead to copying bytes into the realloc'd space from past the chunk that we're bump allocating out of, from unknown memory.

If an attacker can cause reallocs, and can read the realoced data back, this could allow them to read things from other regions of memory that they shouldn't be able to. For example, if some crypto keys happened to live in memory right after a chunk we were bump allocating out of, this could allow the attacker to read the crypto keys.

Beyond just fixing the bug and adding a regression test, I've also taken two additional steps:

  1. While we were already running the testsuite under valgrind in CI, because valgrind exits with the same code that the program did, if there are invalid reads/writes that happen not to trigger a segfault, the program can still exit OK and we will be none the wiser. I've enabled the --error-exitcode=1 flag for valgrind in CI so that tests eagerly fail in these scenarios.

  2. I've written a quickcheck test to exercise realloc. Without the bug fix in this patch, this quickcheck immediately triggers invalid reads when run under valgrind. We didn't previously have quickchecks that exercised realloc because realloc isn't publicly exposed directly, and instead can only be indirectly called. This new quickcheck test exercises realloc via bumpalo::collections::Vec::resize and bumpalo::collections::Vec::shrink_to_fit calls.

Database specific
{
    "license": "CC0-1.0"
}
References

Affected packages

crates.io / bumpalo

Package

Affected ranges

Type
SEMVER
Events
Introduced
3.0.0
Fixed
3.2.1

Ecosystem specific

{
    "affected_functions": null,
    "affects": {
        "os": [],
        "functions": [],
        "arch": []
    }
}

Database specific

{
    "cvss": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N",
    "informational": null,
    "categories": [
        "memory-exposure"
    ]
}