From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Vong Subject: Re: bug#25935: [PATCH] gnu: mupdf: Fix CVE-2017-{5896,5991}. Date: Fri, 03 Mar 2017 14:04:11 +0800 Message-ID: <877f466gmc.fsf@gmail.com> References: <87wpc7bz0u.fsf@gmail.com> <20170302181150.GA9579@jasmine> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43026) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cjgKO-000790-Go for guix-devel@gnu.org; Fri, 03 Mar 2017 01:04:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cjgKL-0004HJ-1k for guix-devel@gnu.org; Fri, 03 Mar 2017 01:04:32 -0500 Received: from mail-pf0-x22c.google.com ([2607:f8b0:400e:c00::22c]:34947) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cjgKK-0004Gp-Qh for guix-devel@gnu.org; Fri, 03 Mar 2017 01:04:29 -0500 Received: by mail-pf0-x22c.google.com with SMTP id j5so30026199pfb.2 for ; Thu, 02 Mar 2017 22:04:27 -0800 (PST) In-Reply-To: <20170302181150.GA9579@jasmine> (Leo Famulari's message of "Thu, 2 Mar 2017 13:11:50 -0500") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Leo Famulari Cc: guix-devel@gnu.org, 25935@debbugs.gnu.org --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Leo Famulari writes: > On Thu, Mar 02, 2017 at 09:15:29PM +0800, Alex Vong wrote: >> This patch (applied to core-updates) fixes the two CVEs disclosed recently. > > Can you send a patch for the master branch instead? The patches should > be applied to mupdf/fixed in (gnu packages pdf). Sure, here it is: --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=0001-gnu-mupdf-Fix-CVE-2017-5896-5991.patch Content-Transfer-Encoding: quoted-printable From=2024ceef58b2ebb70d45c01e7e1bc43cc2056f8705 Mon Sep 17 00:00:00 2001 From: Alex Vong Date: Thu, 2 Mar 2017 19:59:05 +0800 Subject: [PATCH] gnu: mupdf: Fix CVE-2017-{5896,5991}. * gnu/packages/patches/mupdf-CVE-2017-5896.patch, gnu/packages/patches/mupdf-CVE-2017-5991.patch: New files. * gnu/packages/pdf.scm (mupdf/fixed)[source]: Add patches. * gnu/local.mk (dist_patch_DATA): Add them. =2D-- gnu/local.mk | 2 + gnu/packages/patches/mupdf-CVE-2017-5896.patch | 63 +++++++++++++++ gnu/packages/patches/mupdf-CVE-2017-5991.patch | 101 +++++++++++++++++++++= ++++ gnu/packages/pdf.scm | 5 +- 4 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 gnu/packages/patches/mupdf-CVE-2017-5896.patch create mode 100644 gnu/packages/patches/mupdf-CVE-2017-5991.patch diff --git a/gnu/local.mk b/gnu/local.mk index 406e0dc96..584ab75a5 100644 =2D-- a/gnu/local.mk +++ b/gnu/local.mk @@ -764,6 +764,8 @@ dist_patch_DATA =3D \ %D%/packages/patches/mupdf-build-with-openjpeg-2.1.patch \ %D%/packages/patches/mupdf-mujs-CVE-2016-10132.patch \ %D%/packages/patches/mupdf-mujs-CVE-2016-10133.patch \ + %D%/packages/patches/mupdf-CVE-2017-5896.patch \ + %D%/packages/patches/mupdf-CVE-2017-5991.patch \ %D%/packages/patches/mupen64plus-ui-console-notice.patch \ %D%/packages/patches/musl-CVE-2016-8859.patch \ %D%/packages/patches/mutt-store-references.patch \ diff --git a/gnu/packages/patches/mupdf-CVE-2017-5896.patch b/gnu/packages/= patches/mupdf-CVE-2017-5896.patch new file mode 100644 index 000000000..1537ecc89 =2D-- /dev/null +++ b/gnu/packages/patches/mupdf-CVE-2017-5896.patch @@ -0,0 +1,63 @@ +Fix CVE-2017-5896: + +https://bugs.ghostscript.com/show_bug.cgi?id=3D697515 +https://cve.mitre.org/cgi-bin/cvename.cgi?name=3DCVE-2017-5896 +http://www.openwall.com/lists/oss-security/2017/02/10/1 +https://security-tracker.debian.org/tracker/CVE-2017-5896 +https://blogs.gentoo.org/ago/2017/02/09/mupdf-use-after-free-in-fz_subsamp= le_pixmap-pixmap-c/ + +Patch lifted from upstream source repository: + +http://git.ghostscript.com/?p=3Dmupdf.git;h=3D2c4e5867ee699b1081527bc6c6ea= 0e99a35a5c27 + +From 2c4e5867ee699b1081527bc6c6ea0e99a35a5c27 Mon Sep 17 00:00:00 2001 +From: Robin Watts +Date: Thu, 9 Feb 2017 07:12:16 -0800 +Subject: [PATCH] bug 697515: Fix out of bounds read in fz_subsample_pixmap + +Pointer arithmetic for final special case was going wrong. +--- + source/fitz/pixmap.c | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/source/fitz/pixmap.c b/source/fitz/pixmap.c +index a8317127..f1291dc2 100644 +--- a/source/fitz/pixmap.c ++++ b/source/fitz/pixmap.c +@@ -1104,6 +1104,7 @@ fz_subsample_pixmap_ARM(unsigned char *ptr, int w, i= nt h, int f, int factor, + "@STACK:r1,<9>,factor,n,fwd,back,back2,fwd2,divX,back4,fwd4,fwd3,divY,ba= ck5,divXY\n" + "ldr r4, [r13,#4*22] @ r4 =3D divXY \n" + "ldr r5, [r13,#4*11] @ for (nn =3D n; nn > 0; n--) { \n" ++ "ldr r8, [r13,#4*17] @ r8 =3D back4 \n" + "18: @ \n" + "mov r14,#0 @ r14=3D v =3D 0 \n" + "sub r5, r5, r1, LSL #8 @ for (xx =3D x; xx > 0; x--) { \n" +@@ -1120,7 +1121,7 @@ fz_subsample_pixmap_ARM(unsigned char *ptr, int w, i= nt h, int f, int factor, + "mul r14,r4, r14 @ r14=3D v *=3D divX \n" + "mov r14,r14,LSR #16 @ r14=3D v >>=3D 16 \n" + "strb r14,[r9], #1 @ *d++ =3D r14 \n" +- "sub r0, r0, r8 @ s -=3D back2 \n" ++ "sub r0, r0, r8 @ s -=3D back4 \n" + "subs r5, r5, #1 @ n-- \n" + "bgt 18b @ } \n" + "21: @ \n" +@@ -1249,6 +1250,7 @@ fz_subsample_pixmap(fz_context *ctx, fz_pixmap *tile= , int factor) + x +=3D f; + if (x > 0) + { ++ int back4 =3D x * n - 1; + div =3D x * y; + for (nn =3D n; nn > 0; nn--) + { +@@ -1263,7 +1265,7 @@ fz_subsample_pixmap(fz_context *ctx, fz_pixmap *tile= , int factor) + s -=3D back5; + } + *d++ =3D v / div; +- s -=3D back2; ++ s -=3D back4; + } + } + } +--=20 +2.12.0 + diff --git a/gnu/packages/patches/mupdf-CVE-2017-5991.patch b/gnu/packages/= patches/mupdf-CVE-2017-5991.patch new file mode 100644 index 000000000..1fa6dc346 =2D-- /dev/null +++ b/gnu/packages/patches/mupdf-CVE-2017-5991.patch @@ -0,0 +1,101 @@ +Fix CVE-2017-5991: + +https://bugs.ghostscript.com/show_bug.cgi?id=3D697500 +https://cve.mitre.org/cgi-bin/cvename.cgi?name=3DCVE-2017-5991 +https://security-tracker.debian.org/tracker/CVE-2017-5991 + +Patch lifted from upstream source repository: + +http://git.ghostscript.com/?p=3Dmupdf.git;h=3D1912de5f08e90af1d9d0a9791f58= ba3afdb9d465 + +From 1912de5f08e90af1d9d0a9791f58ba3afdb9d465 Mon Sep 17 00:00:00 2001 +From: Robin Watts +Date: Thu, 9 Feb 2017 15:49:15 +0000 +Subject: [PATCH] Bug 697500: Fix NULL ptr access. + +Cope better with errors during rendering - avoid letting the +gstate stack get out of sync. + +This avoids us ever getting into the situation of popping +a clip when we should be popping a mask or a group. This was +causing an unexpected case in the painting. +--- + source/pdf/pdf-op-run.c | 26 ++++++++++++++++++-------- + 1 file changed, 18 insertions(+), 8 deletions(-) + +diff --git a/source/pdf/pdf-op-run.c b/source/pdf/pdf-op-run.c +index a3ea895d..f1eac8d3 100644 +--- a/source/pdf/pdf-op-run.c ++++ b/source/pdf/pdf-op-run.c +@@ -1213,6 +1213,7 @@ pdf_run_xobject(fz_context *ctx, pdf_run_processor *= proc, pdf_xobject *xobj, pdf + pdf_run_processor *pr =3D (pdf_run_processor *)proc; + pdf_gstate *gstate =3D NULL; + int oldtop =3D 0; ++ int oldbot =3D -1; + fz_matrix local_transform =3D *transform; + softmask_save softmask =3D { NULL }; + int gparent_save; +@@ -1232,16 +1233,17 @@ pdf_run_xobject(fz_context *ctx, pdf_run_processor= *proc, pdf_xobject *xobj, pdf + fz_var(cleanup_state); + fz_var(gstate); + fz_var(oldtop); ++ fz_var(oldbot); +=20 + gparent_save =3D pr->gparent; + pr->gparent =3D pr->gtop; ++ oldtop =3D pr->gtop; +=20 + fz_try(ctx) + { + pdf_gsave(ctx, pr); +=20 + gstate =3D pr->gstate + pr->gtop; +- oldtop =3D pr->gtop; +=20 + pdf_xobject_bbox(ctx, xobj, &xobj_bbox); + pdf_xobject_matrix(ctx, xobj, &xobj_matrix); +@@ -1302,12 +1304,25 @@ pdf_run_xobject(fz_context *ctx, pdf_run_processor= *proc, pdf_xobject *xobj, pdf +=20 + doc =3D pdf_get_bound_document(ctx, xobj->obj); +=20 ++ oldbot =3D pr->gbot; ++ pr->gbot =3D pr->gtop; ++ + pdf_process_contents(ctx, (pdf_processor*)pr, doc, resources, xobj->obj= , NULL); + } + fz_always(ctx) + { ++ /* Undo any gstate mismatches due to the pdf_process_contents call */ ++ if (oldbot !=3D -1) ++ { ++ while (pr->gtop > pr->gbot) ++ { ++ pdf_grestore(ctx, pr); ++ } ++ pr->gbot =3D oldbot; ++ } ++ + if (cleanup_state >=3D 3) +- pdf_grestore(ctx, pr); /* Remove the clippath */ ++ pdf_grestore(ctx, pr); /* Remove the state we pushed for the clippath = */ +=20 + /* wrap up transparency stacks */ + if (transparency) +@@ -1341,13 +1356,8 @@ pdf_run_xobject(fz_context *ctx, pdf_run_processor = *proc, pdf_xobject *xobj, pdf + pr->gstate[pr->gparent].ctm =3D gparent_save_ctm; + pr->gparent =3D gparent_save; +=20 +- if (gstate) +- { +- while (oldtop < pr->gtop) +- pdf_grestore(ctx, pr); +- ++ while (oldtop < pr->gtop) + pdf_grestore(ctx, pr); +- } +=20 + pdf_unmark_obj(ctx, xobj->obj); + } +--=20 +2.12.0 + diff --git a/gnu/packages/pdf.scm b/gnu/packages/pdf.scm index a229d689d..13dbd0ecd 100644 =2D-- a/gnu/packages/pdf.scm +++ b/gnu/packages/pdf.scm @@ -11,6 +11,7 @@ ;;; Coypright =C2=A9 2016 Julien Lepiller ;;; Copyright =C2=A9 2016 Arun Isaac ;;; Copyright =C2=A9 2017 Leo Famulari +;;; Copyright =C2=A9 2017 Alex Vong ;;; ;;; This file is part of GNU Guix. ;;; @@ -550,7 +551,9 @@ and examining the file structure (pdfshow).") (append (origin-patches (package-source mupdf)) (search-patches "mupdf-mujs-CVE-2016-10132.patch" =2D "mupdf-mujs-CVE-2016-10133.patch"))))))) + "mupdf-mujs-CVE-2016-10133.patch" + "mupdf-CVE-2017-5896.patch" + "mupdf-CVE-2017-5991.patch"))))))) =20 (define-public qpdf (package =2D-=20 2.12.0 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEdZDkzSn0Cycogr9IxYq4eRf1Ea4FAli5B1sACgkQxYq4eRf1 Ea7PLQ/+MVPQqVnG8KiZu8+r6aIY8CMvKTZsRDhF/r1uvdtbaxYsaIHRoFVgWoG7 etoCU5m67HIHxQKFh66lmsPOwuKl8wjiBRXQOqj54ctG7kIjidKlK5CYzYdwMKvD sACl5Ev5rKebeR0aR+gJl8fhEkXlPa81PoNCzFLSu00j0FSnAkXdNbdQsSq8Elkc s3Hd5H1IPO76FCCY49Bl+Nf9VCsssV1wFtqGy7WB0GG5tuYwAzEldMHioK6PXXET +9oC3JLhAcjEx73Zq/gxZX0P3l9iuJNwV+85dzHpaIAlP0KvkFu2bEbwYOqAKi5v q2jZNGmRoTwWsNwynL0ap2+kyFrnK3m1MnHVCUQg/oM9a9cxf67LhfgJRye6z7GK N1fi7NYr3kbauuZo9CFIi31klU4Jh4nSkJr63os1SJ3rulBMflaIw1nnmAihNoiC bO10H3teXNEHPY1Lly+i6HBjMGW2pM4vWdEkmjGQJQhAjH2mHTpIuo8ld/+8eJ7A YfVtpUm3VixG7f0RqST9Fh2F2oOMznszpZzlkX96P8ylZE+I4tApKRSqaBNCus5P m9kzS8mCryhBu0rvxRwc2BAJlQ+1K1E6eSHSqsAZhcpJTj2UTcz/e8hShtX1dMnD DLlWo8HCkvs307Th8e/Hq+hrrzpMPuRKoxVXz8G/v3F/XkMmpbE= =ony3 -----END PGP SIGNATURE----- --==-=-=--