summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnuj Mittal <anuj.mittal@intel.com>2019-07-29 07:20:57 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-07-29 23:50:43 +0100
commit885459d264e8fa1472142ff0ce02cbce91e630a0 (patch)
tree1c0716b8ed02b7dc4aa740ee8c9808bdbcfa01f9
parentd0e65410f4f0d394614f338899ca19096afbd85a (diff)
downloadpoky-885459d264e8fa1472142ff0ce02cbce91e630a0.tar.gz
bzip2: fix CVE-2019-12900
Also include a patch to fix regression caused by it. See: https://gitlab.com/federicomenaquintero/bzip2/issues/24 (From OE-Core rev: 7c0b2d228f51aebb4415e63a07bdd645e85b09d8) Signed-off-by: Anuj Mittal <anuj.mittal@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-extended/bzip2/bzip2-1.0.6/CVE-2019-12900.patch33
-rw-r--r--meta/recipes-extended/bzip2/bzip2-1.0.6/fix-regression-CVE-2019-12900.patch82
-rw-r--r--meta/recipes-extended/bzip2/bzip2_1.0.6.bb2
3 files changed, 117 insertions, 0 deletions
diff --git a/meta/recipes-extended/bzip2/bzip2-1.0.6/CVE-2019-12900.patch b/meta/recipes-extended/bzip2/bzip2-1.0.6/CVE-2019-12900.patch
new file mode 100644
index 0000000000..9841644881
--- /dev/null
+++ b/meta/recipes-extended/bzip2/bzip2-1.0.6/CVE-2019-12900.patch
@@ -0,0 +1,33 @@
1From 11e1fac27eb8a3076382200736874c78e09b75d6 Mon Sep 17 00:00:00 2001
2From: Albert Astals Cid <aacid@kde.org>
3Date: Tue, 28 May 2019 19:35:18 +0200
4Subject: [PATCH] Make sure nSelectors is not out of range
5
6nSelectors is used in a loop from 0 to nSelectors to access selectorMtf
7which is
8 UChar selectorMtf[BZ_MAX_SELECTORS];
9so if nSelectors is bigger than BZ_MAX_SELECTORS it'll do an invalid memory
10access
11
12Fixes out of bounds access discovered while fuzzying karchive
13CVE: CVE-2019-12900
14Upstream-Status: Backport
15Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
16
17---
18 decompress.c | 2 +-
19 1 file changed, 1 insertion(+), 1 deletion(-)
20
21diff --git a/decompress.c b/decompress.c
22index 311f566..b6e0a29 100644
23--- a/decompress.c
24+++ b/decompress.c
25@@ -287,7 +287,7 @@ Int32 BZ2_decompress ( DState* s )
26 GET_BITS(BZ_X_SELECTOR_1, nGroups, 3);
27 if (nGroups < 2 || nGroups > 6) RETURN(BZ_DATA_ERROR);
28 GET_BITS(BZ_X_SELECTOR_2, nSelectors, 15);
29- if (nSelectors < 1) RETURN(BZ_DATA_ERROR);
30+ if (nSelectors < 1 || nSelectors > BZ_MAX_SELECTORS) RETURN(BZ_DATA_ERROR);
31 for (i = 0; i < nSelectors; i++) {
32 j = 0;
33 while (True) {
diff --git a/meta/recipes-extended/bzip2/bzip2-1.0.6/fix-regression-CVE-2019-12900.patch b/meta/recipes-extended/bzip2/bzip2-1.0.6/fix-regression-CVE-2019-12900.patch
new file mode 100644
index 0000000000..362e6cf319
--- /dev/null
+++ b/meta/recipes-extended/bzip2/bzip2-1.0.6/fix-regression-CVE-2019-12900.patch
@@ -0,0 +1,82 @@
1From 212f3ed7ac3931c9e0e9167a0bdc16eeb3c76af4 Mon Sep 17 00:00:00 2001
2From: Mark Wielaard <mark@klomp.org>
3Date: Wed, 3 Jul 2019 01:28:11 +0200
4Subject: [PATCH] Accept as many selectors as the file format allows.
5
6But ignore any larger than the theoretical maximum, BZ_MAX_SELECTORS.
7
8The theoretical maximum number of selectors depends on the maximum
9blocksize (900000 bytes) and the number of symbols (50) that can be
10encoded with a different Huffman tree. BZ_MAX_SELECTORS is 18002.
11
12But the bzip2 file format allows the number of selectors to be encoded
13with 15 bits (because 18002 isn't a factor of 2 and doesn't fit in
1414 bits). So the file format maximum is 32767 selectors.
15
16Some bzip2 encoders might actually have written out more selectors
17than the theoretical maximum because they rounded up the number of
18selectors to some convenient factor of 8.
19
20The extra 14766 selectors can never be validly used by the decompression
21algorithm. So we can read them, but then discard them.
22
23This is effectively what was done (by accident) before we added a
24check for nSelectors to be at most BZ_MAX_SELECTORS to mitigate
25CVE-2019-12900.
26
27The extra selectors were written out after the array inside the
28EState struct. But the struct has extra space allocated after the
29selector arrays of 18060 bytes (which is larger than 14766).
30All of which will be initialized later (so the overwrite of that
31space with extra selector values would have been harmless).
32
33Upstream-Status: Backport
34Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
35
36---
37 compress.c | 2 +-
38 decompress.c | 10 ++++++++--
39 2 files changed, 9 insertions(+), 3 deletions(-)
40
41diff --git a/compress.c b/compress.c
42index caf7696..19b662b 100644
43--- a/compress.c
44+++ b/compress.c
45@@ -454,7 +454,7 @@ void sendMTFValues ( EState* s )
46
47 AssertH( nGroups < 8, 3002 );
48 AssertH( nSelectors < 32768 &&
49- nSelectors <= (2 + (900000 / BZ_G_SIZE)),
50+ nSelectors <= BZ_MAX_SELECTORS,
51 3003 );
52
53
54diff --git a/decompress.c b/decompress.c
55index b6e0a29..78060c9 100644
56--- a/decompress.c
57+++ b/decompress.c
58@@ -287,7 +287,7 @@ Int32 BZ2_decompress ( DState* s )
59 GET_BITS(BZ_X_SELECTOR_1, nGroups, 3);
60 if (nGroups < 2 || nGroups > 6) RETURN(BZ_DATA_ERROR);
61 GET_BITS(BZ_X_SELECTOR_2, nSelectors, 15);
62- if (nSelectors < 1 || nSelectors > BZ_MAX_SELECTORS) RETURN(BZ_DATA_ERROR);
63+ if (nSelectors < 1) RETURN(BZ_DATA_ERROR);
64 for (i = 0; i < nSelectors; i++) {
65 j = 0;
66 while (True) {
67@@ -296,8 +296,14 @@ Int32 BZ2_decompress ( DState* s )
68 j++;
69 if (j >= nGroups) RETURN(BZ_DATA_ERROR);
70 }
71- s->selectorMtf[i] = j;
72+ /* Having more than BZ_MAX_SELECTORS doesn't make much sense
73+ since they will never be used, but some implementations might
74+ "round up" the number of selectors, so just ignore those. */
75+ if (i < BZ_MAX_SELECTORS)
76+ s->selectorMtf[i] = j;
77 }
78+ if (nSelectors > BZ_MAX_SELECTORS)
79+ nSelectors = BZ_MAX_SELECTORS;
80
81 /*--- Undo the MTF values for the selectors. ---*/
82 {
diff --git a/meta/recipes-extended/bzip2/bzip2_1.0.6.bb b/meta/recipes-extended/bzip2/bzip2_1.0.6.bb
index 025f45c472..33cb8dda97 100644
--- a/meta/recipes-extended/bzip2/bzip2_1.0.6.bb
+++ b/meta/recipes-extended/bzip2/bzip2_1.0.6.bb
@@ -14,6 +14,8 @@ SRC_URI = "http://downloads.yoctoproject.org/mirror/sources/${BP}.tar.gz \
14 file://Makefile.am;subdir=${BP} \ 14 file://Makefile.am;subdir=${BP} \
15 file://run-ptest \ 15 file://run-ptest \
16 file://CVE-2016-3189.patch \ 16 file://CVE-2016-3189.patch \
17 file://CVE-2019-12900.patch \
18 file://fix-regression-CVE-2019-12900.patch \
17 " 19 "
18 20
19SRC_URI[md5sum] = "00b516f4704d4a7cb50a1d97e6e8e15b" 21SRC_URI[md5sum] = "00b516f4704d4a7cb50a1d97e6e8e15b"