new check code fragment
This commit is contained in:
parent
4eefb82dd0
commit
f2db0474c9
@ -1,7 +1,9 @@
|
|||||||
/* Write by David fuqiang Fan <feqin1023@gmail.com>, member of HardenedLinux.
|
/* Write by David fuqiang Fan <feqin1023@gmail.com>, member of HardenedLinux.
|
||||||
The impelmentation code of optimization pass for PaX RAP.
|
The code of this file try to make some optimizationsfor PaX RAP.
|
||||||
Supply the API for RAP.
|
Supply the API for RAP.
|
||||||
|
|
||||||
And we also call function wich compute function type hash from PaX RAP.
|
And we also call function wich compute function type hash from PaX RAP.
|
||||||
|
Code architecture inspired by RAP of PaX Team <pageexec@freemail.hu>.
|
||||||
|
|
||||||
Licensed under the GPL v2. */
|
Licensed under the GPL v2. */
|
||||||
|
|
||||||
@ -268,18 +270,41 @@ rap_optimization_clean ()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MAKE_TARGET_HASH_TREE 1
|
||||||
|
|
||||||
|
/* */
|
||||||
|
static inline tree
|
||||||
|
make_cfi_check_tree ()
|
||||||
|
{
|
||||||
|
tree target_hash; // hash get behind the function definitions.
|
||||||
|
tree source_hash; // hash get before indirect calls.
|
||||||
|
tree var;
|
||||||
|
var = create_tmp_var (integer_type_node, "hl");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Build the check statement:
|
/* Build the check statement:
|
||||||
if ((int *)(cs->target_function - sizeof(rap_hash_value_type)) != hash)
|
if ((int *)(cs->target_function - sizeof(rap_hash_value_type)) != hash)
|
||||||
error () */
|
error () */
|
||||||
static void
|
static inline void
|
||||||
build_cfi_check (gimple cs, rap_hash_value_type hash)
|
build_cfi_check (gimple_stmt_iterator *gp, rap_hash_value_type hash)
|
||||||
{
|
{
|
||||||
|
gimple cs;
|
||||||
|
//gimple_stmt_iterator gsi;
|
||||||
tree decl; type;
|
tree decl; type;
|
||||||
|
|
||||||
gcc_assert (is_gimple_call (cs));
|
gcc_assert (is_gimple_call (cs));
|
||||||
|
cs = gsi_stmt (*gp);
|
||||||
decl = gimple_call_fn (cs);
|
decl = gimple_call_fn (cs);
|
||||||
/* We must be indirect call */
|
/* We must be indirect call */
|
||||||
gcc_assert (DECL_CODE (decl) == SSA_NAME);
|
gcc_assert (TREE_CODE (decl) == SSA_NAME);
|
||||||
|
gcc_assert (! SSA_NAME_IS_DEFAULT_DEF (decl));
|
||||||
type = cs->gimple_call.u.fntype;
|
type = cs->gimple_call.u.fntype;
|
||||||
|
gcc_assert (TREE_TYPE (TREE_TYPE (decl)) == type);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,9 +325,9 @@ static unsigned int
|
|||||||
rap_fe_cfi_execute ()
|
rap_fe_cfi_execute ()
|
||||||
{
|
{
|
||||||
struct cgraph_node *node;
|
struct cgraph_node *node;
|
||||||
if (! flag_ltrans)
|
//if (! flag_ltrans)
|
||||||
gcc_assert(0);
|
//gcc_assert(0);
|
||||||
struct pointer_map_t *indirect_function_maps;
|
//struct pointer_map_t *indirect_function_maps;
|
||||||
|
|
||||||
FOR_EACH_DEFINED_FUNCTION (node)
|
FOR_EACH_DEFINED_FUNCTION (node)
|
||||||
{
|
{
|
||||||
@ -322,20 +347,17 @@ rap_fe_cfi_execute ()
|
|||||||
|
|
||||||
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
|
for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
|
||||||
{
|
{
|
||||||
tree decl;
|
//tree decl;
|
||||||
gimple cs;
|
gimple cs;
|
||||||
rap_hash_value_type hash;
|
rap_hash_value_type hash;
|
||||||
cs = gsi_stmt (gsi);
|
cs = gsi_stmt (gsi);
|
||||||
/* We are in forward cfi only cares about function call */
|
/* We are in forward cfi only cares about function call */
|
||||||
if (! is_gimple_call (cs))
|
if (! is_gimple_call (cs))
|
||||||
continue;
|
continue;
|
||||||
/* direct call, nothing todo */
|
/* Indirect calls */
|
||||||
if (gimple_call_fndecl (cs))
|
if (NULL == gimple_call_fndecl (cs))
|
||||||
;
|
|
||||||
/* indirect call */
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
decl = gimple_call_fn (cs);
|
//decl = gimple_call_fn (cs);
|
||||||
hash = find_cfi_hash (decl);
|
hash = find_cfi_hash (decl);
|
||||||
gcc_assert (hash);
|
gcc_assert (hash);
|
||||||
build_cfi_check (cs, hash);
|
build_cfi_check (cs, hash);
|
||||||
@ -345,11 +367,13 @@ rap_fe_cfi_execute ()
|
|||||||
|
|
||||||
pop_cfun ();
|
pop_cfun ();
|
||||||
}
|
}
|
||||||
|
//indirect_function_maps = pointer_map_create ();
|
||||||
|
//gimple_call_fndecl (const_gimple gs)
|
||||||
|
|
||||||
indirect_function_maps = pointer_map_create ();
|
return 0;
|
||||||
gimple_call_fndecl (const_gimple gs)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Genetate the pass structure */
|
||||||
#define PASS_NAME rap_fe_cfi
|
#define PASS_NAME rap_fe_cfi
|
||||||
//#define PROPERTIES_REQUIRED PROP_gimple_any
|
//#define PROPERTIES_REQUIRED PROP_gimple_any
|
||||||
//#define PROPERTIES_PROVIDED PROP_gimple_lcf
|
//#define PROPERTIES_PROVIDED PROP_gimple_lcf
|
||||||
|
Loading…
Reference in New Issue
Block a user