Skip to content
Snippets Groups Projects
  1. Aug 11, 2023
    • Micah Elizabeth Scott's avatar
      hashx: Fix rare compiler output overflow on aarch64 · a94ce252
      Micah Elizabeth Scott authored
      
      This is a fix for a very rare buffer overflow in hashx, specific to the
      dynamic compiler on aarch64 platforms.
      
      In practice this issue is extremely unlikely to hit randomly, and it's
      only been seen in unit tests that supply unusual mock PRNG output to the
      program generator. My best attempt at estimating the probability of
      hitting the overflow randomly is about 10^-23. Crafting an input with
      the intent to overflow can be done only as fast as an exhaustive search,
      so long as Blake2B is unbroken.
      
      The root cause is that hashx writes assembly code without any length
      checks, and it uses an estimated size rather than an absolute maximum
      size to allocate the buffer for compiled code. Some instructions are
      much longer than others, especially on aarch64.
      
      The length of the overflow is nearly 300 bytes in the worst synthetic
      test cases I've developed so far. Overflow occurs during hashx_make(),
      and the subsequent hashx_exec() will always SIGSEGV as the written code
      crosses outside the region that's been marked executable. In typical use,
      hashx_exec() is called immediately after hashx_make().
      
      This fix increases the buffer size from 1 page to 2 pages on aarch64,
      adds an analysis of the compiled code size, and adds runtime checks so we
      can gracefully fail on overflow. It also adds a unit test (written in
      Rust) that includes a PRNG sequence exercising the overflow. Without
      this patch the unit test shows a SIGSEGV on aarch64, with this patch it
      runs successfully and matches interpreter output.
      
      Signed-off-by: default avatarMicah Elizabeth Scott <beth@torproject.org>
      a94ce252
  2. Aug 04, 2023
  3. Aug 02, 2023
  4. Aug 01, 2023
  5. Jul 31, 2023
  6. Jul 29, 2023
  7. Jul 26, 2023
  8. Jul 24, 2023
  9. Jul 20, 2023
  10. Jul 17, 2023
Loading