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
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.
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.
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.
Statement: This issue did not affect the versions of ruby as shipped with Red Hat Enterprise Linux 5 and 6.
Created ruby tracking bugs for this issue: Affects: fedora-all [bug 1120856]
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.
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
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
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