Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
usr1224 opened this issue Sep 13, 2024 · 0 comments
Open

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

usr1224 opened this issue Sep 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@usr1224
Copy link

usr1224 commented Sep 13, 2024

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

@usr1224 usr1224 added the bug Something isn't working label Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant