Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overflow check in codecopy #444

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions evm_arithmetization/src/cpu/kernel/asm/memory/syscalls.asm
Original file line number Diff line number Diff line change
Expand Up @@ -316,20 +316,20 @@ mcopy_empty:

PUSH $segment SWAP1
// stack: total_size, segment, src_ctx, kexit_info, dest_offset, offset, size
DUP1 DUP8 DUP8 ADD
DUP1 DUP8 DUP8 %add_or_fault
// stack: offset + size, total_size, total_size, segment, src_ctx, kexit_info, dest_offset, offset, size
LT %jumpi(codecopy_within_bounds)

// stack: total_size, segment, src_ctx, kexit_info, dest_offset, offset, size
DUP7 DUP7 ADD
DUP7 DUP7 ADD // We already checked for overflow.
// stack: offset + size, total_size, segment, src_ctx, kexit_info, dest_offset, offset, size
SUB // extra_size = offset + size - total_size
// stack: extra_size, segment, src_ctx, kexit_info, dest_offset, offset, size
DUP1 DUP8 SUB
// stack: copy_size = size - extra_size, extra_size, segment, src_ctx, kexit_info, dest_offset, offset, size

// Compute the new dest_offset after actual copies, at which we will start padding with zeroes.
DUP1 DUP7 ADD
DUP1 DUP7 ADD // We already checked for overflow.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(the check is done prior entering codecopy_after_checks)

// stack: new_dest_offset, copy_size, extra_size, segment, src_ctx, kexit_info, dest_offset, offset, size

GET_CONTEXT
Expand Down
Loading