Skip to content

Commit 58bea41

Browse files
committed
latent_entropy: Fix wrong gcc code generation with 64 bit variables
The stack frame size could grow too large when the plugin used long long on 32-bit architectures when the given function had too many basic blocks. The gcc warning was: drivers/pci/hotplug/ibmphp_ebda.c: In function 'ibmphp_access_ebda': drivers/pci/hotplug/ibmphp_ebda.c:409:1: warning: the frame size of 1108 bytes is larger than 1024 bytes [-Wframe-larger-than=] This switches latent_entropy from u64 to unsigned long. Thanks to PaX Team and Emese Revfy for the patch. Signed-off-by: Kees Cook <keescook@chromium.org>
1 parent da7389a commit 58bea41

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

‎mm/page_alloc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ int _node_numa_mem_[MAX_NUMNODES];
9292
#endif
9393

9494
#ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY
95-
volatile u64 latent_entropy __latent_entropy;
95+
volatile unsigned long latent_entropy __latent_entropy;
9696
EXPORT_SYMBOL(latent_entropy);
9797
#endif
9898

‎scripts/gcc-plugins/latent_entropy_plugin.c‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static enum tree_code get_op(tree *rhs)
340340
break;
341341
}
342342
if (rhs)
343-
*rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
343+
*rhs = build_int_cstu(long_unsigned_type_node, random_const);
344344
return op;
345345
}
346346

@@ -372,7 +372,7 @@ static void __perturb_latent_entropy(gimple_stmt_iterator *gsi,
372372
enum tree_code op;
373373

374374
/* 1. create temporary copy of latent_entropy */
375-
temp = create_var(unsigned_intDI_type_node, "tmp_latent_entropy");
375+
temp = create_var(long_unsigned_type_node, "temp_latent_entropy");
376376

377377
/* 2. read... */
378378
add_referenced_var(latent_entropy_decl);
@@ -459,13 +459,13 @@ static void init_local_entropy(basic_block bb, tree local_entropy)
459459
gsi_insert_before(&gsi, call, GSI_NEW_STMT);
460460
update_stmt(call);
461461

462-
udi_frame_addr = fold_convert(unsigned_intDI_type_node, frame_addr);
462+
udi_frame_addr = fold_convert(long_unsigned_type_node, frame_addr);
463463
assign = gimple_build_assign(local_entropy, udi_frame_addr);
464464
gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
465465
update_stmt(assign);
466466

467467
/* 3. create temporary copy of latent_entropy */
468-
tmp = create_var(unsigned_intDI_type_node, "tmp_latent_entropy");
468+
tmp = create_var(long_unsigned_type_node, "temp_latent_entropy");
469469

470470
/* 4. read the global entropy variable into local entropy */
471471
add_referenced_var(latent_entropy_decl);
@@ -480,7 +480,7 @@ static void init_local_entropy(basic_block bb, tree local_entropy)
480480
update_stmt(assign);
481481

482482
rand_cst = get_random_const();
483-
rand_const = build_int_cstu(unsigned_intDI_type_node, rand_cst);
483+
rand_const = build_int_cstu(long_unsigned_type_node, rand_cst);
484484
op = get_op(NULL);
485485
assign = create_assign(op, local_entropy, local_entropy, rand_const);
486486
gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
@@ -529,7 +529,7 @@ static unsigned int latent_entropy_execute(void)
529529
}
530530

531531
/* 1. create the local entropy variable */
532-
local_entropy = create_var(unsigned_intDI_type_node, "local_entropy");
532+
local_entropy = create_var(long_unsigned_type_node, "local_entropy");
533533

534534
/* 2. initialize the local entropy variable */
535535
init_local_entropy(bb, local_entropy);
@@ -561,10 +561,9 @@ static void latent_entropy_start_unit(void *gcc_data __unused,
561561
if (in_lto_p)
562562
return;
563563

564-
/* extern volatile u64 latent_entropy */
565-
gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
566-
quals = TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE;
567-
type = build_qualified_type(long_long_unsigned_type_node, quals);
564+
/* extern volatile unsigned long latent_entropy */
565+
quals = TYPE_QUALS(long_unsigned_type_node) | TYPE_QUAL_VOLATILE;
566+
type = build_qualified_type(long_unsigned_type_node, quals);
568567
id = get_identifier("latent_entropy");
569568
latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, id, type);
570569

0 commit comments

Comments
 (0)