Bug 451821 (CVE-2008-2725)

Summary: CVE-2008-2725 ruby: integer overflow in rb_ary_splice/update/replace() - REALLOC_N
Product: [Other] Security Response Reporter: Tomas Hoger <thoger>
Component: vulnerabilityAssignee: Red Hat Product Security <security-response-team>
Status: CLOSED ERRATA QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: unspecifiedCC: kreilly, tagoh
Target Milestone: ---Keywords: Security
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
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 06:02:42 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: 451926, 451927, 451928, 451929, 451930, 451931, 452293, 452294, 452295    
Bug Blocks:    
Attachments:
Description Flags
Drew Yao's proposed patch against ruby 1.8.5
none
Drew Yao's proposed patch against ruby 1.9 none

Description Tomas Hoger 2008-06-17 16:54:33 UTC
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 16:55:32 UTC
Created attachment 309637 [details]
Drew Yao's proposed patch against ruby 1.8.5

Comment 2 Tomas Hoger 2008-06-17 16:55:48 UTC
Created attachment 309638 [details]
Drew Yao's proposed patch against ruby 1.9

Comment 5 Tomas Hoger 2008-06-20 18:52:46 UTC
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 11:34:49 UTC
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-25 02:50:38 UTC
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-25 02:52:11 UTC
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 07:10:00 UTC
(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 06:58:55 UTC
*** Bug 451835 has been marked as a duplicate of this bug. ***