Project: exiv2 (exiv2/exiv2), language: c++
Vulnerability instance: exiv2.cve-2017-11337
Sanitizer: address

================= Bug Report (1/1) ==================
## Source: Red Hat Bugzilla
## URL: https://bugzilla.redhat.com/show_bug.cgi?id=1470737
## Description:
Bugzilla ID: 1470737
Title: There is an invalid free in Action::TaskFactory::cleanup funtion of actions.cpp in exiv2. A crafted input will lead to remote denial of service attack.

Description
owl337 2017-07-13 14:30:26 UTC
Created attachment 1297689 [details]
Triggered by  "./exiv2 $POC"

Description of problem:

There is an invalid free in  Action::TaskFactory::cleanup  funtion of actions.cpp in  exiv2. A crafted input will lead to remote denial of service attack.

Version-Release number of selected component (if applicable):

<=latest version

How reproducible:

./exiv2 POC3

Steps to Reproduce:

The output information is as follows:

$./exiv2 POC3

*** Error in `/real/exiv2/bin/.libs/lt-exiv2': malloc(): memory corruption: 0x0000000000bac250 ***
Aborted

ASAN output information:

$./exiv2 POC3

Error: Directory Image, entry 0x0144 has invalid size 4294967295*8; skipping entry.
File name       : POC3
File size       : 28 Bytes
MIME type       : image/tiff
Image size      : 0 x 0
POC3 No Exif data found in the file
=================================================================
==92908==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x60200000ed90 in thread T0
    #0 0x4e1c92  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x4e1c92)
    #1 0x51515c  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x51515c)
    #2 0x4e2fe6  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x4e2fe6)
    #3 0x7fbeb19e9abf  (/lib/x86_64-linux-gnu/libc.so.6+0x20abf)
    #4 0x43b288  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x43b288)

0x60200000ed90 is located 0 bytes inside of 1229389824-byte region [0x60200000ed90,0x60204947ed90)
freed by thread T0 here:
==92908==AddressSanitizer CHECK failed: /build/llvm-toolchain-3.6-18MJNr/llvm-toolchain-3.6-3.6.2/projects/compiler-rt/lib/asan/asan_allocator.cc:668 "((res.trace)) != (0)" (0x0, 0x0)
    #0 0x4c9dd4  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x4c9dd4)
    #1 0x4d0751  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x4d0751)
    #2 0x43b8c8  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x43b8c8)
    #3 0x4c5d70  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x4c5d70)
    #4 0x4c6b9f  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x4c6b9f)
    #5 0x43f5d5  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x43f5d5)
    #6 0x43bc87  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x43bc87)
    #7 0x4e1d51  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x4e1d51)
    #8 0x51515c  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x51515c)
    #9 0x4e2fe6  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x4e2fe6)
    #10 0x7fbeb19e9abf  (/lib/x86_64-linux-gnu/libc.so.6+0x20abf)
    #11 0x43b288  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x43b288)

The GDB debugging information is as follows:

(gdb) set args POC3
(gdb) r
...
(gdb) 
Continuing.

Breakpoint 2, Action::TaskFactory::cleanup (this=<optimized out>) at actions.cpp:194
194                 delete i->second;

(gdb) bt
#0  Action::TaskFactory::cleanup (this=<optimized out>) at actions.cpp:194
#1  0x00000000004e2fe7 in main (argc=<optimized out>, argv=<optimized out>) at exiv2.cpp:174
(gdb) s
=================================================================
==114915==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x60200000edb0 in thread T0
    #0 0x4e1c92  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x4e1c92)
    #1 0x51515c  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x51515c)
    #2 0x4e2fe6  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x4e2fe6)
    #3 0x7ffff5e29abf  (/lib/x86_64-linux-gnu/libc.so.6+0x20abf)
    #4 0x43b288  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x43b288)

0x60200000edb0 is located 0 bytes inside of 1229389824-byte region [0x60200000edb0,0x60204947edb0)
freed by thread T0 here:
==114915==AddressSanitizer CHECK failed: /build/llvm-toolchain-3.6-18MJNr/llvm-toolchain-3.6-3.6.2/projects/compiler-rt/lib/asan/asan_allocator.cc:668 "((res.trace)) != (0)" (0x0, 0x0)
    #0 0x4c9dd4  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x4c9dd4)
    #1 0x4d0751  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x4d0751)
    #2 0x43b8c8  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x43b8c8)
    #3 0x4c5d70  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x4c5d70)
    #4 0x4c6b9f  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x4c6b9f)
    #5 0x43f5d5  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x43f5d5)
    #6 0x43bc87  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x43bc87)
    #7 0x4e1d51  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x4e1d51)
    #8 0x51515c  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x51515c)
    #9 0x4e2fe6  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x4e2fe6)
    #10 0x7ffff5e29abf  (/lib/x86_64-linux-gnu/libc.so.6+0x20abf)
    #11 0x43b288  (/home/icy/real/exiv2-asan/install/bin/exiv2+0x43b288)

[Inferior 1 (process 114915) exited with code 01]

This vulnerability was triggered in Action::TaskFactory::cleanup() at actions.cpp:194. Line 194 attempting free on address which was not malloc()-ed: 0x60200000edb0

 189     void TaskFactory::cleanup()
 190     {
 191         if (instance_ != 0) {
 192             Registry::iterator e = registry_.end();
 193             for (Registry::iterator i = registry_.begin(); i != e; ++i) {
 194                 delete i->second;
 195             }
 196             delete instance_;
 197             instance_ = 0;
 198         }
 199     } //TaskFactory::cleanup



Actual results:

crash

Expected results:

crash


Additional info:

This vulnerability is detected by team OWL337, with our custom fuzzer collAFL. Please contact ganshuitao   and chaoz.cn if you need more info about the team, the tool or the vulnerability.


Comments:
Comment 2
Adam Mariš 2017-07-24 12:41:53 UTC
Please, report this issue to upstream. Thanks!

---

Comment 3
Raphaël Hertzog 2017-08-31 14:13:59 UTC
I forwarded this report upstream: https://github.com/Exiv2/exiv2/issues/50

---

Comment 4
Dan Čermák 2017-10-19 21:00:17 UTC
This has been fixed upstream and backported to the 0.26 branch.

---

Comment 6
Jan Grulich 2019-01-28 16:08:29 UTC
Fixed with exiv2-0.27.0-1.el7_6.

---

Comment 10
errata-xmlrpc 2019-08-06 12:46:47 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2019:2101

Attachments:
Attachment 1297689: Triggered by "./exiv2 $POC" [Link: https://bugzilla.redhat.com/attachment.cgi?id=1297689]

Build script:
#!/bin/bash -eu
# Minimized build script with only core build commands
set -eu
mkdir -p build
cd build
cmake -DEXIV2_ENABLE_PNG=ON -DEXIV2_ENABLE_WEBREADY=ON -DEXIV2_ENABLE_CURL=OFF -DEXIV2_ENABLE_BMFF=ON -DEXIV2_TEAM_WARNINGS_AS_ERRORS=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_CXX_COMPILER="${CXX}" -DCMAKE_CXX_FLAGS="${CXXFLAGS}" -DEXIV2_BUILD_FUZZ_TESTS=ON -DEXIV2_TEAM_OSS_FUZZ=ON -DLIB_FUZZING_ENGINE="${LIB_FUZZING_ENGINE}" ..
make -j $(nproc)

Dockerfile:
FROM hwiwonlee/secb.base:latest
RUN apt-get update && apt-get install -y cmake make ccache python3 libexpat1-dev zlib1g-dev libssh-dev libcurl4-openssl-dev libxml2-utils
RUN git clone https://github.com/exiv2/exiv2 exiv2
RUN git -C exiv2 checkout fa449a4d2c58d63f0d75ff259f25683a98a44630
WORKDIR $SRC/exiv2
COPY build.sh $SRC/

Additional files: