mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 18:09:56 +00:00
randstruct: gcc-plugin: Fix attribute addition
[ Upstream commitf39f18f3c3] Based on changes in the 2021 public version of the randstruct out-of-tree GCC plugin[1], more carefully update the attributes on resulting decls, to avoid tripping checks in GCC 15's comptypes_check_enum_int() when it has been configured with "--enable-checking=misc": arch/arm64/kernel/kexec_image.c:132:14: internal compiler error: in comptypes_check_enum_int, at c/c-typeck.cc:1519 132 | const struct kexec_file_ops kexec_image_ops = { | ^~~~~~~~~~~~~~ internal_error(char const*, ...), at gcc/gcc/diagnostic-global-context.cc:517 fancy_abort(char const*, int, char const*), at gcc/gcc/diagnostic.cc:1803 comptypes_check_enum_int(tree_node*, tree_node*, bool*), at gcc/gcc/c/c-typeck.cc:1519 ... Link: https://archive.org/download/grsecurity/grsecurity-3.1-5.10.41-202105280954.patch.gz [1] Reported-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org> Closes: https://github.com/KSPP/linux/issues/367 Closes: https://lore.kernel.org/lkml/20250530000646.104457-1-thiago.bauermann@linaro.org/ Reported-by: Ingo Saitz <ingo@hannover.ccc.de> Closes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1104745 Fixes:313dd1b629("gcc-plugins: Add the randstruct plugin") Tested-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org> Link: https://lore.kernel.org/r/20250530221824.work.623-kees@kernel.org Signed-off-by: Kees Cook <kees@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
4fb27da8a1
commit
a255510f00
@@ -73,6 +73,9 @@ static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int f
|
||||
|
||||
if (TYPE_P(*node)) {
|
||||
type = *node;
|
||||
} else if (TREE_CODE(*node) == FIELD_DECL) {
|
||||
*no_add_attrs = false;
|
||||
return NULL_TREE;
|
||||
} else {
|
||||
gcc_assert(TREE_CODE(*node) == TYPE_DECL);
|
||||
type = TREE_TYPE(*node);
|
||||
@@ -348,15 +351,14 @@ static int relayout_struct(tree type)
|
||||
TREE_CHAIN(newtree[i]) = newtree[i+1];
|
||||
TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
|
||||
|
||||
add_type_attr(type, "randomize_performed", NULL_TREE);
|
||||
add_type_attr(type, "designated_init", NULL_TREE);
|
||||
if (has_flexarray)
|
||||
add_type_attr(type, "has_flexarray", NULL_TREE);
|
||||
|
||||
main_variant = TYPE_MAIN_VARIANT(type);
|
||||
for (variant = main_variant; variant; variant = TYPE_NEXT_VARIANT(variant)) {
|
||||
for (variant = main_variant; variant; variant = TYPE_NEXT_VARIANT(variant))
|
||||
TYPE_FIELDS(variant) = newtree[0];
|
||||
TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
|
||||
TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
|
||||
TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("designated_init"), NULL_TREE, TYPE_ATTRIBUTES(variant));
|
||||
if (has_flexarray)
|
||||
TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("has_flexarray"), NULL_TREE, TYPE_ATTRIBUTES(type));
|
||||
}
|
||||
|
||||
/*
|
||||
* force a re-layout of the main variant
|
||||
@@ -424,10 +426,8 @@ static void randomize_type(tree type)
|
||||
if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
|
||||
relayout_struct(type);
|
||||
|
||||
for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
|
||||
TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
|
||||
TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
|
||||
}
|
||||
add_type_attr(type, "randomize_considered", NULL_TREE);
|
||||
|
||||
#ifdef __DEBUG_PLUGIN
|
||||
fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
|
||||
#ifdef __DEBUG_VERBOSE
|
||||
|
||||
Reference in New Issue
Block a user