Do not trust argument_end to select the shared frame layout (#5302) - #5310
Open
1820893135-pixel wants to merge 1 commit into
Open
1820893135-pixel wants to merge 1 commit into
1820893135-pixel wants to merge 1 commit into
Conversation
vm_init_exec() decided whether shared_p carries an argument list by
looking at argument_end, a field taken from the bytecode header, and then
cast shared_p to vm_frame_ctx_shared_args_t:
if (argument_end > 0)
{
JERRY_ASSERT (shared_p->status_flags & VM_FRAME_CTX_SHARED_HAS_ARG_LIST);
const ecma_value_t *arg_list_p = ((vm_frame_ctx_shared_args_t *) shared_p)->arg_list_p;
arg_list_len = ((vm_frame_ctx_shared_args_t *) shared_p)->arg_list_len;
The assert is compiled out with NDEBUG, and vm_run_global() only ever
passes a plain vm_frame_ctx_shared_t, so a snapshot whose bytecode
declares arguments makes this read go past the 24-byte shared struct:
==ERROR: AddressSanitizer: stack-buffer-overflow
READ of size 8
#0 vm_init_exec vm.c:5190
jerryscript-project#1 vm_run vm.c:5330
jerryscript-project#2 vm_run_global vm.c:286
jerryscript-project#3 jerry_exec_snapshot jerry-snapshot.c:1024
[32, 56) 'shared' (line 272) <== Memory access at offset 56 overflows
The layout is described by VM_FRAME_CTX_SHARED_HAS_ARG_LIST, which is set
by the callers that actually build the args variant, so test that flag
instead of argument_end. A snapshot that cannot provide an argument list
now leaves the registers undefined, exactly as it does when argument_end
is zero.
JerryScript-DCO-1.0-Signed-off-by: 1820893135-pixel <1820893135@qq.com>
This was referenced Sep 23, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
vm_init_exec()decides whethershared_pcarries an argument list by lookingat
argument_end, a field taken from the bytecode header, and then castsshared_ptovm_frame_ctx_shared_args_t(vm.c:5190):The assert is compiled out with
NDEBUG, andvm_run_global()only ever passesa plain
vm_frame_ctx_shared_t(24 bytes), so a snapshot whose bytecode declaresarguments makes this read go past the struct:
A 122-byte malformed snapshot is enough to trigger it. The read lands 8 bytes
past a stack object that also holds the frame's saved pointers, so the adjacent
arg_list_lenload is the same defect.Fix
The layout is described by
VM_FRAME_CTX_SHARED_HAS_ARG_LIST, which is set bythe callers that actually build the args variant
(
ecma-function-object.c:1088), so test that flag rather than the untrustedargument_end:A snapshot that cannot provide an argument list now leaves the registers
undefined, exactly as it does when
argument_endis zero.Fixes #5302.