Stack-buffer-overflow in __bid128_from_string when parsing long $numberDecimal field

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Critical - P2
    • None
    • Affects Version/s: 8.0.9
    • Component/s: None
    • Environment:
    • Server Programmability
    • ALL
    • Hide

      ./build/655ea29a/mongo/bson/fromjson_fuzzer -runs=1 /mongo/src/mongo/bson/2_fromjson/crash-d9337b38f55bc142b415fffeec9899fcd09f3dd7

      Show
      ./build/655ea29a/mongo/bson/fromjson_fuzzer -runs=1 /mongo/src/mongo/bson/2_fromjson/crash-d9337b38f55bc142b415fffeec9899fcd09f3dd7
    • Programmability 2023-03-30
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Hello! During exploring mongo r8.0.9 I found some fuzzing tests in master branch. Fromjson fuzzer is one of them, which I backported to version r8.0.9. ASAN detected error in 3rd party library code (Intel RDF Math Library). Its'not part of MongoDB, but how about to add some fixes? 

      ASAN error description:

      When parsing a JSON document containing a $numberDecimal field with a numeric literal longer than 100 characters, the fromjson function initiates a call chain leading to __bid128_from_string in the third-party Intel RDF Math Library (bid128_string.c). In this function, a buffer char buffer[100] is allocated on the stack (line 295), but when processing a long number, the loop on line 632 accesses this buffer at an index greater than 99 (buffer[i] > '0'), resulting in a stack-buffer-overflow. This crash is reproducible on a 308-byte test case and can be used by an attacker to perform a denial of service (DoS). The expected behavior is correct error handling or rejection of an overly long number without crashing the server. The issue was discovered using fuzzing (libfuzzer + ASAN) and requires a fix in the Decimal128 parsing code.

      I explored this part of 3rd party code in mongodb master branch and found that error is actual for latest version too. If you interesting in patching, I can open pr with possible fix

        1. crash-d9337b38f55bc142b415fffeec9899fcd09f3dd7
          0.3 kB
          Дмитрий Мидуков
        2. crash_debug.log
          16 kB
          Дмитрий Мидуков
        3. fromjson_fuzzer_crash.log
          1.67 MB
          Дмитрий Мидуков
        4. fromjson_fuzzer.cpp
          2 kB
          Дмитрий Мидуков

            Assignee:
            Billy Donahue
            Reporter:
            Дмитрий Мидуков
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: