Skip to contentSkip to conversation

exiv2: patch CVE-2021-37615 and CVE-2021-37616

PATCH New Gyorgy Sarvari 1 participant 5 messages Feb 28

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 exiv2: patch CVE-2021-37615 and CVE-2021-37616

Details: https://nvd.nist.gov/vuln/detail/CVE-2021-37615
https://nvd.nist.gov/vuln/detail/CVE-2021-37616

Backport the patches from the PR that is referenced by the NVD advisory. Both CVEs are fixed by the same PR.

Note that the patch that added a regression test is not included. This is because it contains a binary patch, which seems to be impossible to apply with all patchtools during do_patch. Though it is not included in this patch, it was applied manually during prepration, and all ptests (including the new regression test) passed successfully.

---
 .../exiv2/exiv2/CVE-2021-37615-1.patch        |  80 ++++++++++
 .../exiv2/exiv2/CVE-2021-37615-2.patch        | 142 ++++++++++++++++++
 meta-oe/recipes-support/exiv2/exiv2_0.27.3.bb |   4 +
 3 files changed, 226 insertions(+)
 create mode 100644 meta-oe/recipes-support/exiv2/exiv2/CVE-2021-37615-1.patch
 create mode 100644 meta-oe/recipes-support/exiv2/exiv2/CVE-2021-37615-2.patch
meta-oe/recipes-support/exiv2/exiv2/CVE-2021-37615-1.patch new file +80 -0
new file mode 100644
index 0000000000..ce5b4543e1
@@ -0,0 +1,80 @@
+From 8e7363ed17e9c3377e7cec1b3d05841e339fc555 Mon Sep 17 00:00:00 2001
+From: Kevin Backhouse <[email protected]>
+Date: Fri, 2 Jul 2021 17:19:58 +0100
+Subject: [PATCH] Throw exception if lens info wasn't found.
+
+CVE: CVE-2021-37615 CVE-2021-37616
+Upstream-Status: Backport [https://github.com/Exiv2/exiv2/commit/98fb218475948cbaef9549f7de3e9bbe9cc80e16]
+Signed-off-by: Gyorgy Sarvari <[email protected]>
+---
+ src/pentaxmn_int.cpp | 36 ++++++++++++++++++++++--------------
+ 1 file changed, 22 insertions(+), 14 deletions(-)
+
+diff --git a/src/pentaxmn_int.cpp b/src/pentaxmn_int.cpp
+index de1ba75..3dac885 100644
+--- a/src/pentaxmn_int.cpp
++++ b/src/pentaxmn_int.cpp
+@@ -1216,6 +1216,25 @@ namespace Exiv2 {
+         return result;
+     }
+ 
++    // Exception thrown by findLensInfo when the lens info can't be found.
++    class LensInfoNotFound : public std::exception {
++    public:
++      LensInfoNotFound() {}
++    };
++
++    // Throws std::exception if the LensInfo can't be found.
++    static ExifData::const_iterator findLensInfo(const ExifData* metadata) {
++      const ExifData::const_iterator dngLensInfo = metadata->findKey(ExifKey("Exif.PentaxDng.LensInfo"));
++      if (dngLensInfo != metadata->end()) {
++        return dngLensInfo;
++      }
++      const ExifData::const_iterator lensInfo = metadata->findKey(ExifKey("Exif.Pentax.LensInfo"));
++      if (lensInfo != metadata->end()) {
++        return lensInfo;
++      }
++      throw LensInfoNotFound();
++    }
++
+     //! resolveLens0x32c print lens in human format
+     std::ostream& resolveLens0x32c(std::ostream& os, const Value& value,
+                                                  const ExifData* metadata)
+@@ -1251,12 +1270,7 @@ namespace Exiv2 {
+         try {
+             unsigned long index  = 0;
+ 
+-            // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Pentax.html#LensData
+-            const ExifData::const_iterator lensInfo = metadata->findKey(ExifKey("Exif.PentaxDng.LensInfo")) != metadata->end()
+-                                                    ? metadata->findKey(ExifKey("Exif.PentaxDng.LensInfo"))
+-                                                    : metadata->findKey(ExifKey("Exif.Pentax.LensInfo"))
+-                                                    ;
+-            if ( lensInfo == metadata->end() ) return EXV_PRINT_COMBITAG_MULTI(pentaxLensType, 2, 1, 2)(os, value, metadata);
++            const ExifData::const_iterator lensInfo = findLensInfo(metadata);
+             if ( lensInfo->count() < 5       ) return EXV_PRINT_COMBITAG_MULTI(pentaxLensType, 2, 1, 2)(os, value, metadata);
+ 
+             if ( value.count() == 2 ) {
+@@ -1310,10 +1324,7 @@ namespace Exiv2 {
+         try {
+             unsigned long index  = 0;
+ 
+-            const ExifData::const_iterator lensInfo = metadata->findKey(ExifKey("Exif.PentaxDng.LensInfo")) != metadata->end()
+-                                                    ? metadata->findKey(ExifKey("Exif.PentaxDng.LensInfo"))
+-                                                    : metadata->findKey(ExifKey("Exif.Pentax.LensInfo"))
+-                                                    ;
++            const ExifData::const_iterator lensInfo = findLensInfo(metadata);
+             if ( value.count() == 4 ) {
+                 std::string model       = getKeyString("Exif.Image.Model"      ,metadata);
+                 if ( model.find("PENTAX K-3")==0 && lensInfo->count() == 128 && lensInfo->toLong(1) == 168 && lensInfo->toLong(2) == 144 ) index = 7;
+@@ -1338,10 +1349,7 @@ namespace Exiv2 {
+         try {
+             unsigned long index  = 0;
+ 
+-            const ExifData::const_iterator lensInfo = metadata->findKey(ExifKey("Exif.PentaxDng.LensInfo")) != metadata->end()
+-                                                    ? metadata->findKey(ExifKey("Exif.PentaxDng.LensInfo"))
+-                                                    : metadata->findKey(ExifKey("Exif.Pentax.LensInfo"))
+-                                                    ;
++            const ExifData::const_iterator lensInfo = findLensInfo(metadata);
+             if ( value.count() == 4 ) {
+                 std::string model       = getKeyString("Exif.Image.Model"      ,metadata);
+                 if ( model.find("PENTAX K-3")==0 && lensInfo->count() == 128 && lensInfo->toLong(1) == 131 && lensInfo->toLong(2) == 128 )
meta-oe/recipes-support/exiv2/exiv2/CVE-2021-37615-2.patch new file +142 -0

142 lines not on this page · raw message

meta-oe/recipes-support/exiv2/exiv2_0.27.3.bb +2 -0
index 1c1c05dfaa..83110b1e0e 100644
@@ -22,6 +22,8 @@ SRC_URI = "https://github.com/Exiv2/${BPN}/releases/download/v${PV}/${BP}-Source
            file://CVE-2021-34334-4.patch \
            file://CVE-2021-34335-1.patch \
            file://CVE-2021-34335-2.patch \
+           file://CVE-2021-37615-1.patch \
+           file://CVE-2021-37615-2.patch \
            "
 SRC_URI[sha256sum] = "a79f5613812aa21755d578a297874fb59a85101e793edc64ec2c6bd994e3e778"
 
#1 lore raw

PATCH 2/5 exiv2: patch CVE-2021-37618

Details: https://nvd.nist.gov/vuln/detail/CVE-2021-37618

Pick the patch from the PR that is referenced by the NVD advisory.

Note that the regression test was not backported, because it contains a binary patch, that I couldn't apply with any of the patchtools in the do_patch step. Before submission however I have applied the patches, and ran all the tests successfully.

---
 .../exiv2/exiv2/CVE-2021-37618.patch          | 32 +++++++++++++++++++
 meta-oe/recipes-support/exiv2/exiv2_0.27.3.bb |  1 +
 2 files changed, 33 insertions(+)
 create mode 100644 meta-oe/recipes-support/exiv2/exiv2/CVE-2021-37618.patch
meta-oe/recipes-support/exiv2/exiv2/CVE-2021-37618.patch new file +32 -0
new file mode 100644
index 0000000000..8799876232
@@ -0,0 +1,32 @@
+From 37e0d4dac7c8b1a9e01448c359bf013ead53904a Mon Sep 17 00:00:00 2001
+From: Kevin Backhouse <[email protected]>
+Date: Mon, 5 Jul 2021 10:40:03 +0100
+Subject: [PATCH] Better bounds checking in Jp2Image::printStructure
+
+CVE: CVE-2021-37618
+Upstream-Status: Backport [https://github.com/Exiv2/exiv2/commit/0fcdde80997913dde284ea98f06f9305d06cb160]
+Signed-off-by: Gyorgy Sarvari <[email protected]>
+---
+ src/jp2image.cpp | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/src/jp2image.cpp b/src/jp2image.cpp
+index e14919c..2da69f1 100644
+--- a/src/jp2image.cpp
++++ b/src/jp2image.cpp
+@@ -538,6 +538,7 @@ static void boxes_check(size_t b,size_t m)
+ 
+                             if (subBox.type == kJp2BoxTypeColorHeader) {
+                                 long pad = 3;  // don't know why there are 3 padding bytes
++                                enforce(data.size_ >= pad, kerCorruptedMetadata);
+                                 if (bPrint) {
+                                     out << " | pad:";
+                                     for (int i = 0; i < 3; i++)
+@@ -547,6 +548,7 @@ static void boxes_check(size_t b,size_t m)
+                                 if (bPrint) {
+                                     out << " | iccLength:" << iccLength;
+                                 }
++                                enforce(iccLength <= data.size_ - pad, kerCorruptedMetadata);
+                                 if (bICC) {
+                                     out.write((const char*)data.pData_ + pad, iccLength);
+                                 }
meta-oe/recipes-support/exiv2/exiv2_0.27.3.bb +1 -0
index 83110b1e0e..3d41bc93b2 100644
@@ -24,6 +24,7 @@ SRC_URI = "https://github.com/Exiv2/${BPN}/releases/download/v${PV}/${BP}-Source
            file://CVE-2021-34335-2.patch \
            file://CVE-2021-37615-1.patch \
            file://CVE-2021-37615-2.patch \
+           file://CVE-2021-37618.patch \
            "
 SRC_URI[sha256sum] = "a79f5613812aa21755d578a297874fb59a85101e793edc64ec2c6bd994e3e778"
 
#2 lore raw

PATCH 3/5 exiv2: patch CVE-2021-37619

In reply to Gyorgy Sarvari

Details: https://nvd.nist.gov/vuln/detail/CVE-2021-37619

Pick the patch from the PR referenced by the NVD advisory.

Note that the regression test is not part of this patch, as no patchtool could apply it in do_patch task.

The test patch was however manually applied during preparing this patch, and all tests were executed successfully.

---
 .../exiv2/exiv2/CVE-2021-37619.patch          | 37 +++++++++++++++++++
 meta-oe/recipes-support/exiv2/exiv2_0.27.3.bb |  1 +
 2 files changed, 38 insertions(+)
 create mode 100644 meta-oe/recipes-support/exiv2/exiv2/CVE-2021-37619.patch
meta-oe/recipes-support/exiv2/exiv2/CVE-2021-37619.patch new file +37 -0
new file mode 100644
index 0000000000..9faf778743
@@ -0,0 +1,37 @@
+From 0b74e631713d328a5f2bd1d9d26baf2e12b9da56 Mon Sep 17 00:00:00 2001
+From: Kevin Backhouse <[email protected]>
+Date: Wed, 30 Jun 2021 18:02:43 +0100
+Subject: [PATCH] fix: fix incorrect loop condition (#1752)
+
+* Regression test for https://github.com/Exiv2/exiv2/security/advisories/GHSA-mxw9-qx4c-6m8v
+
+* Fix incorrect loop condition.
+
+CVE: CVE-2021-37619
+Upstream-Status: Backport [https://github.com/Exiv2/exiv2/commit/86d0a1d5d9f6dc41013a6690408add974e59167c]
+Signed-off-by: Gyorgy Sarvari <[email protected]>
+---
+ src/jp2image.cpp | 6 ++++--
+ 1 file changed, 4 insertions(+), 2 deletions(-)
+
+diff --git a/src/jp2image.cpp b/src/jp2image.cpp
+index 2da69f1..482ef63 100644
+--- a/src/jp2image.cpp
++++ b/src/jp2image.cpp
+@@ -658,12 +658,14 @@ static void boxes_check(size_t b,size_t m)
+         char*         p      = (char*) boxBuf.pData_;
+         bool          bWroteColor = false ;
+ 
+-        while ( count < length || !bWroteColor ) {
++        while ( count < length && !bWroteColor ) {
+             enforce(sizeof(Jp2BoxHeader) <= length - count, Exiv2::kerCorruptedMetadata);
+             Jp2BoxHeader* pSubBox = (Jp2BoxHeader*) (p+count) ;
+ 
+             // copy data.  pointer could be into a memory mapped file which we will decode!
+-            Jp2BoxHeader   subBox = *pSubBox ;
++            // pSubBox isn't always an aligned pointer, so use memcpy to do the copy.
++            Jp2BoxHeader   subBox;
++            memcpy(&subBox, pSubBox, sizeof(Jp2BoxHeader));
+             Jp2BoxHeader   newBox =  subBox;
+ 
+             if ( count < length ) {
meta-oe/recipes-support/exiv2/exiv2_0.27.3.bb +1 -0
index 3d41bc93b2..e7eac337dc 100644
@@ -25,6 +25,7 @@ SRC_URI = "https://github.com/Exiv2/${BPN}/releases/download/v${PV}/${BP}-Source
            file://CVE-2021-37615-1.patch \
            file://CVE-2021-37615-2.patch \
            file://CVE-2021-37618.patch \
+           file://CVE-2021-37619.patch \
            "
 SRC_URI[sha256sum] = "a79f5613812aa21755d578a297874fb59a85101e793edc64ec2c6bd994e3e778"
 
#3 lore raw

PATCH 4/5 exiv2: patch CVE-2021-37620

In reply to Gyorgy Sarvari

Details: https://nvd.nist.gov/vuln/detail/CVE-2021-37620

Pick the patches from the PR that is referenced by the NVD advisory.

Two notes:
1. The regression test contains a binary patch, that couldn't be applied in the do_patch task. Due to this the test was not backported. It was however applied manually and executed successfully during the preparation of this patch.
2. The commit changes some "unsigned" types to "size_t", which is not included in this backport. They were already done by another patch (the one for CVE-2021-34334).

---
 .../exiv2/exiv2/CVE-2021-37620-1.patch        |  26 ++
 .../exiv2/exiv2/CVE-2021-37620-2.patch        | 305 ++++++++++++++++++
 meta-oe/recipes-support/exiv2/exiv2_0.27.3.bb |   2 +
 3 files changed, 333 insertions(+)
 create mode 100644 meta-oe/recipes-support/exiv2/exiv2/CVE-2021-37620-1.patch
 create mode 100644 meta-oe/recipes-support/exiv2/exiv2/CVE-2021-37620-2.patch
meta-oe/recipes-support/exiv2/exiv2/CVE-2021-37620-1.patch new file +26 -0
new file mode 100644
index 0000000000..f072ea6ab0
@@ -0,0 +1,26 @@
+From 672bb4c98a98911f91834617e8a7374acb903206 Mon Sep 17 00:00:00 2001
+From: Kevin Backhouse <[email protected]>
+Date: Sat, 10 Jul 2021 10:42:24 +0100
+Subject: [PATCH] Check that `type` isn't an empty string.
+
+CVE: CVE-2021-37620
+Upstream-Status: Backport [https://github.com/Exiv2/exiv2/commit/2e7bb581a234bfb0d0c9e16a1dbf037a8c30681e]
+Signed-off-by: Gyorgy Sarvari <[email protected]>
+---
+ src/value.cpp | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/src/value.cpp b/src/value.cpp
+index 95eb05a..2536b84 100644
+--- a/src/value.cpp
++++ b/src/value.cpp
+@@ -714,6 +714,9 @@ namespace Exiv2 {
+         if (buf.length() > 5 && buf.substr(0, 5) == "type=") {
+             std::string::size_type pos = buf.find_first_of(' ');
+             type = buf.substr(5, pos-5);
++            if (type.empty()) {
++                throw Error(kerInvalidXmpText, type);
++            }
+             // Strip quotes (so you can also specify the type without quotes)
+             if (type[0] == '"') type = type.substr(1);
+             if (type[type.length()-1] == '"') type = type.substr(0, type.length()-1);
meta-oe/recipes-support/exiv2/exiv2/CVE-2021-37620-2.patch new file +305 -0

305 lines not on this page · raw message

meta-oe/recipes-support/exiv2/exiv2_0.27.3.bb +2 -0
index e7eac337dc..4001f1b639 100644
@@ -26,6 +26,8 @@ SRC_URI = "https://github.com/Exiv2/${BPN}/releases/download/v${PV}/${BP}-Source
            file://CVE-2021-37615-2.patch \
            file://CVE-2021-37618.patch \
            file://CVE-2021-37619.patch \
+           file://CVE-2021-37620-1.patch \
+           file://CVE-2021-37620-2.patch \
            "
 SRC_URI[sha256sum] = "a79f5613812aa21755d578a297874fb59a85101e793edc64ec2c6bd994e3e778"
 
#4 lore raw

PATCH 5/5 exiv2: patch CVE-2021-37621

In reply to Gyorgy Sarvari

Details: https://nvd.nist.gov/vuln/detail/CVE-2021-37621

Backport the patch that is referenced by the NVD advisory.

The regression test contains a binary patch, that couldn't be applied in the do_patch task. Due to this the test was not backported. It was however applied manually and executed successfully during the preparation of this patch.

---
 .../exiv2/exiv2/CVE-2021-37621-1.patch        |  25 +++
 .../exiv2/exiv2/CVE-2021-37621-2.patch        | 187 ++++++++++++++++++
 meta-oe/recipes-support/exiv2/exiv2_0.27.3.bb |   2 +
 3 files changed, 214 insertions(+)
 create mode 100644 meta-oe/recipes-support/exiv2/exiv2/CVE-2021-37621-1.patch
 create mode 100644 meta-oe/recipes-support/exiv2/exiv2/CVE-2021-37621-2.patch
meta-oe/recipes-support/exiv2/exiv2/CVE-2021-37621-1.patch new file +25 -0
new file mode 100644
index 0000000000..1ca9fd2b0d
@@ -0,0 +1,25 @@
+From 4fbd3390829f8418e1ec95252c2fd6b851850508 Mon Sep 17 00:00:00 2001
+From: Kevin Backhouse <[email protected]>
+Date: Tue, 13 Jul 2021 22:50:16 +0100
+Subject: [PATCH] dirLength == 0 can cause an infinite loop.
+
+CVE: CVE-2021-37621
+Upstream-Status: Backport [https://github.com/Exiv2/exiv2/commit/191cd2690608f19335d82ed2be36c7ce8bdc60b9]
+Signed-off-by: Gyorgy Sarvari <[email protected]>
+---
+ src/image.cpp | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/src/image.cpp b/src/image.cpp
+index 2fa41e5..7c2eaa9 100644
+--- a/src/image.cpp
++++ b/src/image.cpp
+@@ -353,6 +353,8 @@ namespace Exiv2 {
+                 throw Error(kerCorruptedMetadata);
+             }
+             uint16_t   dirLength = byteSwap2(dir,0,bSwap);
++            // Prevent infinite loops. (GHSA-m479-7frc-gqqg)
++            enforce(dirLength > 0, kerCorruptedMetadata);
+ 
+             bool tooBig = dirLength > 500;
+             if ( tooBig ) throw Error(kerTiffDirectoryTooLarge);
meta-oe/recipes-support/exiv2/exiv2/CVE-2021-37621-2.patch new file +187 -0

187 lines not on this page · raw message

meta-oe/recipes-support/exiv2/exiv2_0.27.3.bb +2 -0
index 4001f1b639..eecd02d78a 100644
@@ -28,6 +28,8 @@ SRC_URI = "https://github.com/Exiv2/${BPN}/releases/download/v${PV}/${BP}-Source
            file://CVE-2021-37619.patch \
            file://CVE-2021-37620-1.patch \
            file://CVE-2021-37620-2.patch \
+           file://CVE-2021-37621-1.patch \
+           file://CVE-2021-37621-2.patch \
            "
 SRC_URI[sha256sum] = "a79f5613812aa21755d578a297874fb59a85101e793edc64ec2c6bd994e3e778"