Repository navigation
py/nlraarch64: Fix dangerous use of input register. - #11762
Merged
Merged
Conversation
|
Code size report: |
Codecov Report
@@ Coverage Diff @@
## master #11762 +/- ##
=======================================
Coverage 98.40% 98.40%
=======================================
Files 155 155
Lines 20539 20539
=======================================
Hits 20211 20211
Misses 328 328 |
Contributor
Author
|
I didn't see #11716 before doing this, but it fixes the issue as well. |
Contributor
Author
|
Surprisingly, #11716 actually generates larger code due to saving the clobbered registers at the beginning of the Disassembly of this PR: Disassembly of #11716 |
Member
|
Thank you, this fix is definitely needed. And it's how other native NLR implementations work. |
Starting with 2757acf, the `top` variable in `nlr_jump()` in `nlraarch64.c` was assigned to register `x19` by the compiler. However, the assembly code writes over that register with ldp x19, x20, [%0, micropython#32] since `%0` is now `x19`. This causes the next line ldp lr, x9, [%0, micropython#16] to load the wrong values. To fix the issue, we move the value of the `top` variable from an unknown register to a known register at the beginning of the asm code then only use known/hard-coded registers after that. Fixes issue micropython#11754. Signed-off-by: David Lechner <[email protected]>
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.
Starting with 2757acf, the
topvariable innlr_jump()innlraarch64.cwas assigned to registerx19by the compiler. However, the assembly code writes over that register withsince
%0is nowx19. This causes the next lineto load the wrong values. This lead to a crash when returning from the function since
lrnow contains a bad address.To fix the issue, we move the value of the
topvariable from an unknown register to a known register at the beginning of the asm code then only use known/hard-coded registers after that.Fixes: #11754