Skip to content

Commit 710e4eb

Browse files
committed
gcc-plugins: randstruct: Remove cast exception handling
With all randstruct exceptions removed, remove all the exception handling code. Any future warnings are likely to be shared between this plugin and Clang randstruct, and will need to be addressed in a more wholistic fashion. Cc: Christoph Hellwig <[email protected]> Cc: [email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent b146cbf commit 710e4eb

File tree

1 file changed

+3
-76
lines changed

1 file changed

+3
-76
lines changed

scripts/gcc-plugins/randomize_layout_plugin.c

Lines changed: 3 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,6 @@ static struct plugin_info randomize_layout_plugin_info = {
3939
"performance-mode\tenable cacheline-aware layout randomization\n"
4040
};
4141

42-
struct whitelist_entry {
43-
const char *pathname;
44-
const char *lhs;
45-
const char *rhs;
46-
};
47-
48-
static const struct whitelist_entry whitelist[] = {
49-
{ }
50-
};
51-
5242
/* from old Linux dcache.h */
5343
static inline unsigned long
5444
partial_name_hash(unsigned long c, unsigned long prevhash)
@@ -734,60 +724,6 @@ static void handle_local_var_initializers(void)
734724
}
735725
}
736726

737-
static bool type_name_eq(gimple stmt, const_tree type_tree, const char *wanted_name)
738-
{
739-
const char *type_name;
740-
741-
if (type_tree == NULL_TREE)
742-
return false;
743-
744-
switch (TREE_CODE(type_tree)) {
745-
case RECORD_TYPE:
746-
type_name = TYPE_NAME_POINTER(type_tree);
747-
break;
748-
case INTEGER_TYPE:
749-
if (TYPE_PRECISION(type_tree) == CHAR_TYPE_SIZE)
750-
type_name = "char";
751-
else {
752-
INFORM(gimple_location(stmt), "found non-char INTEGER_TYPE cast comparison: %qT\n", type_tree);
753-
debug_tree(type_tree);
754-
return false;
755-
}
756-
break;
757-
case POINTER_TYPE:
758-
if (TREE_CODE(TREE_TYPE(type_tree)) == VOID_TYPE) {
759-
type_name = "void *";
760-
break;
761-
} else {
762-
INFORM(gimple_location(stmt), "found non-void POINTER_TYPE cast comparison %qT\n", type_tree);
763-
debug_tree(type_tree);
764-
return false;
765-
}
766-
default:
767-
INFORM(gimple_location(stmt), "unhandled cast comparison: %qT\n", type_tree);
768-
debug_tree(type_tree);
769-
return false;
770-
}
771-
772-
return strcmp(type_name, wanted_name) == 0;
773-
}
774-
775-
static bool whitelisted_cast(gimple stmt, const_tree lhs_tree, const_tree rhs_tree)
776-
{
777-
const struct whitelist_entry *entry;
778-
expanded_location xloc = expand_location(gimple_location(stmt));
779-
780-
for (entry = whitelist; entry->pathname; entry++) {
781-
if (!strstr(xloc.file, entry->pathname))
782-
continue;
783-
784-
if (type_name_eq(stmt, lhs_tree, entry->lhs) && type_name_eq(stmt, rhs_tree, entry->rhs))
785-
return true;
786-
}
787-
788-
return false;
789-
}
790-
791727
/*
792728
* iterate over all statements to find "bad" casts:
793729
* those where the address of the start of a structure is cast
@@ -864,10 +800,7 @@ static unsigned int find_bad_casts_execute(void)
864800
#ifndef __DEBUG_PLUGIN
865801
if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
866802
#endif
867-
{
868-
if (!whitelisted_cast(stmt, ptr_lhs_type, ptr_rhs_type))
869-
MISMATCH(gimple_location(stmt), "rhs", ptr_lhs_type, ptr_rhs_type);
870-
}
803+
MISMATCH(gimple_location(stmt), "rhs", ptr_lhs_type, ptr_rhs_type);
871804
continue;
872805
}
873806

@@ -890,10 +823,7 @@ static unsigned int find_bad_casts_execute(void)
890823
#ifndef __DEBUG_PLUGIN
891824
if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
892825
#endif
893-
{
894-
if (!whitelisted_cast(stmt, ptr_lhs_type, op0_type))
895-
MISMATCH(gimple_location(stmt), "op0", ptr_lhs_type, op0_type);
896-
}
826+
MISMATCH(gimple_location(stmt), "op0", ptr_lhs_type, op0_type);
897827
} else {
898828
const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
899829
/* skip bogus type casts introduced by container_of */
@@ -903,10 +833,7 @@ static unsigned int find_bad_casts_execute(void)
903833
#ifndef __DEBUG_PLUGIN
904834
if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
905835
#endif
906-
{
907-
if (!whitelisted_cast(stmt, ptr_lhs_type, ptr_rhs_type))
908-
MISMATCH(gimple_location(stmt), "ssa", ptr_lhs_type, ptr_rhs_type);
909-
}
836+
MISMATCH(gimple_location(stmt), "ssa", ptr_lhs_type, ptr_rhs_type);
910837
}
911838

912839
}

0 commit comments

Comments
 (0)