From e556bbcee03a7ffab00b3748f3370be7f915c772 Mon Sep 17 00:00:00 2001 From: Sona Sarmadi Date: Tue, 15 Mar 2016 07:17:13 +0100 Subject: libpng: CVE-2015-8126 Fixes buffer overflow vulnerabilities in png_get_PLTE/png_set_PLTE functions References: https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2015-8126 http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2015-8126 Upstream patches: https://github.com/glennrp/libpng/commit/81f44665cce4cb1373f049a76f3904e981b7a766 https://github.com/glennrp/libpng/commit/a901eb3ce6087e0afeef988247f1a1aa208cb54d https://github.com/glennrp/libpng/commit/1bef8e97995c33123665582e57d3ed40b57d5978 https://github.com/glennrp/libpng/commit/83f4c735c88e7f451541c1528d8043c31ba3b466 Signed-off-by: Sona Sarmadi Signed-off-by: Paul Vaduva --- .../libpng/libpng-1.6.13/CVE-2015-8126_1.patch | 69 +++++++++++++++++ .../libpng/libpng-1.6.13/CVE-2015-8126_2.patch | 88 ++++++++++++++++++++++ .../libpng/libpng-1.6.13/CVE-2015-8126_3.patch | 79 +++++++++++++++++++ .../libpng/libpng-1.6.13/CVE-2015-8126_4.patch | 48 ++++++++++++ meta/recipes-multimedia/libpng/libpng_1.6.13.bb | 6 ++ 5 files changed, 290 insertions(+) create mode 100644 meta/recipes-multimedia/libpng/libpng-1.6.13/CVE-2015-8126_1.patch create mode 100644 meta/recipes-multimedia/libpng/libpng-1.6.13/CVE-2015-8126_2.patch create mode 100644 meta/recipes-multimedia/libpng/libpng-1.6.13/CVE-2015-8126_3.patch create mode 100644 meta/recipes-multimedia/libpng/libpng-1.6.13/CVE-2015-8126_4.patch (limited to 'meta/recipes-multimedia') diff --git a/meta/recipes-multimedia/libpng/libpng-1.6.13/CVE-2015-8126_1.patch b/meta/recipes-multimedia/libpng/libpng-1.6.13/CVE-2015-8126_1.patch new file mode 100644 index 0000000000..7d4c3fe80b --- /dev/null +++ b/meta/recipes-multimedia/libpng/libpng-1.6.13/CVE-2015-8126_1.patch @@ -0,0 +1,69 @@ +From 81f44665cce4cb1373f049a76f3904e981b7a766 Mon Sep 17 00:00:00 2001 +From: Glenn Randers-Pehrson +Date: Thu, 29 Oct 2015 09:26:41 -0500 +Subject: [PATCH] [libpng16] Reject attempt to write over-length PLTE chunk + +Upstream-Status: Backport +https://github.com/glennrp/libpng/commit/81f44665cce4cb1373f049a76f3904e981b7a766 + +CVE: CVE-2015-8126 patch #1 + +Signed-off-by: Armin Kuster +Signed-off-by: Sona Sarmadi + +diff -ruN a/libpng.3 b/libpng.3 +--- a/libpng.3 2014-08-21 12:53:36.000000000 +0200 ++++ b/libpng.3 2016-03-14 12:32:29.071935164 +0100 +@@ -5611,6 +5611,11 @@ + chunk. This error was fixed in libpng-1.6.3, and a tool (called + contrib/tools/png-fix-itxt) has been added to the libpng distribution. + ++Starting with libpng-1.6.19, attempting to write an over-length PLTE chunk ++is an error. Previously this requirement of the PNG specification was not ++enforced. Libpng continues to accept over-length PLTE chunks when reading, ++but does not make any use of the extra entries. ++ + .SH XIII. Detecting libpng + + The png_get_io_ptr() function has been present since libpng-0.88, has never +diff -ruN a/libpng-manual.txt b/libpng-manual.txt +--- a/libpng-manual.txt 2014-08-21 12:53:36.000000000 +0200 ++++ b/libpng-manual.txt 2016-03-14 12:32:29.067935336 +0100 +@@ -5107,6 +5107,11 @@ + chunk. This error was fixed in libpng-1.6.3, and a tool (called + contrib/tools/png-fix-itxt) has been added to the libpng distribution. + ++Starting with libpng-1.6.19, attempting to write an over-length PLTE chunk ++is an error. Previously this requirement of the PNG specification was not ++enforced. Libpng continues to accept over-length PLTE chunks when reading, ++but does not make any use of the extra entries. ++ + XIII. Detecting libpng + + The png_get_io_ptr() function has been present since libpng-0.88, has never +diff -ruN a/pngwutil.c b/pngwutil.c +--- a/pngwutil.c 2014-08-21 12:53:37.000000000 +0200 ++++ b/pngwutil.c 2016-03-14 12:35:00.001454124 +0100 +@@ -919,17 +919,20 @@ + png_write_PLTE(png_structrp png_ptr, png_const_colorp palette, + png_uint_32 num_pal) + { +- png_uint_32 i; ++ png_uint_32 max_num_pal, i; + png_const_colorp pal_ptr; + png_byte buf[3]; + + png_debug(1, "in png_write_PLTE"); + ++ max_num_pal = (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ? ++ (1 << png_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH; ++ + if (( + #ifdef PNG_MNG_FEATURES_SUPPORTED + !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) && + #endif +- num_pal == 0) || num_pal > 256) ++ num_pal == 0) || num_pal > max_num_pal) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { diff --git a/meta/recipes-multimedia/libpng/libpng-1.6.13/CVE-2015-8126_2.patch b/meta/recipes-multimedia/libpng/libpng-1.6.13/CVE-2015-8126_2.patch new file mode 100644 index 0000000000..69cb565901 --- /dev/null +++ b/meta/recipes-multimedia/libpng/libpng-1.6.13/CVE-2015-8126_2.patch @@ -0,0 +1,88 @@ +From a901eb3ce6087e0afeef988247f1a1aa208cb54d Mon Sep 17 00:00:00 2001 +From: Glenn Randers-Pehrson +Date: Fri, 30 Oct 2015 07:57:49 -0500 +Subject: [PATCH] [libpng16] Prevent reading over-length PLTE chunk (Cosmin + Truta). + +Upstream-Status: Backport +https://github.com/glennrp/libpng/commit/a901eb3ce6087e0afeef988247f1a1aa208cb54d + +Many changes involved date and version updates with don't apply in this case. + +CVE: CVE-2015-8126 patch #2 +Signed-off-by: Armin Kuster +Signed-off-by: Sona Sarmadi + +diff -ruN a/pngrutil.c b/pngrutil.c +--- a/pngrutil.c 2014-08-21 12:53:36.000000000 +0200 ++++ b/pngrutil.c 2016-03-14 13:05:12.419581068 +0100 +@@ -997,6 +997,9 @@ + * confusing. + * + * Fix this by not sharing the palette in this way. ++ * ++ * Starting with libpng-1.6.19, png_set_PLTE() also issues a png_error() when ++ * it attempts to set a palette length that is too large for the bit depth. + */ + png_set_PLTE(png_ptr, info_ptr, palette, num); + +diff -ruN a/pngset.c b/pngset.c +--- a/pngset.c 2014-08-21 12:53:36.000000000 +0200 ++++ b/pngset.c 2016-03-14 13:05:12.439580208 +0100 +@@ -503,12 +503,17 @@ + png_const_colorp palette, int num_palette) + { + ++ png_uint_32 max_palette_length; ++ + png_debug1(1, "in %s storage function", "PLTE"); + + if (png_ptr == NULL || info_ptr == NULL) + return; + +- if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH) ++ max_palette_length = (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ? ++ (1 << png_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH; ++ ++ if (num_palette < 0 || num_palette > max_palette_length) + { + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + png_error(png_ptr, "Invalid palette length"); +@@ -541,8 +546,8 @@ + png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); + + /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead +- * of num_palette entries, in case of an invalid PNG file that has +- * too-large sample values. ++ * of num_palette entries, in case of an invalid PNG file or incorrect ++ * call to png_set_PLTE() with too-large sample values. + */ + png_ptr->palette = png_voidcast(png_colorp, png_calloc(png_ptr, + PNG_MAX_PALETTE_LENGTH * (sizeof (png_color)))); +diff -ruN a/pngwutil.c b/pngwutil.c +--- a/pngwutil.c 2016-03-14 13:01:23.433428517 +0100 ++++ b/pngwutil.c 2016-03-14 13:07:42.933108329 +0100 +@@ -919,20 +919,20 @@ + png_write_PLTE(png_structrp png_ptr, png_const_colorp palette, + png_uint_32 num_pal) + { +- png_uint_32 max_num_pal, i; ++ png_uint_32 max_palette_length, i; + png_const_colorp pal_ptr; + png_byte buf[3]; + + png_debug(1, "in png_write_PLTE"); + +- max_num_pal = (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ? ++ max_palette_length = (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ? + (1 << png_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH; + + if (( + #ifdef PNG_MNG_FEATURES_SUPPORTED + !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) && + #endif +- num_pal == 0) || num_pal > max_num_pal) ++ num_pal == 0) || num_pal > max_palette_length) + { + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + { diff --git a/meta/recipes-multimedia/libpng/libpng-1.6.13/CVE-2015-8126_3.patch b/meta/recipes-multimedia/libpng/libpng-1.6.13/CVE-2015-8126_3.patch new file mode 100644 index 0000000000..0e0ad23200 --- /dev/null +++ b/meta/recipes-multimedia/libpng/libpng-1.6.13/CVE-2015-8126_3.patch @@ -0,0 +1,79 @@ +From 1bef8e97995c33123665582e57d3ed40b57d5978 Mon Sep 17 00:00:00 2001 +From: Glenn Randers-Pehrson +Date: Fri, 30 Oct 2015 11:34:37 -0500 +Subject: [PATCH] [libpng16] Silently truncate over-length PLTE chunk while + reading. + +Upstream-Status: Backport +https://github.com/glennrp/libpng/commit/1bef8e97995c33123665582e57d3ed40b57d5978 + +Normal Issues is date and version conflicts not applied. + +CVE: CVE-2015-8i26 patch #3 + +Signed-off-by: Armin Kuster + + +--- + ANNOUNCE | 3 ++- + CHANGES | 3 ++- + pngrutil.c | 15 +++++++++++---- + pngset.c | 2 +- + 4 files changed, 16 insertions(+), 7 deletions(-) + +Index: libpng-1.6.17/pngrutil.c +=================================================================== +--- libpng-1.6.17.orig/pngrutil.c ++++ libpng-1.6.17/pngrutil.c +@@ -867,7 +867,7 @@ void /* PRIVATE */ + png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) + { + png_color palette[PNG_MAX_PALETTE_LENGTH]; +- int num, i; ++ int max_palette_length, num, i; + #ifdef PNG_POINTER_INDEXING_SUPPORTED + png_colorp pal_ptr; + #endif +@@ -925,9 +925,19 @@ png_handle_PLTE(png_structrp png_ptr, pn + return; + } + ++ max_palette_length = (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ? ++ (1 << png_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH; ++ + /* The cast is safe because 'length' is less than 3*PNG_MAX_PALETTE_LENGTH */ + num = (int)length / 3; + ++ /* If the palette has 256 or fewer entries but is too large for the bit depth, ++ * we don't issue an error, to preserve the behavior of previous libpng versions. ++ * We silently truncate the unused extra palette entries here. ++ */ ++ if (num > max_palette_length) ++ num = max_palette_length; ++ + #ifdef PNG_POINTER_INDEXING_SUPPORTED + for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++) + { +@@ -997,9 +1007,6 @@ png_handle_PLTE(png_structrp png_ptr, pn + * confusing. + * + * Fix this by not sharing the palette in this way. +- * +- * Starting with libpng-1.6.19, png_set_PLTE() also issues a png_error() when +- * it attempts to set a palette length that is too large for the bit depth. + */ + png_set_PLTE(png_ptr, info_ptr, palette, num); + +Index: libpng-1.6.17/pngset.c +=================================================================== +--- libpng-1.6.17.orig/pngset.c ++++ libpng-1.6.17/pngset.c +@@ -523,7 +523,7 @@ png_set_PLTE(png_structrp png_ptr, png_i + max_palette_length = (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ? + (1 << png_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH; + +- if (num_palette < 0 || num_palette > max_palette_length) ++ if (num_palette < 0 || num_palette > (int) max_palette_length) + { + if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + png_error(png_ptr, "Invalid palette length"); diff --git a/meta/recipes-multimedia/libpng/libpng-1.6.13/CVE-2015-8126_4.patch b/meta/recipes-multimedia/libpng/libpng-1.6.13/CVE-2015-8126_4.patch new file mode 100644 index 0000000000..2622630d10 --- /dev/null +++ b/meta/recipes-multimedia/libpng/libpng-1.6.13/CVE-2015-8126_4.patch @@ -0,0 +1,48 @@ +From 83f4c735c88e7f451541c1528d8043c31ba3b466 Mon Sep 17 00:00:00 2001 +From: Glenn Randers-Pehrson +Date: Thu, 5 Nov 2015 11:18:44 -0600 +Subject: [PATCH] [libpng16] Clean up coding style in png_handle_PLTE() + +Upstream-Status: Backport +https://github.com/glennrp/libpng/commit/83f4c735c88e7f451541c1528d8043c31ba3b466 + +CVE: CVE-2015-8126 patch #4 +Signed-off-by: Armin Kuster + +--- + pngrutil.c | 17 ++++++++++------- + 1 file changed, 10 insertions(+), 7 deletions(-) + +Index: libpng-1.6.17/pngrutil.c +=================================================================== +--- libpng-1.6.17.orig/pngrutil.c ++++ libpng-1.6.17/pngrutil.c +@@ -925,18 +925,21 @@ png_handle_PLTE(png_structrp png_ptr, pn + return; + } + +- max_palette_length = (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ? +- (1 << png_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH; +- + /* The cast is safe because 'length' is less than 3*PNG_MAX_PALETTE_LENGTH */ + num = (int)length / 3; + +- /* If the palette has 256 or fewer entries but is too large for the bit depth, +- * we don't issue an error, to preserve the behavior of previous libpng versions. +- * We silently truncate the unused extra palette entries here. ++ /* If the palette has 256 or fewer entries but is too large for the bit ++ * depth, we don't issue an error, to preserve the behavior of previous ++ * libpng versions. We silently truncate the unused extra palette entries ++ * here. + */ ++ if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ++ max_palette_length = (1 << png_ptr->bit_depth); ++ else ++ max_palette_length = PNG_MAX_PALETTE_LENGTH; ++ + if (num > max_palette_length) +- num = max_palette_length; ++ num = max_palette_length; + + #ifdef PNG_POINTER_INDEXING_SUPPORTED + for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++) diff --git a/meta/recipes-multimedia/libpng/libpng_1.6.13.bb b/meta/recipes-multimedia/libpng/libpng_1.6.13.bb index 3d32bfea2c..80dcc0a63f 100644 --- a/meta/recipes-multimedia/libpng/libpng_1.6.13.bb +++ b/meta/recipes-multimedia/libpng/libpng_1.6.13.bb @@ -10,6 +10,12 @@ LIBV = "16" SRC_URI = "${SOURCEFORGE_MIRROR}/project/libpng/libpng${LIBV}/${PV}/libpng-${PV}.tar.xz \ " +SRC_URI += "\ + file://CVE-2015-8126_1.patch \ + file://CVE-2015-8126_2.patch \ + file://CVE-2015-8126_3.patch \ + file://CVE-2015-8126_4.patch \ + " SRC_URI[md5sum] = "9822c25466f060142359f80ed142c9e5" SRC_URI[sha256sum] = "d9c8ce54a5fc8052ed794ca65b553384a74c0608b09ae163cbbb07176018e625" -- cgit v1.2.3-54-g00ecf