llvm.org GIT mirror llvm / b72a3a9
[cfi-verify] Add an interesting unit test where undef search length changes result. Add an interesting unit test, found by changing --search-length-undef from the default. Program handles it correctly but good for ensuring correctness on further changes :) Reviewers: pcc Subscribers: mgorny, llvm-commits, kcc, vlad.tsyrklevich Differential Revision: https://reviews.llvm.org/D38658 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317355 91177308-0d34-0410-b5e6-96231b3b80d8 Mitch Phillips 1 year, 9 months ago
1 changed file(s) with 53 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
649649 0x0f, 0x0b, // 22: ud2
650650 },
651651 0xDEADBEEF);
652 uint64_t PrevSearchLengthForUndef = SearchLengthForUndef;
653 SearchLengthForUndef = 5;
652654 EXPECT_FALSE(Analysis.isIndirectInstructionCFIProtected(0xDEADBEEF + 9));
655 SearchLengthForUndef = PrevSearchLengthForUndef;
656 }
657
658 TEST_F(BasicFileAnalysisTest, UndefSearchLengthOneTest) {
659 Analysis.parseSectionContents(
660 {
661 0x77, 0x0d, // 0x688118: ja 0x688127 [+12]
662 0x48, 0x89, 0xdf, // 0x68811a: mov %rbx, %rdi
663 0xff, 0xd0, // 0x68811d: callq *%rax
664 0x48, 0x89, 0xdf, // 0x68811f: mov %rbx, %rdi
665 0xe8, 0x09, 0x00, 0x00, 0x00, // 0x688122: callq 0x688130
666 0x0f, 0x0b, // 0x688127: ud2
667 },
668 0x688118);
669 uint64_t PrevSearchLengthForUndef = SearchLengthForUndef;
670 SearchLengthForUndef = 1;
671 EXPECT_TRUE(Analysis.isIndirectInstructionCFIProtected(0x68811d));
672 SearchLengthForUndef = PrevSearchLengthForUndef;
673 }
674
675 TEST_F(BasicFileAnalysisTest, UndefSearchLengthOneTestFarAway) {
676 Analysis.parseSectionContents(
677 {
678 0x74, 0x73, // 0x7759eb: je 0x775a60
679 0xe9, 0x1c, 0x04, 0x00, 0x00, 0x00, // 0x7759ed: jmpq 0x775e0e
680 },
681 0x7759eb);
682
683 Analysis.parseSectionContents(
684 {
685 0x0f, 0x85, 0xb2, 0x03, 0x00, 0x00, // 0x775a56: jne 0x775e0e
686 0x48, 0x83, 0xc3, 0xf4, // 0x775a5c: add $0xfffffffffffffff4,%rbx
687 0x48, 0x8b, 0x7c, 0x24, 0x10, // 0x775a60: mov 0x10(%rsp),%rdi
688 0x48, 0x89, 0xde, // 0x775a65: mov %rbx,%rsi
689 0xff, 0xd1, // 0x775a68: callq *%rcx
690 },
691 0x775a56);
692
693 Analysis.parseSectionContents(
694 {
695 0x0f, 0x0b, // 0x775e0e: ud2
696 },
697 0x775e0e);
698 uint64_t PrevSearchLengthForUndef = SearchLengthForUndef;
699 SearchLengthForUndef = 1;
700 EXPECT_FALSE(Analysis.isIndirectInstructionCFIProtected(0x775a68));
701 SearchLengthForUndef = 2;
702 EXPECT_TRUE(Analysis.isIndirectInstructionCFIProtected(0x775a68));
703 SearchLengthForUndef = 3;
704 EXPECT_TRUE(Analysis.isIndirectInstructionCFIProtected(0x775a68));
705 SearchLengthForUndef = PrevSearchLengthForUndef;
653706 }
654707
655708 } // anonymous namespace