Bug 1466739 (CVE-2017-9227)

Summary: CVE-2017-9227 oniguruma: Out-of-bounds stack read in mbc_enc_len() during regular expression searching
Product: [Other] Security Response Reporter: Adam Mariš <amaris>
Component: vulnerabilityAssignee: Red Hat Product Security <security-response-team>
Status: CLOSED ERRATA QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: unspecifiedCC: abhgupta, bkearney, cbillett, ccoleman, cpelland, dajohnso, dedgar, dmcphers, dmoppert, dominik.mierzejewski, fedora, gblomqui, gmccullo, gtanzill, hhorak, hhudgeon, jfrey, jgoulding, jhardy, jorton, jprause, ktdreyer, mtasaka, no1youknowz, obarenbo, rbeyel, rcollet, roliveri, ruby-maint, simaishi, s, strzibny, tiwillia, tomckay, vanmeeuwen+fedora, vondruch, webstack-team, yozone
Target Milestone: ---Keywords: Security
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: oniguruma 6.3.0, php 5.6.31, php 7.0.21, php 7.1.7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-06-08 03:15:52 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1466749, 1466750, 1466751, 1466752, 1466753, 1554537    
Bug Blocks: 1466748    

Description Adam Mariš 2017-06-30 11:06:19 UTC
An issue was discovered in Oniguruma 6.2.0, as used in Oniguruma-mod in
Ruby through 2.4.1 and mbstring in PHP through 7.1.5. A stack
out-of-bounds read occurs in mbc_enc_len() during regular expression
searching. Invalid handling of reg->dmin in forward_search_range()
could result in an invalid pointer dereference, as an out-of-bounds
read from a stack buffer.
 
Upstream bug:

https://github.com/kkos/oniguruma/issues/58

Upstream patch:

https://github.com/kkos/oniguruma/commit/9690d3ab1f9bcd2db8cbe1fe3ee4a5da606b8814

Comment 1 Adam Mariš 2017-06-30 11:33:27 UTC
Created oniguruma tracking bugs for this issue:

Affects: epel-7 [bug 1466750]
Affects: fedora-all [bug 1466752]


Created php tracking bugs for this issue:

Affects: fedora-all [bug 1466751]


Created ruby tracking bugs for this issue:

Affects: fedora-all [bug 1466749]


Created ruby193-ruby tracking bugs for this issue:

Affects: openshift-1 [bug 1466753]

Comment 2 Dominik Mierzejewski 2017-09-05 10:03:49 UTC
How is ruby affected? Was this reported to ruby developers?

Comment 3 Vít Ondruch 2017-09-05 10:25:36 UTC
Yes, it was.

This is the short answer:

~~~
I don't think the CVEs directly apply to us.  See below.  In short, We
check validity of strings before matching.
~~~

And for this specific issue, this is the long version:

~~~
> CVE-2017-9227 https://github.com/kkos/oniguruma/issues/58

not affected.

% ruby <<'END'
str   = [ 0xc7, 0xd6, 0xfe, 0xea, 0xe0, 0xe2, 0x00 ].pack('c*')
input = [0x6a, 0x00, 0x01, 0x6c, 0x7b, 0x00, 0x01, 0x6c, 0x7b, 0x32,
        0x32, 0x7d, 0x7b, 0x32, 0x32, 0x7d, 0x7b, 0x32, 0x32, 0x7d,
        0x7b, 0x32, 0x32, 0x7d, 0x7b, 0x32, 0x32, 0x7d, 0x7b, 0x32,
        0x32, 0x7d, 0x7b, 0x32, 0x32, 0x7d, 0x7b, 0x32, 0x32, 0x6a,
        0x00, 0x01, 0x6c, 0x7b, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d,
        0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d,
        0x1d, 0x1d, 0x32, 0x32, 0x7d, 0x7b, 0x32, 0x32, 0x7d, 0x7b,
        0x32, 0x32, 0x7d, 0x7b, 0x32, 0x32, 0x7d, 0x7b, 0x32, 0x32,
        0x7d, 0x7b, 0x32, 0x7d, 0x7b, 0x32, 0x32, 0x7d, 0x7b, 0x32,
        0x32, 0x7d, 0x7b, 0x32, 0x7d].pack('c*')

re = Regexp.new(input.force_encoding('UTF-8'), Regexp::IGNORECASE)
re.match str.force_encoding('UTF-8')
END
Traceback (most recent call last):
        1: from -:14:in `<main>'
-:14:in `match': invalid byte sequence in UTF-8 (ArgumentError)
~~~

But they are still awaiting for upstream (Oniguruma) response.

Comment 4 Dominik Mierzejewski 2017-09-05 10:47:59 UTC
Thank you for the clarification, Vit. Could you please have the advisory at https://access.redhat.com/security/cve/CVE-2017-9227 updated to say that ruby is not affected, then?

Comment 5 Vít Ondruch 2017-09-05 10:56:06 UTC
(In reply to Dominik Mierzejewski from comment #4)
Unfortunately, this is not in my hands. This should be:

1) Officially clarified by upstream.
2) The portal should be updated by Red Hat Security team.

Comment 6 Doran Moppert 2017-09-07 02:55:28 UTC
Thanks Vit!

Ruby's string validation blocks the obvious reproducer, but I wasn't confident enough that other paths couldn't reach it to mark Ruby as notaffected.

If you receive further info from upstream, please needinfo or mail me directly and I'll make sure these bugs and the CVE pages are updated correctly.

Comment 9 errata-xmlrpc 2018-05-03 05:06:54 UTC
This issue has been addressed in the following products:

  Red Hat Software Collections for Red Hat Enterprise Linux 6
  Red Hat Software Collections for Red Hat Enterprise Linux 6.7 EUS
  Red Hat Software Collections for Red Hat Enterprise Linux 7
  Red Hat Software Collections for Red Hat Enterprise Linux 7.3 EUS
  Red Hat Software Collections for Red Hat Enterprise Linux 7.4 EUS
  Red Hat Software Collections for Red Hat Enterprise Linux 7.5 EUS

Via RHSA-2018:1296 https://access.redhat.com/errata/RHSA-2018:1296