Fix a suspected off-by-one error in parseFDEInstructions()#27
Merged
alexey-milovidov merged 2 commits intomasterfrom Jun 23, 2024
Merged
Fix a suspected off-by-one error in parseFDEInstructions()#27alexey-milovidov merged 2 commits intomasterfrom
alexey-milovidov merged 2 commits intomasterfrom
Conversation
This was referenced Jun 14, 2024
Member
Author
Would it be better to maintain our patches as a series of commits on top of upstream, and update by rebasing? |
92d7bd0 to
b2d4e24
Compare
Member
Author
|
It didn't break CI in ClickHouse/ClickHouse#65257 , so I think we should merge this. |
alexey-milovidov
approved these changes
Jun 23, 2024
Member
|
@al13n321 have you considered backporting it? |
This was referenced Jul 22, 2024
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.
We get segfaults in libunwind often, especially on aarch64. From reproducing and investigating ClickHouse/ClickHouse#64915 , the cause of the crash, in that specific instance, is what this PR changes - off-by-one error (?) when determining which unwind info entry's address range covers the current instruction address. Details in the next section.
But this is very suspicious because this is hot code, and not ARM-specific. And there seems to be another bug in how
initialStateis used (it can be used-after-free if a register is saved/loaded on different iterations of the outer loop). I would've expected unwinding to crash or produce garbage much more often if this were really broken. Maybe compilers emit these ranges incorrectly on x86 but correctly on ARM (always or sometimes)? Maybe the code was supposed to add/subtract one somewhere else (but I checked and it doesn't look so)? Maybe I'm reading the wrong standard (.eh_frame vs .debug_frame?), and the two standards are mostly the same but are off-by-one from each other (that would be so weird, but DWARF is weird)? Maybe the off-by-one is much more likely to crash the program on ARM because return address works differently (there'slrregister)? I'm confused.I guess let's run this in CI and see if it super-breaks.
Details:
From https://dwarfstd.org/doc/DWARF5.pdf :
(Notice the '≥', while the code had effectively '>'.)
(The example in Appendix D.6 looks consistent with this understanding as well.)
In this case, the address is 0xbc3b924, CIE and FDE are:
Code is:
Clearly the unwind commands
are supposed to apply when instruction pointer is at bc3b924 (i.e. the
add sp, sp, #0x50has happened, butrethasn't). I stepped through the code and checked that libunwind doesn't apply these commands because of the>.