From ff9ad9f3414fd8f29b6a6aed32b2cc5d7aa6cfd1 Mon Sep 17 00:00:00 2001
From: Jason Hiser <jdhiser@gmail.com>
Date: Sun, 16 Dec 2018 20:08:46 -0500
Subject: [PATCH] added self validate to cfi

Former-commit-id: 95fa05f84f37d381f79abf65df62d79c0d81c974
---
 tools/selective_cfi/scfi_instr.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tools/selective_cfi/scfi_instr.cpp b/tools/selective_cfi/scfi_instr.cpp
index b9f2dc20e..69ef7c6b8 100644
--- a/tools/selective_cfi/scfi_instr.cpp
+++ b/tools/selective_cfi/scfi_instr.cpp
@@ -327,9 +327,15 @@ bool SCFI_Instrument::mark_targets()
                     }
                 } 
 	}
+
 	cout<<"# ATTRIBUTE Selective_Control_Flow_Integrity::ind_targets_found="<<std::dec<<ind_targets<<endl;
 	cout<<"# ATTRIBUTE Selective_Control_Flow_Integrity::targets_found="<<std::dec<<targets<<endl;
 	cout<<"# ATTRIBUTE Selective_Control_Flow_Integrity::exe_nonce_targets_found="<<std::dec<<exe_nonce_targets<<endl;
+
+	assert(getenv("SELF_VALIDATE")==nullptr || ind_targets > 5 );
+	assert(getenv("SELF_VALIDATE")==nullptr || targets > 5 );
+	assert(getenv("SELF_VALIDATE")==nullptr || exe_nonce_targets > 5 );
+
 	return true;
 }
 
@@ -1135,6 +1141,8 @@ bool SCFI_Instrument::instrument_jumps()
 	cout<<"# ATTRIBUTE Selective_Control_Flow_Integrity::cfi_ret_complete="<<std::dec<<cfi_branch_ret_complete<<endl;
 	display_histogram(cout, "cfi_ret_complete_histogram", rets);
 
+	assert(getenv("SELF_VALIDATE")==nullptr || cfi_branch_call_checks> 2);
+	assert(getenv("SELF_VALIDATE")==nullptr || cfi_branch_call_checks> 2);
 
 	// 0 or 1 checks.
 	cout<<"# ATTRIBUTE Selective_Control_Flow_Integrity::multimodule_checks="<< (unsigned int)(zestcfi_function_entry!=NULL) <<endl;
-- 
GitLab