DoS Vulnerability in Ruby

Posted by michael June 10, 2009 @ 12:01 AM

A Denial of Service vulnerability has been found and fixed in ruby. The vulnerability is due to the BigDecimal method mishandling certain large input values and can cause the interpreter to crash. This could be used by an attacker to crash any ruby program which creates BigDecimal objects based on user input, including almost every Rails application. This vulnerability has been assigned the CVE name CVE-2009-1904.

For upgrade instructions and information on affected ruby versions please see the ruby security team’s announcement.

All users are advised to upgrade their ruby installations immediately to avoid this problem. In the event that you are unable to upgrade your ruby installation, or are using an out-of-maintenance ruby version, there is a workaround available on github. You can either install it as a gem, or simply copy the file bigdecimal-segfault-fix.rb into config/initializers of your rails application.

NOTE: this workaround breaks valid formats supported by BigDecimal, users should not rely on this fix for an extended period of time but should instead immediately begin planning a migration to a supported ruby release.

The upcoming Rails 2.3.3 release will include some minor mitigating changes to reduce some potential attack vectors for this vulnerability. However these mitigations will not close every potential method of attack and users should still upgrade their ruby installation as soon as possible.

Thanks to Jose Fernández for reporting the vulnerability to the rails security team, and to the ruby security team for confirming the nature of the bug and handling the release process.

17 comments

Comments

  1. Eric Davis on 10 Jun 00:11:

    Thank you for the workaround. It looks simple enough to protect some applications while I can upgrade Ruby.

  2. Aaron on 10 Jun 00:22:

    what would be the name of the gem to install for this? Sorry for the newb question.

  3. Koz on 10 Jun 00:30:

    The installation instructions are documented on the github page.

  4. sensei on 10 Jun 04:48:

    Do you mean the BigDecimal class?

  5. rmx on 10 Jun 07:01:

    DoS! Oh noes! Ruby has a ton.. have a free one on the house. Works on 1.8 and 1.9. Feel free to freak out about it and get a CVE.

    ruby-1.9$ ./ruby -e ‘[].pack(”@#{2**31}”)’ -e:1: [BUG] Segmentation fault ruby 1.9.2dev (2009-06-10 trunk 23660) [i686-linux]

  6. Hongli Lai on 10 Jun 09:47:

    @rmx: Your example code does not result in a crash on REE 20090610.

  7. Chris Heald on 10 Jun 10:17:

    @rmx: Sure, that’ll segfault, but you’ll have to produce a means to exploit that via a public webserver before I’ll be convinced that it’s a DoS vector.

  8. Mark on 10 Jun 10:35:

    and what is with the win Version?

    Is the project dead? since last year there are not updates.

  9. rick on 10 Jun 16:05:

    sensei: the vulnerability is in the BigDecimal method, check the workaround code. I was confused too.

  10. Dee Zsombor on 10 Jun 18:19:

    Beware the ruby version recommended here will yield true on the

    BigDecimal(“10.03”).to_f == 10.3

    expression. This will effectively break a long list of rails helpers. Add this to your rails project to fix:

    if BigDecimal(“10.03”).to_f != 10.03 class BigDecimal def to_f self.to_s.to_f end end end

    Or wait till they release a proper one … more haste less speed.

  11. Bob Aman on 11 Jun 00:37:

    My favorite segfault is in Ruby 1.8.7 patchlevel 72:

    loop &:p

    I used it to crash the @rubx twitter bot.

  12. Real Time on 11 Jun 05:26:

    I really enjoy Ruby 1.8.7 myself. I highly recommend that version.

  13. Jose on 11 Jun 14:34:

    @rmx:

    I don’t know what you’re talking about.

    I just tried your example on Ruby 1.8.6 and 1.9.1 and it didn’t break anything.

  14. Koz on 16 Jun 10:27:

    Folks, don’t go feeding the trolls ;)

  15. www.doibizworld.com on 03 Jul 02:16:

    http://weblog.rubyonrails.org/2009/6/12/community-highlights-ruby-heroes/comments/25419#comment-25419

  16. www.doibizworld.com on 03 Jul 02:17:

    have you still distressed yourself about the right products filling at the price?Just try www.dobizworld.com to make your successful career

  17. markn on 07 Jul 05:35:

    I’m just curious… How would the DoS attack be acheaved on a rails app? Is there some way to submit something in say a form that would cause a segment fault?