This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Add ROP Protection Instructions for PowerPC
ClosedPublic

Authored by stefanp on Mar 25 2021, 1:32 PM.

Details

Summary

There are four new PowerPC instructions that are introduced in
Power 10. They are hashst, hashchk, hashstp, hashchkp.

These instructions will be used for ROP Protection.
This patch adds the four instructions.

Diff Detail

Event Timeline

stefanp created this revision.Mar 25 2021, 1:32 PM
stefanp requested review of this revision.Mar 25 2021, 1:32 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 25 2021, 1:32 PM
stefanp added reviewers: lei, amyk, Restricted Project.Mar 25 2021, 1:33 PM
amyk accepted this revision as: amyk.Apr 5 2021, 2:58 PM

Overall this LGTM.

llvm/lib/Target/PowerPC/PPCInstr64Bit.td
1536

I believe the hasSideEffects is needed because the instruction may TRAP if the hash does not match the hash stored at the specified address. This is a super minor nit, but maybe it might be better to explicitly say that the flag is needed because of this reason.

The hasSideEffects flag is needed as the instruction may TRAP if ...

I think this is minor though, so if you think it's not needed, you can feel free to disregard this comment.

This revision is now accepted and ready to land.Apr 5 2021, 2:58 PM
nemanjai accepted this revision.Apr 8 2021, 7:00 AM

LGTM.

stefanp updated this revision to Diff 336424.Apr 9 2021, 6:07 AM

Updated comment.

This revision was automatically updated to reflect the committed changes.
hctim added a subscriber: hctim.Apr 9 2021, 12:13 PM

Looks like this patch broke the UBSan buildbot (https://lab.llvm.org/buildbot/#/builders/5/builds/6546), PTAL.

Repro instructions here, copied the UBSan report below for your reference:

FAIL: LLVM :: MC/Disassembler/PowerPC/ppc64-encoding-ISA31.txt (54419 of 75431)
******************** TEST 'LLVM :: MC/Disassembler/PowerPC/ppc64-encoding-ISA31.txt' FAILED ********************
Script:
--
: 'RUN: at line 1';   /b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/bin/llvm-mc --disassemble /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/MC/Disassembler/PowerPC/ppc64-encoding-ISA31.txt -triple powerpc64-unknown-linux-gnu    -mcpu=pwr10 | /b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/bin/FileCheck /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/test/MC/Disassembler/PowerPC/ppc64-encoding-ISA31.txt
--
Exit Code: 1
Command Output (stderr):
--
/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp:290:60: runtime error: left shift of negative value -1
    #0 0x133a4a8 in decodeMemRIHashOperands /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp:290:60
    #1 0x133a4a8 in llvm::MCDisassembler::DecodeStatus llvm::decodeToMCInst<unsigned long>(llvm::MCDisassembler::DecodeStatus, unsigned int, unsigned long, llvm::MCInst&, unsigned long, void const*, bool&) /b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/lib/Target/PowerPC/PPCGenDisassemblerTables.inc:6657:9
    #2 0x1337b3e in llvm::MCDisassembler::DecodeStatus llvm::decodeInstruction<unsigned long>(unsigned char const*, llvm::MCInst&, unsigned long, unsigned long, void const*, llvm::MCSubtargetInfo const&) /b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/lib/Target/PowerPC/PPCGenDisassemblerTables.inc:8119:11
    #3 0xfc69a9 in PrintInsts /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/tools/llvm-mc/Disassembler.cpp:49:16
    #4 0xfc69a9 in llvm::Disassembler::disassemble(llvm::Target const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, llvm::MCSubtargetInfo&, llvm::MCStreamer&, llvm::MemoryBuffer&, llvm::SourceMgr&, llvm::MCContext&, llvm::raw_ostream&, llvm::MCTargetOptions const&) /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/tools/llvm-mc/Disassembler.cpp:196:24
    #5 0xfb7b68 in main /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/tools/llvm-mc/llvm-mc.cpp:559:11
    #6 0x7ff4a60a409a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a)
    #7 0xf9c949 in _start (/b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/bin/llvm-mc+0xf9c949)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp:290:60 in
stefanp reopened this revision.Apr 12 2021, 3:31 AM

Reopening review to investigate the issue.

This revision is now accepted and ready to land.Apr 12 2021, 3:31 AM
stefanp updated this revision to Diff 337695.Apr 15 2021, 3:56 AM

Was able to reproduce the issue that caused the left shift of -1.
Fixed the patch by replacing the shift with a multiply.
Also realized that the type should have been signed and not unsigned.

This revision was automatically updated to reflect the committed changes.