complete the cfg and trap tree

This commit is contained in:
fanfuqiang 2018-10-19 19:17:36 +08:00
parent 783d03fbe6
commit ddfd45ca8e

View File

@ -435,15 +435,21 @@ build_cfi_hash_tree (gimple cs, int direct, tree *target_off_type_p)
static basic_block static basic_block
cfi_catch_and_trap_bb (location_t loc, basic_block *after) cfi_catch_and_trap_bb (location_t loc, basic_block *after)
{ {
tree report;
tree trap; tree trap;
gimple_seq seq;
gimple g; gimple g;
gimple_seq seq;
#if 0
tree report;
tree param;
gimple_seq seq;
basic_block bb; basic_block bb;
gimple_stmt_iterator gsi; gimple_stmt_iterator gsi;
/* Build the report & trap tree. */ /* Build the report & trap tree. */
const char *str = "[!] HardenedLinux cfi violate catched.";
int len = strlen (str);
param = build_string_literal (len, str);
/* gimple sequence for bb. */ /* gimple sequence for bb. */
seq = g = gimple_build_call (report, loc); seq = g = gimple_build_call (report, loc);
/* ssa concerns. */ /* ssa concerns. */
@ -452,12 +458,15 @@ cfi_catch_and_trap_bb (location_t loc, basic_block *after)
gimple_set_block (g, bb); gimple_set_block (g, bb);
/* Initialize iterator. */ /* Initialize iterator. */
gsi = gsi_start (seq); //gsi = gsi_start (seq);
g = gimple_build_call (trap, loc); #endif
gsi_insert_after (&gsi, g, GSI_SAME_STMT); trap = builtin_decl_explicit (BUILT_IN_TRAP);
seq = g = gimple_build_call (trap, loc);
bb = create_basic_block (seq, NULL, after);
update_modified_stmt (g);
//gsi_insert_after (&gsi, g, GSI_SAME_STMT);
gimple_set_block (g, bb); gimple_set_block (g, bb);
//panic ("[!] HardenedLinux fe-cfi violate catched.");
return bb; return bb;
} }
@ -488,9 +497,12 @@ insert_cond_and_build_ssa_cfg (gimple_stmt_iterator *gp,
tree t_t) tree t_t)
{ {
gimple cs, g; gimple cs, g;
gimple_stmt_iterator first, gsi; gimple_stmt_iterator gsi;
gimple cond; // test gimple we insert. gimple cond; // test gimple we insert.
gimple call; // call label gimple we insert. gimple call; // call label gimple we insert.
basic_block old_bb;
basic_block catch_bb;
edge edge_false;
tree lhs; tree lhs;
gsi = *gp; gsi = *gp;
@ -536,32 +548,29 @@ insert_cond_and_build_ssa_cfg (gimple_stmt_iterator *gp,
call call
# old code */ # old code */
/* Make the blocks & edges. */ /* Make the blocks & edges. */
stmt_starts_bb_p (); //stmt_starts_bb_p ();
stmt_ends_bb_p (); //stmt_ends_bb_p ();
{ /* Get the original bb, Thers is only one.
basic_block bb_old; For now the basic block is clean. */
basic_block bb_cond; old_bb = gimple_bb (cs);
basic_block bb_catch; edge_false = split_block (old_bb, cs);
basic_block bb_call; gcc_assert (edge_false->flags == EDGE_FALLTHRU);
edge edge_false; edge_false->flags = EDGE_FALSE_VALUE;
edge edge_true; GIMPLE_CHECK (edge_false->dest->il.gimple.seq, GIMPLE_CALL);
//
/* Get the original bb, Thers is only one. /* Create block after the block contain original call.
For now the basic block is clean. */ We can have a toplogical for the blocks created and old. */
bb_old = gimple_bb (cs); // EDGE_TRUE_VALUE
edge_false = split_block (bb_old, cs); catch_bb = cfi_catch_and_trap_bb (gimple_location (cs), edge_false->dest);
gcc_assert (edge_false->flags == EDGE_FALLTHRU); /* catch_bb must dominated by old the bb contains the indirect call
edge_false->flags = EDGE_FALSE_VALUE; what we insert cfi guard. */
if (current_loops != NULL)
/* Create block after the block contain original call. {
We can have a toplogical for the blocks created and old. */ add_bb_to_loop (catch_bb, old_bb->loop_father);
// EDGE_TRUE_VALUE if (old_bb->loop_father->latch == old_bb)
bb_catch = cfi_catch_and_trap_bb (gimple_location (cs), edge_false->dest); old_bb->loop_father->latch = catch_bb;
}
// EDGE_TRUE_VALUE make_single_succ_edge (old_bb, catch_bb, EDGE_TRUE_VALUE);
GIMPLE_CHECK (edge_false->dest->il.gimple.seq, GIMPLE_CALL);
}
return; return;
} }