@@ -1177,6 +1177,7 @@ void __init_or_module apply_seal_endbr(s32 *start, s32 *end) { }
11771177#endif
11781178
11791179enum cfi_mode cfi_mode __ro_after_init = __CFI_DEFAULT ;
1180+ static bool cfi_debug __ro_after_init ;
11801181
11811182#ifdef CONFIG_FINEIBT_BHI
11821183bool cfi_bhi __ro_after_init = false;
@@ -1259,6 +1260,8 @@ static __init int cfi_parse_cmdline(char *str)
12591260 } else if (!strcmp (str , "off" )) {
12601261 cfi_mode = CFI_OFF ;
12611262 cfi_rand = false;
1263+ } else if (!strcmp (str , "debug" )) {
1264+ cfi_debug = true;
12621265 } else if (!strcmp (str , "kcfi" )) {
12631266 cfi_mode = CFI_KCFI ;
12641267 } else if (!strcmp (str , "fineibt" )) {
@@ -1707,6 +1710,8 @@ static int cfi_rewrite_callers(s32 *start, s32 *end)
17071710 return 0 ;
17081711}
17091712
1713+ #define pr_cfi_debug (X ...) if (cfi_debug) pr_info(X)
1714+
17101715static void __apply_fineibt (s32 * start_retpoline , s32 * end_retpoline ,
17111716 s32 * start_cfi , s32 * end_cfi , bool builtin )
17121717{
@@ -1734,6 +1739,7 @@ static void __apply_fineibt(s32 *start_retpoline, s32 *end_retpoline,
17341739 * rewrite them. This disables all CFI. If this succeeds but any of the
17351740 * later stages fails, we're without CFI.
17361741 */
1742+ pr_cfi_debug ("CFI: disabling all indirect call checking\n" );
17371743 ret = cfi_disable_callers (start_retpoline , end_retpoline );
17381744 if (ret )
17391745 goto err ;
@@ -1744,14 +1750,19 @@ static void __apply_fineibt(s32 *start_retpoline, s32 *end_retpoline,
17441750 cfi_bpf_hash = cfi_rehash (cfi_bpf_hash );
17451751 cfi_bpf_subprog_hash = cfi_rehash (cfi_bpf_subprog_hash );
17461752 }
1753+ pr_cfi_debug ("CFI: cfi_seed: 0x%08x\n" , cfi_seed );
17471754
1755+ pr_cfi_debug ("CFI: rehashing all preambles\n" );
17481756 ret = cfi_rand_preamble (start_cfi , end_cfi );
17491757 if (ret )
17501758 goto err ;
17511759
1760+ pr_cfi_debug ("CFI: rehashing all indirect calls\n" );
17521761 ret = cfi_rand_callers (start_retpoline , end_retpoline );
17531762 if (ret )
17541763 goto err ;
1764+ } else {
1765+ pr_cfi_debug ("CFI: rehashing disabled\n" );
17551766 }
17561767
17571768 switch (cfi_mode ) {
@@ -1761,6 +1772,7 @@ static void __apply_fineibt(s32 *start_retpoline, s32 *end_retpoline,
17611772 return ;
17621773
17631774 case CFI_KCFI :
1775+ pr_cfi_debug ("CFI: re-enabling all indirect call checking\n" );
17641776 ret = cfi_enable_callers (start_retpoline , end_retpoline );
17651777 if (ret )
17661778 goto err ;
@@ -1771,17 +1783,20 @@ static void __apply_fineibt(s32 *start_retpoline, s32 *end_retpoline,
17711783 return ;
17721784
17731785 case CFI_FINEIBT :
1786+ pr_cfi_debug ("CFI: adding FineIBT to all preambles\n" );
17741787 /* place the FineIBT preamble at func()-16 */
17751788 ret = cfi_rewrite_preamble (start_cfi , end_cfi );
17761789 if (ret )
17771790 goto err ;
17781791
17791792 /* rewrite the callers to target func()-16 */
1793+ pr_cfi_debug ("CFI: rewriting indirect call sites to use FineIBT\n" );
17801794 ret = cfi_rewrite_callers (start_retpoline , end_retpoline );
17811795 if (ret )
17821796 goto err ;
17831797
17841798 /* now that nobody targets func()+0, remove ENDBR there */
1799+ pr_cfi_debug ("CFI: removing old endbr insns\n" );
17851800 cfi_rewrite_endbr (start_cfi , end_cfi );
17861801
17871802 if (builtin ) {
@@ -2324,6 +2339,7 @@ void __init alternative_instructions(void)
23242339
23252340 __apply_fineibt (__retpoline_sites , __retpoline_sites_end ,
23262341 __cfi_sites , __cfi_sites_end , true);
2342+ cfi_debug = false;
23272343
23282344 /*
23292345 * Rewrite the retpolines, must be done before alternatives since
0 commit comments