Skip to content

WTF::BitSet<2048ul, unsigned long>::set(unsigned long) Out-of-Bounds #1389

Open
@usr1224

Description

@usr1224

Credit : Sunghoon Jang, Jeonil Ji

Escargot

  • OS: Ubuntu 18.04

Describe the bug
Out-of-Bounds write

Test case
Test code to reproduce the behavior:
set.txt
rename .txt -> .js before use

Backtrace
set1

Analysis

set2 third_party/yarr/BitSet.h
  • A SIGABRT occurred in this code.
set3
  • After building Escargot in debug mode, I confirmed that an out-of-bounds (OOB) write occurred while accessing index 67108737.
set4 third_party/yarr/BitSet.h
  • The result of n / wordSize is 67108737, leading to OOB access at bits[67108737].
    • 67108737 = 0x3ffff81
  • To check the value of n, I examined backtrace#1, where the set() function is called.
set5 third_party/yarr/YarrPattern.cpp
  • I confirmed that the set() function uses ch - chunkLo as an argument.
set6 set7
  • The value of n = ch - chunkLo
  • A negative value (0xffffe055) was passed to n.
set8

third_party/yarr/BitSet.h:150 asm

  • I confirmed that the argument values are being pushed onto the stack inside the set function.
  • The value of n (0xffffe055) is stored at rbp-0x10.
set9

third_party/yarr/BitSet.h

  • I verified that n / wordSize is being used as the index of bits.
set10
  • Since wordSize = 2^6, it performs a shr 6 operation internally.
set11
  • The value of rax contains n (0xffffe055).
  • After the n / wordSize operation, the result 0x3ffff81 is stored in rdx.
  • Then, an attempt is made to access bits[0x3ffff81], resulting in the OOB.

Credit : Sunghoon Jang, Jeonil Ji

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions