Skip to content
Memory corruption Disclosed report Advanced CVE-2022-28738

CVE-2022-28738: Double free in Regexp compilation

A bug in Ruby's Regexp compilation meant a crafted regexp source string could cause the same memory to be freed twice.

piao Follow

Originally disclosed on HackerOne

Bounty$4,000 High View original
  • Triaged in 15 hours
  • Fixed in 4 days
  • Paid in 4 days
  • Disclosed after 34 days

Summary by the program

A double-free vulnerability is discovered in Regexp compilation. This vulnerability has been assigned the CVE identifier CVE-2022-28738. We strongly recommend upgrading Ruby.

Details Due to a bug in the Regexp compilation process, creating a Regexp object with a crafted source string could cause the same memory to be freed twice. This is known as a “double free” vulnerability. Note that, in general, it is considered unsafe to create and use a Regexp object generated from untrusted input. In this case, however, following a comprehensive assessment, we treat this issue as a vulnerability.

Please update Ruby to 3.0.4, or 3.1.2.

Affected versions ruby 3.0.3 or prior ruby 3.1.1 or prior Note that ruby 2.6 series and 2.7 series are not affected.

Credits Thanks to piao for discovering this issue.

History Originally published at 2022-04-12 12:00:00 (UTC)

https://www.ruby-lang.org/en/news/2022/04/12/double-free-in-regexp-compilation-cve-2022-28738/

The report

Due to a bug in the Regexp compilation process, creating a Regexp object with a crafted source string could cause the same memory to be freed twice. This is known as a “double free” vulnerability. Note that, in general, it is considered unsafe to create and use a Regexp object generated from untrusted input. In this case, however, following a comprehensive assessment, we treat this issue as a vulnerability.

poc:

ruby -e '/(\\x15\\x17\\xE2\\xF5\\xF5\\xF5\\xC2\\x04\\x08J,\\x00\\xD0\\x00\\x00(?(1)\\xF5\\xF5\\xF5\\xD7\\xF5\\xF5\\xF5\\x87\\x04\\xFA555\\xBEJ,\\x18FF\\x15\\xFF|\\x03\\x01\\x00\\x01\\x00\\x00\\x8F\r|)44\\x00\\x8F\r|)+/m'

Impact

may lead to a RCE attack cooperate with marshal.load

The original report as published on HackerOne, by piao. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely a flaw in the Regexp compiler's memory handling when processing a crafted pattern, causing a buffer to be freed more than once.

Impact

The double free could corrupt memory; the source text does not describe remote code execution.

What the attacker needed

Ruby 3.0.3 or 3.1.1 (or earlier); ability to supply a crafted regexp source

The fix

It was fixed by upgrading Ruby to 3.0.4 or 3.1.2.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a program builds a regular expression (a pattern used to match text) from a string, Ruby compiles it into an internal form. A mistake in that compiler let the same chunk of memory be released twice, which can corrupt the program's memory. Memory corruption like this can sometimes be turned into running an attacker's own code.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by piao

View all

4 more disclosed reports, best first.

More from Internet Bug Bounty

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.