Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tar-split does not read block by block nor validate tar headers #35075

Closed
n4ss opened this issue Oct 3, 2017 · 13 comments · Fixed by #35424
Closed

tar-split does not read block by block nor validate tar headers #35075

n4ss opened this issue Oct 3, 2017 · 13 comments · Fixed by #35424

Comments

@n4ss
Copy link

n4ss commented Oct 3, 2017

Problem

https://github.com/moby/moby/blob/master/vendor/github.com/vbatts/tar-split/tar/asm/disassemble.go#L124

This line can read any number of \0s at the end of an archive, potentially taking up all the space in RAM.

We actually read in memory the complete padding sequence.

Reproductible

To reproduce, compress a high amount of 0s and push&pull as an image.

Solution

We should:

  • validate the integrity of tar headers
  • either refuse large padding sequences or read block by block and write on disk above a certain limit.

/cc @thaJeztah @vdemeester @stevvooe

@n4ss n4ss changed the title tar-split does not read block by block nor validate tar format tar-split does not read block by block nor validate tar headers Oct 3, 2017
@fntlnz
Copy link
Member

fntlnz commented Oct 4, 2017

Reproducible with

fallocate -l 2G test.tar
docker import test.tar

In my case the import command completely freezed the host and had to restart

@stevvooe
Copy link
Contributor

stevvooe commented Oct 4, 2017

@fntlnz That is actually a completely different case than was considered here. I suspect that might be a different path; same result. :(

Looks like this is hitting the same path. Oops.

Thanks for the great report!

@fntlnz
Copy link
Member

fntlnz commented Oct 4, 2017

@steevvoe if we fix the tar thing in this case also all the others should benefit right? IDK if I’m missing something but the point seems to be: “we have to avoid the speculations on malicious images crafted to disturb the docker daemon”

@stevvooe
Copy link
Contributor

stevvooe commented Oct 4, 2017

@fntlnz Looking back your case, this is actually the same code path. I confused "import" with "load", which properly errors out (we checked!).

@fntlnz
Copy link
Member

fntlnz commented Oct 4, 2017

@stevvooe I was a bit confused 🌈

@runcom
Copy link
Member

runcom commented Nov 7, 2017

/cc @vbatts

@cyphar
Copy link
Contributor

cyphar commented Nov 7, 2017

@vbatts I was looking at this code, and it's not clear to me whether there's a trivial way of solving it. The core problem is that the encoding for the tar-split.json packer requires having the slice in memory -- which obviously doesn't work if it's 20GB. One solution would be to do it in chunks, but the current Packer API doesn't support that. We could break the previous tar-split code to make it always chunk -- but I'd want to know what @vbatts has to say about that and whether it will break anything.

I'm going to open a bug against tar-split.

@vbatts
Copy link
Contributor

vbatts commented Nov 7, 2017

interesting way to OOM. This pad should only ever be 1024, but spec requires reading to the end.
I reckon we could read that remainder to a tempfile, but that seems unfortunate to do for every disassemble.

@vbatts
Copy link
Contributor

vbatts commented Nov 7, 2017

oh right. @cyphar is right about the slice. That would be marshaled in memory. Let's see...

@cyphar
Copy link
Contributor

cyphar commented Nov 7, 2017

I have proposed a patch for tar-split in vbatts/tar-split#42, and a tracking issue for this bug in vbatts/tar-split#41.

@vbatts
Copy link
Contributor

vbatts commented Nov 7, 2017

fixed released in https://github.com/vbatts/tar-split/releases/tag/v0.10.2
@cyphar is working up a PR for moby now.
Thanks for the report!

@thaJeztah
Copy link
Member

Thanks both!

@cyphar
Copy link
Contributor

cyphar commented Nov 7, 2017

For reference, CVE-2017-14992 was assigned for this bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants