Bug 451821 - (CVE-2008-2725) CVE-2008-2725 ruby: integer overflow in rb_ary_splice/update/replace() - REALLOC_N
CVE-2008-2725 ruby: integer overflow in rb_ary_splice/update/replace() - REAL...
Status: CLOSED ERRATA
Product: Security Response
Classification: Other
Component: vulnerability (Show other bugs)
unspecified
All Linux
medium Severity medium
: ---
: ---
Assigned To: Red Hat Product Security
source=vendorsec,reported=20080605,pu...
: Security
: CVE-2008-2727 (view as bug list)
Depends On: 451926 451927 451928 451929 451930 451931 452293 452294 452295
Blocks:
  Show dependency treegraph
 
Reported: 2008-06-17 12:54 EDT by Tomas Hoger
Modified: 2016-03-04 06:45 EST (History)
2 users (show)

See Also:
Fixed In Version: 1.8.6.230-1.fc9
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2008-07-26 02:02:42 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)
Drew Yao's proposed patch against ruby 1.8.5 (409 bytes, patch)
2008-06-17 12:55 EDT, Tomas Hoger
no flags Details | Diff
Drew Yao's proposed patch against ruby 1.9 (340 bytes, patch)
2008-06-17 12:55 EDT, Tomas Hoger
no flags Details | Diff

  None (edit)
Description Tomas Hoger 2008-06-17 12:54:33 EDT
Drew Yao of the Apple Product Security team reported an integer overflow leading
to a memory mis-allocation and heap overflow in the rb_ary_splice() function
used by ruby interpreter for handling arrays.  Problematic reallocation is:

     if (len >= RARRAY(ary)->aux.capa) {
-->    REALLOC_N(RARRAY(ary)->ptr, VALUE, len);
       RARRAY(ary)->aux.capa = len;
     }

This flaw can be used to crash and possibly execute arbitrary code with the
privileges of Ruby application which use untrusted input in array operations.

Acknowledgements:

Red Hat would like to thank Drew Yao of the Apple Product Security team for reporting this issue.
Comment 1 Tomas Hoger 2008-06-17 12:55:32 EDT
Created attachment 309637 [details]
Drew Yao's proposed patch against ruby 1.8.5
Comment 2 Tomas Hoger 2008-06-17 12:55:48 EDT
Created attachment 309638 [details]
Drew Yao's proposed patch against ruby 1.9
Comment 5 Tomas Hoger 2008-06-20 14:52:46 EDT
Public now, lifting embargo:
http://preview.ruby-lang.org/en/news/2008/06/20/arbitrary-code-execution-vulnerabilities

Upstream released fixed versions:
1.8.5-p231, 1.8.6-p230, 1.8.7-p22, 1.9.0-2

Patches applied upstream:
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=17460
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=17472
Comment 9 Akira TAGOH 2008-06-24 07:34:49 EDT
BTW there are no rb_ary_splice() function and no such code in even
rb_ary_replace() for 1.8.1, we have shipped for RHEL4. however there seems to be
similar code in rb_ary_update(). FYI.
Comment 10 Fedora Update System 2008-06-24 22:50:38 EDT
ruby-1.8.6.230-1.fc8 has been pushed to the Fedora 8 stable repository.  If problems still persist, please make note of it in this bug report.
Comment 11 Fedora Update System 2008-06-24 22:52:11 EDT
ruby-1.8.6.230-1.fc9 has been pushed to the Fedora 9 stable repository.  If problems still persist, please make note of it in this bug report.
Comment 12 Tomas Hoger 2008-06-25 03:10:00 EDT
(In reply to comment #9)

So more digging into the issue, it seems REALLOC_N and "beg + rlen"
issues existed in ruby forever.  Looking at the very first array.c
revision in the SVN, it seems to contain predecessor of the current
code:

http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/array.c?annotate=2#l443

It is also present in 1.4.0, thought as "beg + RARRAY(rpl)->len" as of:

http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/array.c?r1=3&r2=11#l440

This code lived in ary_replace() / rb_ary_replace() in all ruby up to
last 1.6.x ruby I managed to find - 1.6.8.

ary_replace() -> rb_ary_replace() rename:

http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/array.c?r1=371&r2=372#l482

Some time in between 1.6.8 and 1.8.0, rb_ary_replace() was renamed to
rb_ary_update():

http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/array.c?r1=1356&r2=1355&pathrev=1356#l544

This was used in 1.8.0 and 1.8.1.  In 1.8.2 function was renamed to
current rb_ary_splice():

http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/array.c?r1=7306&r2=7305&pathrev=7306#l1074
Comment 15 Tomas Hoger 2008-07-01 02:58:55 EDT
*** Bug 451835 has been marked as a duplicate of this bug. ***

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