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

Backport security fixes from 0.26 #123

Merged
merged 17 commits into from
Jan 7, 2018
Merged

Backport security fixes from 0.26 #123

merged 17 commits into from
Jan 7, 2018

Conversation

dirkmueller
Copy link

No description provided.

D4N and others added 9 commits October 17, 2017 13:52
(cherry picked from commit 6e3855a)
Source:
Exiv2#57 (comment)

tc can be a null pointer when the TIFF tag is unknown (the factory
then returns an auto_ptr(0)) => as this can happen for corrupted
files, an explicit check should be used because an assertion can be
turned of in release mode (with NDEBUG defined)

This also fixes Exiv2#57

(cherry picked from commit 1f1715c)
The invalid memory dereference in
Exiv2::getULong()/Exiv2::StringValueBase::read()/Exiv2::DataValue::read()
is caused further up the call-stack, by
v->read(pData, size, byteOrder) in TiffReader::readTiffEntry()
passing an invalid pData pointer (pData points outside of the Tiff
file). pData can be set out of bounds in the (size > 4) branch where
baseOffset() and offset are added to pData_ without checking whether
the result is still in the file. As offset comes from an untrusted
source, an attacker can craft an arbitrarily large offset into the
file.

This commit adds a check into the problematic branch, whether the
result of the addition would be out of bounds of the Tiff
file. Furthermore the whole operation is checked for possible
overflows.

(cherry picked from commit d4e4288)
v can be null if the typeId is invalid => throw an exception notifying
the user that his file is corrupted instead of the assertion

(cherry picked from commit 1841c2a)
@D4N
Copy link
Member

D4N commented Oct 17, 2017

Hi, thanks for cherry-picking the commits! I'll take a look at it later today or tomorrow.

Have you tried building exiv2 and the reproducers for the vulnerabilities?

@dirkmueller
Copy link
Author

I did try building, but I haven't tried the reproducers (it wasn't entirely obvious to me which reproducers apply where). I'll give this some further try later.

@D4N
Copy link
Member

D4N commented Oct 17, 2017

The reproducers are in located in test/data/ and should have been added by #120 to the 0.26 branch. They are called 00* and POC*.

Ideally the testsuite (run it via make test in the test directory) should be clean, but that involves updating a huge binary file which I have failed to yet. However, if exiv2 does not crash with ASAN enabled, it should be fine.

@dirkmueller
Copy link
Author

here's what I did:

cmake .. -DCMAKE_CXX_FLAGS="-O2 -fsanitize=address"
for i in /tmp/data/*; do bin/exiv2 $i 2>&1 | grep -a -i asan && echo $i; done
/tmp/data/exiv2-bug1080.jpg

none of the data/00* or data/POC* files trigger. there seems to be a missing fix for bug1080.

(cherry picked from commit 54ac67d)
@dirkmueller
Copy link
Author

so I added the fix for that one as well, now the above loop for a copy of the data dir from master is clean.

@D4N
Copy link
Member

D4N commented Oct 17, 2017 via email

@D4N
Copy link
Member

D4N commented Oct 18, 2017

Please also cherry pick the following commits: 73a4cdb, 0f3e646, c90991c, 751312f, fd3711f and 1b01704

You'll get an error on every single one of these for the file test/data/bugfixes-test.out. Don't bother with merging it, just take the version from 0.25 (and not from the commits you cherry pick). I'll then send you an updated version, so that the testsuite runs without issues.

@dirkmueller
Copy link
Author

I'll get to this in the week after next week.

@D4N D4N merged commit caff2c8 into Exiv2:0.25 Jan 7, 2018
@D4N
Copy link
Member

D4N commented Jan 7, 2018

Thanks for your work!

@clanmills
Copy link
Collaborator

Thank you for doing this work. Lots of great team work here. Thank You all very much.

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

Successfully merging this pull request may close these issues.

3 participants