-
Notifications
You must be signed in to change notification settings - Fork 333
fix verifier panic and interpreter overflow #137
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
fix verifier panic and interpreter overflow #137
Conversation
Signed-off-by: Echo8377 <[email protected]>
bef13b0 to
763b582
Compare
src/interpreter.rs
Outdated
| // Use checked arithmetic to prevent integer overflow | ||
| let offset = insn.imm as isize; | ||
| if offset < 0 { | ||
| let abs_offset = (-offset) as usize; | ||
| if abs_offset > insn_ptr { | ||
| Err(Error::other(format!( | ||
| "Error: call offset underflow (insn #{})", | ||
| insn_ptr - 1 | ||
| )))?; | ||
| } | ||
| insn_ptr -= abs_offset; | ||
| } else { | ||
| insn_ptr = insn_ptr.checked_add(offset as usize).ok_or_else(|| { | ||
| Error::other(format!( | ||
| "Error: call offset overflow (insn #{})", | ||
| insn_ptr - 1 | ||
| )) | ||
| })?; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we work with immediate values, we know the value at verification time, and we shouldn't be doing these checks at runtime, we should do it in src/verifier.rs instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we work with immediate values, we know the value at verification time, and we shouldn't be doing these checks at runtime, we should do it in
src/verifier.rsinstead.
You're right about avoiding runtime checks. I checked verifier.rs and realized your original code was already solid and handles these bounds correctly. So I've removed the redundant check from interpreter.rs to restore the efficient behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked verifier.rs and realized your original code was already solid and handles these bounds correctly
I don't think it does, I tried your reproducer yesterday and the code in the verifier doesn't prevent the overflow in debug mode. We should probably reject the program in that case. But I can look into it at some point as well, I didn't have time yesterday.
Signed-off-by: Echo8377 <[email protected]>
qmonnet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
No description provided.