Bug 1118158 (CVE-2014-4975) - CVE-2014-4975 ruby: off-by-one stack-based buffer overflow in the encodes() function
Summary: CVE-2014-4975 ruby: off-by-one stack-based buffer overflow in the encodes() f...
Keywords:
Status: CLOSED ERRATA
Alias: CVE-2014-4975
Product: Security Response
Classification: Other
Component: vulnerability
Version: unspecified
Hardware: All
OS: Linux
low
low
Target Milestone: ---
Assignee: Red Hat Product Security
QA Contact:
URL:
Whiteboard:
Depends On: 1120856 1163998 1164000 1164004 1164005 1542178 1542179
Blocks: 1118161 1157711
TreeView+ depends on / blocked
 
Reported: 2014-07-10 06:13 UTC by Murray McAllister
Modified: 2021-02-17 06:24 UTC (History)
62 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-08-07 13:21:14 UTC
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHSA-2014:1912 0 normal SHIPPED_LIVE Moderate: ruby security update 2014-11-27 03:37:35 UTC
Red Hat Product Errata RHSA-2014:1913 0 normal SHIPPED_LIVE Moderate: ruby193-ruby security update 2014-11-26 21:52:42 UTC
Red Hat Product Errata RHSA-2014:1914 0 normal SHIPPED_LIVE Moderate: ruby200-ruby security update 2014-11-26 21:52:27 UTC

Description Murray McAllister 2014-07-10 06:13:53 UTC
A possible stack-based buffer overflow flaw was reported in the Ruby encodes() function from pack.c. From the bug report, this function may be used on data received from a server, and could be triggered remotely.

As the affected stack buffer is a static size on the stack, FORTIFY_SOURCE may help mitigate this issue to only be a denial of service.

The original report suggests older versions (such as 1.9.3) are not affected.

Bug report: https://bugs.ruby-lang.org/issues/10019

CVE request: http://www.openwall.com/lists/oss-security/2014/07/09/13

Comment 1 Ján Rusnačko 2014-07-10 10:45:07 UTC
The proposed patch is not OK, since len can be up to ULONG_MAX big. 

The best I could get is:

2.1.2-p168 :015 > ['1'*(2**32)].pack 'm4566666666666666664'
Killed
[jrusnack@griffin ruby]$ irb
2.1.2-p168 :001 > ['1'*(2**32)].pack 'm4566666666666666664'
NoMemoryError: failed to allocate memory
	from (irb):1:in `pack'
	from (irb):1
	from /home/jrusnack/.rvm/rubies/ruby-2.1.2/bin/irb:11:in `<main>'

which can be expected. From the report I don`t see how one can get SEGFAULT. I also compiled ruby with address sanitizer and found nothing.

Comment 2 Tomas Hoger 2014-07-10 19:01:35 UTC
It is possible to trigger an off-by-one write, with '\n' character written past the end of the input buffer.  That happens when the encodes() function is called with len of 3070 or 3071.  That can happen in the following cases:

- the length of the input string is 3070 (or 3071) and count value for the m
  format directive is 3072 or more
- count value for the m format directive is exactly 3072 and the length of the
  input string is n*3072 - 2 (or -1)

I.e. crash can be possibly reproduced with:

- ["a"*3070].pack("m4000")
- ["a"*(3072*3-2)].pack("m3072")

Both cases require rather non-standard format specification that requests long output lines.  Hence this is unlikely to be triggered in applications that may encode untrusted input strings, but use trusted format specification.

Also considering the limited overflow (single byte that is not attacker controlled), this is unlikely to have code execution impact.  For ruby builds using stack protector (such as those in Red Hat Enterprise Linux or Fedora), the overflow is detected if it reaches canary value.

It is currently unclear if the issue described above is the problem reporter ran into.

Comment 4 Tomas Hoger 2014-07-17 21:23:25 UTC
CVE-2014-4975 was assigned to the off-by-one overflow in encodes() as described in comment 2 above and upstream bug:
https://bugs.ruby-lang.org/issues/10019#note-6

For CVE assignment, see:
http://seclists.org/oss-sec/2014/q3/173

The issue was fixed upstream in the following commit:
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46778

As noted above, this overflow can only happen when using specific format specification for Ruby Array's pack() method:
http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-pack

Format "m" (base64 encoding) with length argument of at least 3072 is affected.  This is unlikely in cases when format string is from a trusted source, as the length value defines the maximum length of the output line.  After the specified number of characters, a line break is inserted.  Typical use case would limit line length to less than ~100 characters, the default is 60 characters if no length is specified.  The alternative is output with no line breaks at all, which can be requested using format "m0", and is unaffected by this issue.

This is not very likely to be exposed, and with limited impact on Ruby builds with stack protector.  Considering this a Low impact issue.

Comment 5 Tomas Hoger 2014-07-17 21:25:26 UTC
Statement:

This issue did not affect the versions of ruby as shipped with Red Hat Enterprise Linux 5 and 6.

Comment 6 Tomas Hoger 2014-07-17 21:26:16 UTC
Created ruby tracking bugs for this issue:

Affects: fedora-all [bug 1120856]

Comment 7 Fedora Update System 2014-11-10 06:32:21 UTC
ruby-2.1.4-24.fc21 has been pushed to the Fedora 21 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 11 errata-xmlrpc 2014-11-26 16:52:55 UTC
This issue has been addressed in the following products:

  Red Hat Software Collections 1 for Red Hat Enterprise Linux 7
  Red Hat Software Collections 1 for Red Hat Enterprise Linux 6
  Red Hat Software Collections 1 for Red Hat Enterprise Linux 6.5 EUS
  Red Hat Software Collections 1 for Red Hat Enterprise Linux 6.4 EUS
  Red Hat Software Collections 1 for Red Hat Enterprise Linux 6.6 EUS

Via RHSA-2014:1914 https://rhn.redhat.com/errata/RHSA-2014-1914.html

Comment 12 errata-xmlrpc 2014-11-26 16:53:24 UTC
This issue has been addressed in the following products:

  Red Hat Software Collections 1 for Red Hat Enterprise Linux 7
  Red Hat Software Collections 1 for Red Hat Enterprise Linux 6
  Red Hat Software Collections 1 for Red Hat Enterprise Linux 6.5 EUS
  Red Hat Software Collections 1 for Red Hat Enterprise Linux 6.4 EUS
  Red Hat Software Collections 1 for Red Hat Enterprise Linux 6.6 EUS

Via RHSA-2014:1913 https://rhn.redhat.com/errata/RHSA-2014-1913.html

Comment 13 errata-xmlrpc 2014-11-26 22:37:48 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 7

Via RHSA-2014:1912 https://rhn.redhat.com/errata/RHSA-2014-1912.html


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