Skip to content
  • NARUSE, Yui's avatar
    ce6863a0
    merge revision(s) 18573b8d: [Backport #20178] (#9822) · ce6863a0
    NARUSE, Yui authored
    
    
    Avoid reading unused lvars in Primitive.cexpr
    
    	Previously on builds with optimizations disabled, this could result in
    	an out of bounds read. When we had all of:
    	* built with -O0
    	* Leaf builtin
    	* Primitive.mandatory_only
    	* "no args builtin", called by vm_call_single_noarg_inline_builti
    	* The stack is escaped to the heap via binding or a proc
    
    	This is because mk_builtin_loader generated reads for all locals
    	regardless of whether they were used and in the case we generated a
    	mandatory_only iseq that would include more variables than were actually
    	available.
    
    	On optimized builds, the invalid accesses would be optimized away, and
    	this also was often unnoticed as the invalid access would just hit
    	another part of the stack unless it had been escaped to the heap.
    
    	The fix here is imperfect, as this could have false positives, but since
    	Primitive.cexpr! is only available within the cruby codebase itself
    	that's probably fine as a proper fix would be much more challenging (the
    	only false positives we found were in rjit.rb).
    
    	Fixes [Bug #20178]
    
    Co-authored-by: default avatarAdam Hess <HParker@github.com>
    	---
    	 bootstraptest/test_method.rb | 9 +++++++++
    	 tool/mk_builtin_loader.rb    | 6 ++++++
    	 2 files changed, 15 insertions(+)
    ce6863a0
    merge revision(s) 18573b8d: [Backport #20178] (#9822)
    NARUSE, Yui authored
    
    
    Avoid reading unused lvars in Primitive.cexpr
    
    	Previously on builds with optimizations disabled, this could result in
    	an out of bounds read. When we had all of:
    	* built with -O0
    	* Leaf builtin
    	* Primitive.mandatory_only
    	* "no args builtin", called by vm_call_single_noarg_inline_builti
    	* The stack is escaped to the heap via binding or a proc
    
    	This is because mk_builtin_loader generated reads for all locals
    	regardless of whether they were used and in the case we generated a
    	mandatory_only iseq that would include more variables than were actually
    	available.
    
    	On optimized builds, the invalid accesses would be optimized away, and
    	this also was often unnoticed as the invalid access would just hit
    	another part of the stack unless it had been escaped to the heap.
    
    	The fix here is imperfect, as this could have false positives, but since
    	Primitive.cexpr! is only available within the cruby codebase itself
    	that's probably fine as a proper fix would be much more challenging (the
    	only false positives we found were in rjit.rb).
    
    	Fixes [Bug #20178]
    
    Co-authored-by: default avatarAdam Hess <HParker@github.com>
    	---
    	 bootstraptest/test_method.rb | 9 +++++++++
    	 tool/mk_builtin_loader.rb    | 6 ++++++
    	 2 files changed, 15 insertions(+)
Loading