CVE-2021-45707: Nix Out-of-bounds Write Vulnerability
MODERATECVE-2021-45707 is a MODERATE (CVSS 6.7) out-of-bounds write vulnerability (CWE-787: Out-of-bounds Write) affecting Nix libraries in the crates.io ecosystem. The issue involves out-of-bounds write in nix. Remediation is available by upgrading affected packages to version 0.20.2, 0.21.2, 0.22.2.
CVE-2021-45707 at a Glance
Security Impact
CVSS: 6.7
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H).
How to Fix CVE-2021-45707
To remediate this vulnerability, upgrade all affected Nix dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
Upgrade nix to 0.20.2
Upgrade nix to 0.21.2
Upgrade nix to 0.22.2
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
inspect dependencies for nix
How to Check if You Are Affected
To determine whether your application is affected by CVE-2021-45707, inspect your project dependencies for Nix:
inspect dependencies for nix
Analyze the terminal output to locate any version of Nix in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.20.2), your application is affected.
Note: Verify declared build manifests and deployed runtime container environments.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-787: Out-of-bounds Write, where the product writes data past the end, or before the beginning, of the intended buffer. In Nix, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2021-45707 Affected Nix Versions
3 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
nix
|
crates.io |
≥ 0.16.0
< 0.20.2
|
0.20.2
|
|
nix
|
crates.io |
≥ 0.21.0
< 0.21.2
|
0.21.2
|
|
nix
|
crates.io |
≥ 0.22.0
< 0.22.2
|
0.22.2
|
References
Frequently Asked Questions
What is CVE-2021-45707?
Which Nix versions are affected?
What version fixes CVE-2021-45707?
Is nix affected?
What is the CVSS score of CVE-2021-45707?
What CWE is associated with CVE-2021-45707?
How can I check crates.io dependencies for CVE-2021-45707?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-76w9-p8mg-j927",
"modified" : "2024-02-21T19:15:12Z",
"published" : "2022-01-06T22:07:14Z",
"aliases" : [ "CVE-2021-45707" ],
"summary" : "Out-of-bounds Write in nix",
"details" : "On certain platforms, if a user has more than 16 groups, the nix::unistd::getgrouplist function will call the libc getgrouplist function with a length parameter greater than the size of the buffer it provides, resulting in an out-of-bounds write and memory corruption.\n\nThe libc getgrouplist function takes an in/out parameter ngroups specifying the size of the group buffer. When the buffer is too small to hold all of the requested user's group memberships, some libc implementations, including glibc and Solaris libc, will modify ngroups to indicate the actual number of groups for the user, in addition to returning an error. The version of nix::unistd::getgrouplist in nix 0.16.0 and up will resize the buffer to twice its size, but will not read or modify the ngroups variable. Thus, if the user has more than twice as many groups as the initial buffer size of 8, the next call to getgrouplist will then write past the end of the buffer.\n\nThe issue would require editing /etc/groups to exploit, which is usually only editable by the root user.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:L/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "crates.io",
"name" : "nix"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0.16.0"
}, {
"fixed" : "0.20.2"
} ]
} ]
}, {
"package" : {
"ecosystem" : "crates.io",
"name" : "nix"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0.21.0"
}, {
"fixed" : "0.21.2"
} ]
} ]
}, {
"package" : {
"ecosystem" : "crates.io",
"name" : "nix"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0.22.0"
}, {
"fixed" : "0.22.2"
} ]
} ]
} ],
"references" : [ {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-45707"
}, {
"type" : "WEB",
"url" : "https://github.com/nix-rust/nix/issues/1541"
}, {
"type" : "ADVISORY",
"url" : "https://github.com/advisories/GHSA-wgrg-5h56-jg27"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/nix-rust/nix"
}, {
"type" : "WEB",
"url" : "https://raw.githubusercontent.com/rustsec/advisory-db/main/crates/nix/RUSTSEC-2021-0119.md"
}, {
"type" : "WEB",
"url" : "https://rustsec.org/advisories/RUSTSEC-2021-0119.html"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-787" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2022-01-05T23:13:23Z",
"nvd_published_at" : "2021-12-27T00:15:00Z"
}
}