complete the cfg and trap tree
This commit is contained in:
parent
783d03fbe6
commit
ddfd45ca8e
@ -435,14 +435,20 @@ 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);
|
||||||
@ -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 ();
|
||||||
{
|
|
||||||
basic_block bb_old;
|
|
||||||
basic_block bb_cond;
|
|
||||||
basic_block bb_catch;
|
|
||||||
basic_block bb_call;
|
|
||||||
edge edge_false;
|
|
||||||
edge edge_true;
|
|
||||||
//
|
|
||||||
|
|
||||||
/* Get the original bb, Thers is only one.
|
/* Get the original bb, Thers is only one.
|
||||||
For now the basic block is clean. */
|
For now the basic block is clean. */
|
||||||
bb_old = gimple_bb (cs);
|
old_bb = gimple_bb (cs);
|
||||||
edge_false = split_block (bb_old, cs);
|
edge_false = split_block (old_bb, cs);
|
||||||
gcc_assert (edge_false->flags == EDGE_FALLTHRU);
|
gcc_assert (edge_false->flags == EDGE_FALLTHRU);
|
||||||
edge_false->flags = EDGE_FALSE_VALUE;
|
edge_false->flags = EDGE_FALSE_VALUE;
|
||||||
|
GIMPLE_CHECK (edge_false->dest->il.gimple.seq, GIMPLE_CALL);
|
||||||
|
|
||||||
/* Create block after the block contain original call.
|
/* Create block after the block contain original call.
|
||||||
We can have a toplogical for the blocks created and old. */
|
We can have a toplogical for the blocks created and old. */
|
||||||
// EDGE_TRUE_VALUE
|
// EDGE_TRUE_VALUE
|
||||||
bb_catch = cfi_catch_and_trap_bb (gimple_location (cs), edge_false->dest);
|
catch_bb = cfi_catch_and_trap_bb (gimple_location (cs), edge_false->dest);
|
||||||
|
/* catch_bb must dominated by old the bb contains the indirect call
|
||||||
// EDGE_TRUE_VALUE
|
what we insert cfi guard. */
|
||||||
GIMPLE_CHECK (edge_false->dest->il.gimple.seq, GIMPLE_CALL);
|
if (current_loops != NULL)
|
||||||
|
{
|
||||||
|
add_bb_to_loop (catch_bb, old_bb->loop_father);
|
||||||
|
if (old_bb->loop_father->latch == old_bb)
|
||||||
|
old_bb->loop_father->latch = catch_bb;
|
||||||
}
|
}
|
||||||
|
make_single_succ_edge (old_bb, catch_bb, EDGE_TRUE_VALUE);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user