GHSA-wgrg-5h56-jg27: Out-of-bounds write in nix :unistd::getgrouplist Vulnerability

HIGH
Published
Advisory Summary

GHSA-wgrg-5h56-jg27 is a HIGH :unistd::getgrouplist vulnerability (General Security Weakness) affecting Out-of-bounds write in nix libraries in the crates.io ecosystem. The issue involves :unistd::getgrouplist. Remediation is available by upgrading affected packages to version 0.20.2, 0.21.2, 0.22.2.

GHSA-wgrg-5h56-jg27 at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-wgrg-5h56-jg27
Severity HIGH
CVSS v3.1 Base Score N/A
CWE Classification General Security Weakness
Affected Product Out-of-bounds write in nix
Package Ecosystem crates.io
Published Date
Last Updated

How to Fix GHSA-wgrg-5h56-jg27

To remediate this vulnerability, upgrade all affected Out-of-bounds write in 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.

nix fixed: 0.20.2
Upgrade nix to 0.20.2
nix fixed: 0.21.2
Upgrade nix to 0.21.2
nix fixed: 0.22.2
Upgrade nix to 0.22.2
Verify Direct and Transitive Dependencies

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 GHSA-wgrg-5h56-jg27, inspect your project dependencies for Out-of-bounds write in nix:

inspect dependencies for nix

Analyze the terminal output to locate any version of Out-of-bounds write in 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 General Security Weakness. In Out-of-bounds write 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

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. The 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 reqested 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. The issue would require editing /etc/groups to exploit, which is usually only editable by the root user.

GHSA-wgrg-5h56-jg27 Affected Out-of-bounds write in nix Versions

3 component(s)
Fixed Versions:
0.20.20.21.20.22.2
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 GHSA-wgrg-5h56-jg27?
GHSA-wgrg-5h56-jg27 is a security vulnerability in Out-of-bounds write in nix involving :unistd::getgrouplist under General Security Weakness.
Which Out-of-bounds write in nix versions are affected?
Affected versions include releases prior to 0.20.2, 0.21.2, 0.22.2 across affected packages: nix.
What version fixes GHSA-wgrg-5h56-jg27?
Upgrading to 0.20.2, 0.21.2, 0.22.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is nix affected?
Yes, nix is affected in releases prior to 0.20.2, 0.21.2, 0.22.2. Upgrade your dependency to 0.20.2, 0.21.2, 0.22.2 or later.
What CWE is associated with GHSA-wgrg-5h56-jg27?
GHSA-wgrg-5h56-jg27 is classified under General Security Weakness.
How can I check crates.io dependencies for GHSA-wgrg-5h56-jg27?
Run the dependency tree command: 'inspect dependencies for nix'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-wgrg-5h56-jg27",
  "modified" : "2022-06-17T00:13:59Z",
  "published" : "2022-06-17T00:13:59Z",
  "aliases" : [ ],
  "summary" : "Out-of-bounds write in nix::unistd::getgrouplist",
  "details" : "On certain platforms, if a user has more than 16 groups, the\n`nix::unistd::getgrouplist` function will call the libc `getgrouplist`\nfunction with a length parameter greater than the size of the buffer it\nprovides, resulting in an out-of-bounds write and memory corruption.\n\nThe libc `getgrouplist` function takes an in/out parameter `ngroups`\nspecifying the size of the group buffer. When the buffer is too small to\nhold all of the reqested user's group memberships, some libc\nimplementations, including glibc and Solaris libc, will modify `ngroups`\nto indicate the actual number of groups for the user, in addition to\nreturning an error. The version of `nix::unistd::getgrouplist` in nix\n0.16.0 and up will resize the buffer to twice its size, but will not\nread or modify the `ngroups` variable. Thus, if the user has more than\ntwice as many groups as the initial buffer size of 8, the next call to\n`getgrouplist` will then write past the end of the buffer.\n\nThe issue would require editing /etc/groups to exploit, which is usually\nonly editable by the root user.\n",
  "severity" : [ ],
  "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" : "WEB",
    "url" : "https://github.com/nix-rust/nix/issues/1541"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/nix-rust/nix"
  }, {
    "type" : "WEB",
    "url" : "https://rustsec.org/advisories/RUSTSEC-2021-0119.html"
  } ],
  "database_specific" : {
    "cwe_ids" : [ ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2022-06-17T00:13:59Z",
    "nvd_published_at" : null
  }
}