diff options
author | Anuj Mittal <anuj.mittal@intel.com> | 2019-07-29 07:20:57 +0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-07-29 23:50:43 +0100 |
commit | 885459d264e8fa1472142ff0ce02cbce91e630a0 (patch) | |
tree | 1c0716b8ed02b7dc4aa740ee8c9808bdbcfa01f9 | |
parent | d0e65410f4f0d394614f338899ca19096afbd85a (diff) | |
download | poky-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>
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 @@ | |||
1 | From 11e1fac27eb8a3076382200736874c78e09b75d6 Mon Sep 17 00:00:00 2001 | ||
2 | From: Albert Astals Cid <aacid@kde.org> | ||
3 | Date: Tue, 28 May 2019 19:35:18 +0200 | ||
4 | Subject: [PATCH] Make sure nSelectors is not out of range | ||
5 | |||
6 | nSelectors is used in a loop from 0 to nSelectors to access selectorMtf | ||
7 | which is | ||
8 | UChar selectorMtf[BZ_MAX_SELECTORS]; | ||
9 | so if nSelectors is bigger than BZ_MAX_SELECTORS it'll do an invalid memory | ||
10 | access | ||
11 | |||
12 | Fixes out of bounds access discovered while fuzzying karchive | ||
13 | CVE: CVE-2019-12900 | ||
14 | Upstream-Status: Backport | ||
15 | Signed-off-by: Anuj Mittal <anuj.mittal@intel.com> | ||
16 | |||
17 | --- | ||
18 | decompress.c | 2 +- | ||
19 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
20 | |||
21 | diff --git a/decompress.c b/decompress.c | ||
22 | index 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 @@ | |||
1 | From 212f3ed7ac3931c9e0e9167a0bdc16eeb3c76af4 Mon Sep 17 00:00:00 2001 | ||
2 | From: Mark Wielaard <mark@klomp.org> | ||
3 | Date: Wed, 3 Jul 2019 01:28:11 +0200 | ||
4 | Subject: [PATCH] Accept as many selectors as the file format allows. | ||
5 | |||
6 | But ignore any larger than the theoretical maximum, BZ_MAX_SELECTORS. | ||
7 | |||
8 | The theoretical maximum number of selectors depends on the maximum | ||
9 | blocksize (900000 bytes) and the number of symbols (50) that can be | ||
10 | encoded with a different Huffman tree. BZ_MAX_SELECTORS is 18002. | ||
11 | |||
12 | But the bzip2 file format allows the number of selectors to be encoded | ||
13 | with 15 bits (because 18002 isn't a factor of 2 and doesn't fit in | ||
14 | 14 bits). So the file format maximum is 32767 selectors. | ||
15 | |||
16 | Some bzip2 encoders might actually have written out more selectors | ||
17 | than the theoretical maximum because they rounded up the number of | ||
18 | selectors to some convenient factor of 8. | ||
19 | |||
20 | The extra 14766 selectors can never be validly used by the decompression | ||
21 | algorithm. So we can read them, but then discard them. | ||
22 | |||
23 | This is effectively what was done (by accident) before we added a | ||
24 | check for nSelectors to be at most BZ_MAX_SELECTORS to mitigate | ||
25 | CVE-2019-12900. | ||
26 | |||
27 | The extra selectors were written out after the array inside the | ||
28 | EState struct. But the struct has extra space allocated after the | ||
29 | selector arrays of 18060 bytes (which is larger than 14766). | ||
30 | All of which will be initialized later (so the overwrite of that | ||
31 | space with extra selector values would have been harmless). | ||
32 | |||
33 | Upstream-Status: Backport | ||
34 | Signed-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 | |||
41 | diff --git a/compress.c b/compress.c | ||
42 | index 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 | |||
54 | diff --git a/decompress.c b/decompress.c | ||
55 | index 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 | ||
19 | SRC_URI[md5sum] = "00b516f4704d4a7cb50a1d97e6e8e15b" | 21 | SRC_URI[md5sum] = "00b516f4704d4a7cb50a1d97e6e8e15b" |