Repository navigation
Fix vtable slot bounds checking for refined receiver types - #24069
Conversation
|
@vijaysun-omr @mpirvu requesting review |
ab04eba to
cda5193
Compare
When receiver types are refined during compilation (e.g., from an interface to a concrete implementor), the vtable slot offset computed against the original resolved class may fall outside the bounds of the refined class's vtable. This can lead to reading arbitrary memory values as J9Method pointers, causing crashes or incorrect devirtualization. This commit adds vtable slot validation in three critical locations: 1. TR_PersistentCHTable::findSingleAbstractImplementer - Added bounds check 2. TR_J9VMBase::getResolvedVirtualMethod - Added bounds check 3. TR_J9VirtualCallSite::findCallSiteForAbstractClass - Added name/signature verification This fixes the root cause of a class of failures observed with invalid vtable slot indices being used post-refinement, and we run into such issues in the scenario described below: - A virtual call is resolved against one class (e.g., interface implementor A) - The receiver type is refined to a different class (e.g., implementor B) - The vtable slot from class A is used to index into class B's vtable - Class B's vtable may be smaller or have different layout, causing OOB access Signed-off-by: Nazim Bhuiyan <nubhuiyan@ibm.com>
mpirvu
left a comment
There was a problem hiding this comment.
LGTM. I have one small question (inline).
|
jenkins test sanity,extended all jdk25 |
Just so I understand this comment, the case being talked about here is that the call was an interface call |
It was never an invokeinterface that got converted. It is an invokevirtual call from the start, whose target is an interface method |
|
jdk25 ppc64le linux sanity.openjdk failure: It is a known issue: #23435 jdk25 x86-64 linux sanity.functional failure: A similar known issue: #14706 |
|
Still trying to understand here...
If the bytecodes said |
|
The bytecode says Also see the following: openj9/runtime/compiler/optimizer/J9Inliner.cpp Lines 505 to 512 in a5901da |
|
jdk25 x86-64 mac sanity.openjdk was aborted due to timeout running test |
|
I started a 1x grinder for mac just for the failing testList_0 here: https://openj9-jenkins.osuosl.org/job/Grinder/5220/ |
|
Thanks, that comment you pasted seems to describe something very similar to your case. Having said that, it seems that the only reason |
Value profiling is not why |
|
Okay, interesting (and subtle) issue with arg propagation. I wonder if another fix could have been if we did a check on the method in the call Just out of curiosity, could nothing go wrong if |
I suppose that would work too. However, I went with the bounds checking approach because I wanted to minimize the impact that the fix would have. It would terminate class walk when the vtable index is obviously wrong, while the otherwise correct vtable accesses would be still allowed. This seemed like the safer approach to me.
I did wonder this as well, which was the motivation behind the name and signature matching that's included in the fix. |
|
Okay thanks, that clarifies the thought process much more. While the name/signature match help in being "more correct" (if there is such a thing), I wonder if the refined class ( |
My understanding is that this sort of situation is only possible when the classes involved are all related in some way. The scenario you described, from what I understand, would mean that it's possible for I.foo to have its receiver refined to a completely incompatible type. I'm not sure if there is a way for that to happen. If we somehow did end up in that situation, would peeking ILGen ending up with the wrong method in a not-taken path affect the outcome of the compilation? Perhaps we could design some tests to try and figure out what happens. It is possible that this sort of issue was happening for as long as peeking + IAP has been around, but hidden from us because the wrong vtable offset was within bounds of the unintended receiver's vtable, so flying completely under the radar. |
|
The reason I was thinking of the "completely incompatible type" case was from considering a scenario like this one that you mentioned earlier
In such a scenario, is it not possible that one has some An instanceof check at compile time in the case of any call that has an interface |
|
@vijaysun-omr I agree that this problem is possible. This will require some additional investigation that goes beyond what this fix is addressing, i.e., validation of accesses into the vtable entries, where the classes involved are related, preventing crashes during JIT compilation. Do you think compatibility checks can be worked on in a follow-up PR, or does it make more sense to be part of this one? |
|
Thanks Nazim. I don't have an issue with that follow-on PR potentially changing the logic delivered in this PR, e.g. maybe an instanceof test at the right place(s) may eliminate the need for a bounds check. But we can cross that bridge when we get to it, i.e. this change itself is fixing a set of problems I can approve it with the understanding that things will be re-visited as part of the follow-on work. |
|
I have approved this PR, thanks |
|
The grinder on mac was successful. Since none of the test failures are related to this PR I am going to merge it. |
|
@nbhuiyan Please port this PR to 0.60.0 release branch. Thanks |
When receiver types are refined during compilation (e.g., from an interface to a concrete implementor), the vtable slot offset computed against the original resolved class may fall outside the bounds of the refined class's vtable. This can lead to reading arbitrary memory values as J9Method pointers, causing crashes or incorrect devirtualization.
This commit adds vtable slot validation in three critical locations:
This fixes the root cause of a class of failures observed with invalid vtable slot indices being used post-refinement, and we run into such issues in the scenario described below:
Issue: #24018, #24009