@@ -232,12 +232,11 @@ struct SrcState {
232
232
bool operator !=(const SrcState &RHS) const { return !((*this ) == RHS); }
233
233
};
234
234
235
- static void
236
- printLastInsts (raw_ostream &OS,
237
- ArrayRef<SmallPtrSet<const MCInst *, 4 >> LastInstWritingReg) {
235
+ static void printInstsShort (raw_ostream &OS,
236
+ ArrayRef<SmallPtrSet<const MCInst *, 4 >> Insts) {
238
237
OS << " Insts: " ;
239
- for (unsigned I = 0 ; I < LastInstWritingReg .size (); ++I) {
240
- auto &Set = LastInstWritingReg [I];
238
+ for (unsigned I = 0 ; I < Insts .size (); ++I) {
239
+ auto &Set = Insts [I];
241
240
OS << " [" << I << " ](" ;
242
241
for (const MCInst *MCInstP : Set)
243
242
OS << MCInstP << " " ;
@@ -252,7 +251,7 @@ raw_ostream &operator<<(raw_ostream &OS, const SrcState &S) {
252
251
} else {
253
252
OS << " SafeToDerefRegs: " << S.SafeToDerefRegs << " , " ;
254
253
OS << " TrustedRegs: " << S.TrustedRegs << " , " ;
255
- printLastInsts (OS, S.LastInstWritingReg );
254
+ printInstsShort (OS, S.LastInstWritingReg );
256
255
}
257
256
OS << " >" ;
258
257
return OS;
@@ -281,7 +280,7 @@ void SrcStatePrinter::print(raw_ostream &OS, const SrcState &S) const {
281
280
OS << " , TrustedRegs: " ;
282
281
RegStatePrinter.print (OS, S.TrustedRegs );
283
282
OS << " , " ;
284
- printLastInsts (OS, S.LastInstWritingReg );
283
+ printInstsShort (OS, S.LastInstWritingReg );
285
284
}
286
285
OS << " >" ;
287
286
}
@@ -752,7 +751,7 @@ SrcSafetyAnalysis::create(BinaryFunction &BF,
752
751
struct DstState {
753
752
// / The set of registers whose values cannot be inspected by an attacker in
754
753
// / a way usable as an authentication oracle. The results of authentication
755
- // / instructions should be written to such registers.
754
+ // / instructions should only be written to such registers.
756
755
BitVector CannotEscapeUnchecked;
757
756
758
757
std::vector<SmallPtrSet<const MCInst *, 4 >> FirstInstLeakingReg;
@@ -770,6 +769,9 @@ struct DstState {
770
769
return (*this = StateIn);
771
770
772
771
CannotEscapeUnchecked &= StateIn.CannotEscapeUnchecked ;
772
+ for (unsigned I = 0 ; I < FirstInstLeakingReg.size (); ++I)
773
+ for (const MCInst *J : StateIn.FirstInstLeakingReg [I])
774
+ FirstInstLeakingReg[I].insert (J);
773
775
return *this ;
774
776
}
775
777
@@ -778,7 +780,8 @@ struct DstState {
778
780
bool empty () const { return CannotEscapeUnchecked.empty (); }
779
781
780
782
bool operator ==(const DstState &RHS) const {
781
- return CannotEscapeUnchecked == RHS.CannotEscapeUnchecked ;
783
+ return CannotEscapeUnchecked == RHS.CannotEscapeUnchecked &&
784
+ FirstInstLeakingReg == RHS.FirstInstLeakingReg ;
782
785
}
783
786
bool operator !=(const DstState &RHS) const { return !((*this ) == RHS); }
784
787
};
@@ -788,7 +791,8 @@ raw_ostream &operator<<(raw_ostream &OS, const DstState &S) {
788
791
if (S.empty ()) {
789
792
OS << " empty" ;
790
793
} else {
791
- OS << " CannotEscapeUnchecked: " << S.CannotEscapeUnchecked ;
794
+ OS << " CannotEscapeUnchecked: " << S.CannotEscapeUnchecked << " , " ;
795
+ printInstsShort (OS, S.FirstInstLeakingReg );
792
796
}
793
797
OS << " >" ;
794
798
return OS;
@@ -808,10 +812,13 @@ void DstStatePrinter::print(raw_ostream &OS, const DstState &S) const {
808
812
OS << " dst-state<" ;
809
813
if (S.empty ()) {
810
814
assert (S.CannotEscapeUnchecked .empty ());
815
+ assert (S.FirstInstLeakingReg .empty ());
811
816
OS << " empty" ;
812
817
} else {
813
818
OS << " CannotEscapeUnchecked: " ;
814
819
RegStatePrinter.print (OS, S.CannotEscapeUnchecked );
820
+ OS << " , " ;
821
+ printInstsShort (OS, S.FirstInstLeakingReg );
815
822
}
816
823
OS << " >" ;
817
824
}
@@ -841,6 +848,7 @@ class DstSafetyAnalysis {
841
848
const unsigned NumRegs;
842
849
843
850
const TrackedRegisters RegsToTrackInstsFor;
851
+
844
852
// / Stores information about the detected instruction sequences emitted to
845
853
// / check an authenticated pointer. Specifically, if such sequence is detected
846
854
// / in a basic block, it maps the first instruction of that sequence to the
@@ -897,7 +905,6 @@ class DstSafetyAnalysis {
897
905
const BitVector &LeakedRegs,
898
906
const DstState &Cur) const {
899
907
SmallVector<MCPhysReg> Regs;
900
- const MCPhysReg NoReg = BC.MIB ->getNoRegister ();
901
908
902
909
// A pointer can be checked, or
903
910
if (auto CheckedReg =
@@ -911,7 +918,7 @@ class DstSafetyAnalysis {
911
918
bool IsAuthenticated;
912
919
MCPhysReg BranchDestReg =
913
920
BC.MIB ->getRegUsedAsIndirectBranchDest (Inst, IsAuthenticated);
914
- assert (BranchDestReg != NoReg );
921
+ assert (BranchDestReg != BC. MIB -> getNoRegister () );
915
922
if (!IsAuthenticated)
916
923
Regs.push_back (BranchDestReg);
917
924
}
0 commit comments