Bug 16629 - jasper new security issue CVE-2016-1867
Summary: jasper new security issue CVE-2016-1867
Status: RESOLVED FIXED
Alias: None
Product: Mageia
Classification: Unclassified
Component: Security (show other bugs)
Version: 5
Hardware: All Linux
Priority: Normal normal
Target Milestone: ---
Assignee: QA Team
QA Contact: Sec team
URL: http://lwn.net/Vulnerabilities/673469/
Whiteboard: has_procedure advisory MGA5-64-OK
Keywords: validated_update
Depends on:
Blocks:
 
Reported: 2015-08-21 20:11 CEST by David Walser
Modified: 2016-02-09 20:06 CET (History)
3 users (show)

See Also:
Source RPM: jasper-1.900.1-20.mga5.src.rpm
CVE:
Status comment:


Attachments
Crafted JPEG 2000 file (551 bytes, image/jpeg)
2016-01-28 19:27 CET, Len Lawrence
Details
Information from upstream tests. (1.10 KB, text/plain)
2016-01-28 19:29 CET, Len Lawrence
Details

Description David Walser 2015-08-21 20:11:44 CEST
Some security issues in jasper have been reported, and a patch is available that may fix some of them, but it does not completely apply cleanly:
http://openwall.com/lists/oss-security/2015/08/21/4

Mageia 4 and Mageia 5 are also affected.

Reproducible: 

Steps to Reproduce:
David Walser 2015-08-21 20:11:53 CEST

Whiteboard: (none) => MGA5TOO, MGA4TOO

Comment 1 David Walser 2015-08-24 17:57:08 CEST
Another issue was also reported (CVE-2015-5221):
http://openwall.com/lists/oss-security/2015/08/20/4

I don't know of any patch for this issue yet.
David Walser 2015-08-26 18:44:07 CEST

URL: (none) => http://lwn.net/Vulnerabilities/655645/

David Walser 2015-09-02 22:05:31 CEST

Summary: jasper new security issue CVE-2015-5203 => jasper new security issues CVE-2015-5203 and CVE-2015-5221

Comment 2 Sander Lepik 2015-10-11 18:30:32 CEST
I found the patch for the first CVE and submitted patched version into cauldron but as there is no patch for the other CVE I only commited the patch for mga5 and didn't submit yet. Not sure what to do about it. Do we wait more or we split the bug and fix at least one security issue?

CC: (none) => mageia
Hardware: i586 => All
Whiteboard: MGA5TOO, MGA4TOO => MGA5TOO

Comment 3 David Walser 2015-10-11 18:52:50 CEST
Sure, we could split it.
Comment 4 Sander Lepik 2015-10-25 13:29:58 CET
Still no patch for the other issue.
Comment 5 David Walser 2016-01-13 20:02:48 CET
Another issue was reported and assigned CVE-2016-1867:
http://openwall.com/lists/oss-security/2016/01/13/6

Summary: jasper new security issues CVE-2015-5203 and CVE-2015-5221 => jasper new security issues CVE-2015-5203, CVE-2015-5221, and CVE-2016-1867

Comment 6 David Walser 2016-01-25 17:08:11 CET
(In reply to David Walser from comment #5)
> Another issue was reported and assigned CVE-2016-1867:
> http://openwall.com/lists/oss-security/2016/01/13/6

OpenSuSE has issued an advisory for this on January 24:
http://lists.opensuse.org/opensuse-updates/2016-01/msg00077.html
Comment 7 David Walser 2016-01-25 18:11:52 CET
CVE-2015-5221 moved to Bug 17622.

Version: Cauldron => 5
Summary: jasper new security issues CVE-2015-5203, CVE-2015-5221, and CVE-2016-1867 => jasper new security issues CVE-2015-5203 and CVE-2016-1867
Whiteboard: MGA5TOO => (none)

Comment 8 David Walser 2016-01-25 18:27:44 CET
Patched packages uploaded for Mageia 5 and Cauldron.

Testing procedure in:
https://bugs.mageia.org/show_bug.cgi?id=14729

========================

Updated jasper packages fix security vulnerabilities:

A double-free issue in JasPer 1.900.1 in the jasper_image_stop_load() function
can cause a denial of service if a specially crafted JPEG image is loaded
(CVE-2015-5203).

The jpc_pi_nextcprl function in JasPer 1.900.1 allows remote attackers to
cause a denial of service (out-of-bounds read and application crash) via a
crafted JPEG 2000 image (CVE-2016-1867).

References:
http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2015-5203
http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2016-1867
http://openwall.com/lists/oss-security/2015/08/21/4
http://openwall.com/lists/oss-security/2016/01/13/6
http://lists.opensuse.org/opensuse-updates/2016-01/msg00077.html
========================

Updated packages in core/updates_testing:
========================
jasper-1.900.1-20.1.mga5
libjasper1-1.900.1-20.1.mga5
libjasper-devel-1.900.1-20.1.mga5
libjasper-static-devel-1.900.1-20.1.mga5

from jasper-1.900.1-20.1.mga5.src.rpm

Assignee: bugsquad => qa-bugs
Whiteboard: (none) => has_procedure

Comment 9 David Walser 2016-01-25 20:36:18 CET
(In reply to David Walser from comment #6)
> (In reply to David Walser from comment #5)
> > Another issue was reported and assigned CVE-2016-1867:
> > http://openwall.com/lists/oss-security/2016/01/13/6
> 
> OpenSuSE has issued an advisory for this on January 24:
> http://lists.opensuse.org/opensuse-updates/2016-01/msg00077.html

LWN reference for CVE-2016-1867:
http://lwn.net/Vulnerabilities/673469/
Comment 10 Len Lawrence 2016-01-28 01:14:13 CET
mga5  x86_64  Mate

From "urpmq -i jasper"

JasPer is a software-based implementation of the codec specified in the
emerging JPEG-2000 Part-1 standard (i.e., ISO/IEC 15444-1).  This package
contains tools for working with JPEG-2000 images.

I could not find any evidence that ImageMagick uses jasper so concentrated on jasper itself.
From jasper --help:
The following formats are supported:
    mif      My Image Format (MIF)
    pnm      Portable Graymap/Pixmap (PNM)
    bmp      Microsoft Bitmap (BMP)
    ras      Sun Rasterfile (RAS)
    jp2      JPEG-2000 JP2 File Format Syntax (ISO/IEC 15444-1)
    jpc      JPEG-2000 Code Stream Syntax (ISO/IEC 15444-1)
    jpg      JPEG (ISO/IEC 10918-1)
    pgx      JPEG-2000 VM Format (PGX)
[lcl@vega ~/qa]$ jasper --input piuva.jpg --output piuva.bmp
[lcl@vega ~/qa]$ jasper --input piuva.bmp --output piuva.jpg
THE BMP FORMAT IS NOT FULLY SUPPORTED!
THAT IS, THE JASPER SOFTWARE CANNOT DECODE ALL TYPES OF BMP DATA.
IF YOU HAVE ANY PROBLEMS, PLEASE TRY CONVERTING YOUR IMAGE DATA
TO THE PNM FORMAT, AND USING THIS FORMAT INSTEAD.
[lcl@vega ~/qa]$ jasper --input piuva.jpg --output piuva.pnm
[lcl@vega ~/qa]$ file piuva.pnm
piuva.pnm: Netpbm PPM "rawbits" image data, size = 320 x 340
[lcl@vega ~/qa]$ jasper --input piuva.pnm --output Piuva.jpg
[lcl@vega ~/qa]$ file Piuva.jpg
Piuva.jpg: JPEG image data, JFIF standard 1.01
[lcl@vega ~/qa]$ jasper --input piuva.jpg --output piuva.jp2
[lcl@vega ~/qa]$ eom piuva.jp2
[lcl@vega ~/qa]$ file piuva.jp2
piuva.jp2: JPEG 2000 Part 1 (JP2)
JPEG files also converted to jpc format but pgx failed.
[lcl@vega ~/qa]$ jasper --input piuva.pnm --output piuva.pgx
error: BMP format does not support color space
error: cannot encode image
[lcl@vega ~/qa]$ jasper --input piuva.jpg --output piuva.pgx
error: BMP format does not support color space
error: cannot encode image
[lcl@vega ~/qa]$ jasper --input piuva.jpg --output piuva.ras
All these formats can be displayed with eom, gqview, gwenview and display but only display can cope with Sun raster files.
[lcl@vega ~/qa]$ file piuva.ras
piuva.ras: Sun raster image data, 320 x 340, 24-bit, no colormap
[lcl@vega ~/qa]$ convert piuva.jpg -quality 100 piuva.pgx
[lcl@vega ~/qa]$ eom piuva.pgx      # OK
[lcl@vega ~/qa]$ display piuva.pgx  # OK
[lcl@vega ~/qa]$ gqview piuva.pgx
ERROR:filedata.c:1101:file_data_new_group: assertion failed: (fd)
Abort
Converting from a valid pgx image to jpg works.
[lcl@vega ~/qa]$ jasper --input piuva.pgx --output Piuva.jpg
[lcl@vega ~/qa]$ eom Piuva.jpg      # OK

This is all pre-update and  lacks a PoC.

Installed the update candidates and ran some of these image conversion tests again.
[lcl@vega ~/qa]$ jasper --input piuva.jpg --output piuva.jp2
[lcl@vega ~/qa]$ eom piuva.jp2
eom: jas_stream.c:1044: mem_write: Assertion `ret == cnt' failed.
Abort
[lcl@vega ~/qa]$ display piuva.jp2  # OK
[lcl@vega ~/qa]$ jasper --input piuva.pgx --output Piuva.jpg
[lcl@vega ~/qa]$ display Piuva.jpg  # OK
[lcl@vega ~/qa]$ eom Piuva.jpg      # OK
[lcl@vega ~/qa]$ jasper --input piuva.pnm --output Piuva.ras
[lcl@vega ~/qa]$ display Piuva.ras  # OK
[lcl@vega ~/qa]$ jasper --input Piuva.ras --output Piuva.jpc
[lcl@vega ~/qa]$ eom Piuva.jpc
eom: jas_stream.c:1044: mem_write: Assertion `ret == cnt' failed.
Abort
[lcl@vega ~/qa]$ display Piuva.jpc  # OK

So, the conversions work and display via ImageMagick but some of them have issues in desktop viewers.

CC: (none) => tarazed25

Comment 11 Len Lawrence 2016-01-28 02:38:22 CET
As far as I can tell eom does not use jasper and as it has not been updated the error it finds must have something to do with the format of the jpc image, for instance, which implies that there might be a bug in the jasper update or its library.  Whatever the problem is, it does not bother ImageMagick.

But now the water is getting murkier.  A pre-update jasper was used to convert a JPEG to jpc format on another machine.  eom handled it fine but the same file copied to the test machine now also fails under eom though display is fine with it.
A diff between the imported jpc file and the original on the test machine is zero.  I just cannot figure this out.
Comment 12 Len Lawrence 2016-01-28 02:48:52 CET
The md5sum values for the original and imported jpc files are identical.
I am inclined to brush this one under the carpet because the conversions all seem to succeed and no differences can be found between the files that display and those that do not (under eom).

What do you think David?
Comment 13 David Walser 2016-01-28 02:53:18 CET
I don't know what eom is.  If you can open a JPEG 2000 file in a program that uses libjasper1, then it's OK to go.
Comment 14 Len Lawrence 2016-01-28 10:51:03 CET
Sorry, eom is Eye of Mate, a fork from Eye of GNOME (eog), a simple image viewer that uses libjpeg.  I was concentrating on the conversion side and using a range of viewers to check the results.  ImageMagick seems to be the most accommodating.
The problem with eom seems to be tangential to the testing of jasper, hence the "sweep it under the carpet".
Comment 15 Len Lawrence 2016-01-28 11:23:46 CET
The Gimp is listed as one of the packages needing lib64jasper1, referred to as libjasper.so.1()(64bit).  gimp fails on jpc and jp2 files.
gimp piuva.jpc and gimp piuva.jp2 both return:
file-jp2-load: jas_stream.c:1044: mem_write: Assertion `ret == cnt' failed.
The same is true for eom.
As a cross-check I converted the jpeg image to jpc and jp2 formats using ImageMagick (which relies on libjpeg) and ran eom on them.  That returned the same jas_stream.c error.  The internal functions in libjasper1 have the form jas_streamxxx so my interpretation of the failures is that libjasper1 cannot handle the JPEG 2000 format after the update.  Not OK.
Comment 16 David Walser 2016-01-28 12:13:15 CET
Did you verify that it did work before this update?
Comment 17 Len Lawrence 2016-01-28 12:25:59 CET
Yes, I checked most of the formats, including JPEG 2000 , using different viewers.  No problems.
Comment 18 David Walser 2016-01-28 12:28:38 CET
OK thanks, we'll have to figure out which patch did it.

Whiteboard: has_procedure => has_procedure feedback

Comment 19 David Walser 2016-01-28 13:47:35 CET
Please try the build I just pushed without the CVE-2016-1867 patch.
Comment 20 Len Lawrence 2016-01-28 16:28:05 CET
Updated to -1.900.1-20.2

The following command succeeded in displaying the image:
[lcl@vega ~/qa]$ gwenview piuva.jp2
gwenview(21053) Gwenview::LoadingDocumentImplPrivate::loadMetaInfo: 
QImageReader::read() using format hint "jpc" failed: "Unsupported image format" 
gwenview(21053) Gwenview::LoadingDocumentImplPrivate::loadMetaInfo: QImageReader::read() without format hint failed: "Unsupported image format" 
This one failed:
[lcl@vega ~/qa]$ eom piuva.jp2
eom: jas_stream.c:1044: mem_write: Assertion `ret == cnt' failed.
Abort

[lcl@vega ~/qa]$ gwenview piuva.jp2
gwenview(21383) Gwenview::LoadingDocumentImplPrivate::loadMetaInfo: QImageReader::read() using format hint "jpc" failed: "Unsupported image format" 
gwenview(21383) Gwenview::LoadingDocumentImplPrivate::loadMetaInfo: QImageReader::read() without format hint failed: "Unsupported image format" 
gwenview(21383) Gwenview::LoadingDocumentImplPrivate::loadMetaInfo: QImageReader::read() using format hint "jpc" failed: "Unsupported image format" 
gwenview(21383) Gwenview::LoadingDocumentImplPrivate::loadMetaInfo: QImageReader::read() without format hint failed: "Unsupported image format" 

The image failed to display - showed a popup:
  Loading 'piuva.jpc' failed
  Loading meta information failed.

ImageMagick's display had no problem with either format.

On to .3 I guess?
Comment 21 David Walser 2016-01-28 16:31:14 CET
Now I've re-enabled the CVE-2016-1867 patch and disabled CVE-2015-5203.  Try that.

I don't see how CVE-2015-5203's patch would break things though, it just changes some int's to size_t's.
Comment 22 Len Lawrence 2016-01-28 17:41:13 CET
Updated to *-1.900.1-20.3 and all looks fine apart from rendering via gwenview.  gewnview is fine with .jp2 images but fails on .jpc as an unrecognized format, which may well be the case anyway.  Don't know enough about gwenview to say.  eom has no trouble with either.  gqview shows thumbnails for all the formats apart from ras which it does not support.  Thus the problem seems to be in the CVE-2015-5203 patch.  Maybe a cut-and-paste error in the patch?  Or a missing initialization somewhere?  Just guessing.
Comment 23 Len Lawrence 2016-01-28 17:54:02 CET
I see from http://openwall.com/lists/oss-security/2016/01/13/6 that there is a poc.jp2 somewhere which leads to a segfault but I do not know how to get hold of it.
Comment 24 David Walser 2016-01-28 18:00:36 CET
(In reply to Len Lawrence from comment #23)
> I see from http://openwall.com/lists/oss-security/2016/01/13/6 that there is
> a poc.jp2 somewhere which leads to a segfault but I do not know how to get
> hold of it.

Sorry about that.  openwall filters attachments, so you have to go to seclists for that.  Here it is:
http://seclists.org/oss-sec/2016/q1/84
Comment 25 Len Lawrence 2016-01-28 19:23:28 CET
OK, thanks David.  Command from the readme.txt file produced the expected segmentation fault message on a system with the *.1 packages:

$ jasper -f poc.jp2 -F temp.bmp -t jp2 -T bmp
Segmentation fault

Running this with the *.3 packages trapped the fault and left an empty temporary bitmap file:

$ jasper -f poc.jp2 -F temp.bmp -t jp2 -T bmp
warning: trailing garbage in marker segment (6 bytes)

I did obtain an strace but don't think it contains anything that isn't already known.

Next step is to backtrack to *.2 is it, and use --downgrade?
Comment 26 Len Lawrence 2016-01-28 19:27:40 CET
Created attachment 7383 [details]
Crafted JPEG 2000 file

$ jasper -f poc.jp2 -F temp.bmp -t jp2 -T bmp
Segmentation fault before update - warning message afterwards.
Comment 27 Len Lawrence 2016-01-28 19:29:52 CET
Created attachment 7384 [details]
Information from upstream tests.
Comment 28 Len Lawrence 2016-01-28 19:39:40 CET
Rats.  Referring to comment #25 the PoC was applied to the pre *.1 system, i.e. {jasper, lib64jasper1}-1.900.1-20.mga5 :;
Comment 29 David Walser 2016-02-05 16:57:13 CET
Len, what's the verdict on the last build of jasper?  Is it OK or not?
Comment 30 Len Lawrence 2016-02-05 17:23:22 CET
Looking at comment #26, the test showed that jasper has been fixed so it is OK with respect to CVE-2016-1867.  Not sure what is going on when the CVE-2015-5203 patch is enabled.
Comment 31 David Walser 2016-02-05 17:31:10 CET
OK, let's release the fix for CVE-2016-1867 now and deal with CVE-2015-5203 (now moved to Bug 17622) later.

Advisory:
========================

Updated jasper packages fix security vulnerabilities:

The jpc_pi_nextcprl function in JasPer 1.900.1 allows remote attackers to
cause a denial of service (out-of-bounds read and application crash) via a
crafted JPEG 2000 image (CVE-2016-1867).

References:
http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2016-1867
http://openwall.com/lists/oss-security/2016/01/13/6
http://lists.opensuse.org/opensuse-updates/2016-01/msg00077.html
========================

Updated packages in core/updates_testing:
========================
jasper-1.900.1-20.3.mga5
libjasper1-1.900.1-20.3.mga5
libjasper-devel-1.900.1-20.3.mga5
libjasper-static-devel-1.900.1-20.3.mga5

from jasper-1.900.1-20.3.mga5.src.rpm

URL: http://lwn.net/Vulnerabilities/655645/ => http://lwn.net/Vulnerabilities/673469/
Summary: jasper new security issues CVE-2015-5203 and CVE-2016-1867 => jasper new security issue CVE-2016-1867
Whiteboard: has_procedure feedback => has_procedure

Len Lawrence 2016-02-05 17:59:16 CET

Whiteboard: has_procedure => has_procedure MGA5-64-OK

Comment 32 Len Lawrence 2016-02-05 18:00:45 CET
Assuming that it is alright to go with one architecture, validating this.
Len Lawrence 2016-02-05 18:01:01 CET

Keywords: (none) => validated_update
CC: (none) => sysadmin-bugs

Comment 33 David Walser 2016-02-05 18:01:33 CET
Yep, thanks for the help Len!
Comment 34 claire robinson 2016-02-09 16:49:49 CET
Advisory uploaded.

Whiteboard: has_procedure MGA5-64-OK => has_procedure advisory MGA5-64-OK

Comment 35 Mageia Robot 2016-02-09 20:06:06 CET
An update for this issue has been pushed to the Mageia Updates repository.

http://advisories.mageia.org/MGASA-2016-0059.html

Status: NEW => RESOLVED
Resolution: (none) => FIXED


Note You need to log in before you can comment on or make changes to this bug.