Skip to content

Commit

Permalink
Add a prohibitedFunctions list to CFIChecks to filter the SAFECode ru…
Browse files Browse the repository at this point in the history
…ntime functions from TargetLists
  • Loading branch information
zhengyang92 committed Jun 14, 2016
1 parent e1986b9 commit b324534
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
1 change: 1 addition & 0 deletions projects/safecode/include/safecode/CFIChecks.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct CFIChecks : public ModulePass, InstVisitor<CFIChecks> {
protected:
// Pointer to load/store run-time check function
Function * FunctionCheckUI;
static const char * const prohibitedFunctions[];

// Create a global variable table for the targets of the call instruction
GlobalVariable * createTargetTable (CallInst & CI, bool & isComplete);
Expand Down
12 changes: 2 additions & 10 deletions projects/safecode/lib/CommonMemorySafety/SpecializeCMSCalls.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,8 @@ void SpecializeCMSCalls::specialize(Module &M, StringRef Before,
for (Value::user_iterator UI = From->user_begin(), E = From->user_end();
UI != E;
++UI) {
//
// CFIchecks pass generates a TargetList global variable which produces
// irrelevent users of __loadcheck and __storecheck.
//
// i8* bitcast (void (i8*, i64)* @__loadcheck to i8*)
// i8* bitcast (void (i8*, i64)* @__storecheck to i8*)
//
// Only call instructions are supposed to transform.
CallInst *CI;
if(!(CI = dyn_cast<CallInst>(*UI))) return;
// Only call instructions are supposed to exist.
CallInst *CI = cast<CallInst>(*UI);

IRBuilder<> Builder(CI);
SmallVector <Value*, 4> Args(To->arg_size());
Expand Down
41 changes: 41 additions & 0 deletions projects/safecode/lib/InsertPoolChecks/CFIChecks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ namespace {
STATISTIC (Checks, "CFI Checks Added");
}

// All runtime checks functions should not appear in TargetList.
const char* const CFIChecks::prohibitedFunctions[] = {
"__loadcheck", "__storecheck",
"pool_init_runtime", "pool_init_logfile"
"poolargvregister",
"pool_register", "pool_register_debug",
"pool_register_stack", "pool_register_stack_debug",
"pool_register_global", "pool_register_global_debug",
"pool_reregister", "pool_reregister_debug",
"pool_unregister", "pool_unregister_debug",
"poolrealloc", "poolcheck", "poolcheckui", "poolcheck_debug", "poolcheckui_debug",
"poolcheckalign", "poolcheckalign_debug",
"boundscheck", "boundscheckui", "boundscheckui_debug", "boundscheck_debug",
"exactcheck2", "exactcheck2_debug", "fastlscheck", "fastlscheck_debug",
"pchk_getActualValue",
"funccheck", "funccheckui", "funccheck_debug", "funccheckui_debug",
"pool_shadow", "pool_unshadow",
"poolcheck_free", "poolcheck_freeui", "poolcheck_free_debug", "poolcheck_freeui_debug",
};

//
// Method: createTargetTable()
//
Expand Down Expand Up @@ -112,6 +132,27 @@ CFIChecks::createTargetTable (CallInst & CI, bool & isComplete) {
continue;
}

//
// Do not include functions in the prohibitedFunctions array, or functions
// with __sc_bb_ or __sc_dbg_ prefix.
//
if (Target->hasName()) {
StringRef Name = Target->getName();

This comment has been minimized.

Copy link
@zhengyang92

zhengyang92 Jun 16, 2016

Author Owner

comments

if(Name.find("__sc_bb_") || Name.find("__sc_dbg_")) continue;

bool isMatched = false;
for (size_t i = 0; i < sizeof(prohibitedFunctions)/sizeof(prohibitedFunctions[0]); i++)
{
if (Name == prohibitedFunctions[i])
{
isMatched = true;
break;
}
}
if(isMatched) continue;
}


//
// Do not include functions with available externally linkage. These
// functions are never emitted into the final executable.
Expand Down

2 comments on commit b324534

@jtcriswell
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the initializer for the prohibitedFunctions array, put each function name on a single line. That will make the code easier to read.

@jtcriswell
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please be sure to use the LLVM coding style for your code. Curly braces should appear at the end of the line instead of on the next line.

Please sign in to comment.