This is an archive of the discontinued LLVM Phabricator instance.

[NFC][AMDGPU] Guard the custom fixups kind array from invalid access
ClosedPublic

Authored by gmirazchiyski on Aug 24 2023, 4:43 AM.

Details

Summary

Verify the possibility of accidental passing of an invalid MCFixupKind value which can cause an invalid access in the array, and guard from it via assert.

Diff Detail

Event Timeline

gmirazchiyski created this revision.Aug 24 2023, 4:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 24 2023, 4:43 AM
gmirazchiyski requested review of this revision.Aug 24 2023, 4:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 24 2023, 4:43 AM
gmirazchiyski edited the summary of this revision. (Show Details)Aug 24 2023, 4:45 AM
arsenm added inline comments.Aug 24 2023, 5:21 AM
llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp
188

Isn’t this equivalent to the previous bounds check?

gmirazchiyski added inline comments.Aug 24 2023, 7:07 AM
llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUAsmBackend.cpp
188

Thank you for checking this @arsenm ! I don't think it is or at least see it as exactly the same check.

Kind < 128 (FirstTargetFixupKind) -> returns FK_NONE which I think it's no-op here
Kind >= 256 (FirstLiteralRelocationKind) -> returns the base getFixupKindInfo(Kind)
Those bounds checks are fair and needed, but for anything in the range of [128;255], Kind is allowed, and anything above 128 will be invalid.

Yes, obviously only the AMDGPU::fixup_si_sopp_br fixup kind which is valid will be used for AMDGPU but the assert is here as a security guard to the Infos array in case of misuse.

I can agree to the point this can do and is safe without the assert, but from the outside it looks like a security concern, which we will only know it will not occur after we dig into the logic.
Moreover, other backends seem to similarly assert too.

A friendly ping. Thanks! :)

arsenm accepted this revision.Aug 29 2023, 2:52 PM
This revision is now accepted and ready to land.Aug 29 2023, 2:52 PM
This revision was landed with ongoing or failed builds.Aug 30 2023, 3:13 AM
This revision was automatically updated to reflect the committed changes.