CC: [email protected] BCC: [email protected] CC: [email protected] TO: Kees Cook <[email protected]> CC: Dan Li <[email protected]>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git for-next/lkdtm head: 2e53b877dc1258d4ac3de98f496bb88ec3bf5e25 commit: 2e53b877dc1258d4ac3de98f496bb88ec3bf5e25 [6/6] lkdtm: Add CFI_BACKWARD to test ROP mitigations :::::: branch date: 7 days ago :::::: commit date: 7 days ago compiler: arc-elf-gcc (GCC) 11.2.0 reproduce (cppcheck warning): # apt-get install cppcheck git checkout 2e53b877dc1258d4ac3de98f496bb88ec3bf5e25 cppcheck --quiet --enable=style,performance,portability --template=gcc FILE If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <[email protected]> cppcheck possible warnings: (new ones prefixed by >>, may not real problems) >> drivers/misc/lkdtm/cfi.c:100:21: warning: syntax error [syntaxError] void *labels[] = {0, &&normal, &&redirected, &&check_normal, &&check_redirected}; ^ vim +100 drivers/misc/lkdtm/cfi.c 2e53b877dc1258 Kees Cook 2022-03-11 96 2e53b877dc1258 Kees Cook 2022-03-11 97 static void lkdtm_CFI_BACKWARD(void) 2e53b877dc1258 Kees Cook 2022-03-11 98 { 2e53b877dc1258 Kees Cook 2022-03-11 99 /* Use calculated gotos to keep labels addressable. */ 2e53b877dc1258 Kees Cook 2022-03-11 @100 void *labels[] = {0, &&normal, &&redirected, &&check_normal, &&check_redirected}; 2e53b877dc1258 Kees Cook 2022-03-11 101 2e53b877dc1258 Kees Cook 2022-03-11 102 pr_info("Attempting unchecked stack return address redirection ...\n"); 2e53b877dc1258 Kees Cook 2022-03-11 103 2e53b877dc1258 Kees Cook 2022-03-11 104 /* Always false */ 2e53b877dc1258 Kees Cook 2022-03-11 105 if (force_check) { 2e53b877dc1258 Kees Cook 2022-03-11 106 /* 2e53b877dc1258 Kees Cook 2022-03-11 107 * Prepare to call with NULLs to avoid parameters being treated as 2e53b877dc1258 Kees Cook 2022-03-11 108 * constants in -02. 2e53b877dc1258 Kees Cook 2022-03-11 109 */ 2e53b877dc1258 Kees Cook 2022-03-11 110 set_return_addr_unchecked(NULL, NULL); 2e53b877dc1258 Kees Cook 2022-03-11 111 set_return_addr(NULL, NULL); 2e53b877dc1258 Kees Cook 2022-03-11 112 if (force_check) 2e53b877dc1258 Kees Cook 2022-03-11 113 goto *labels[1]; 2e53b877dc1258 Kees Cook 2022-03-11 114 if (force_check) 2e53b877dc1258 Kees Cook 2022-03-11 115 goto *labels[2]; 2e53b877dc1258 Kees Cook 2022-03-11 116 if (force_check) 2e53b877dc1258 Kees Cook 2022-03-11 117 goto *labels[3]; 2e53b877dc1258 Kees Cook 2022-03-11 118 if (force_check) 2e53b877dc1258 Kees Cook 2022-03-11 119 goto *labels[4]; 2e53b877dc1258 Kees Cook 2022-03-11 120 return; 2e53b877dc1258 Kees Cook 2022-03-11 121 } 2e53b877dc1258 Kees Cook 2022-03-11 122 2e53b877dc1258 Kees Cook 2022-03-11 123 /* 2e53b877dc1258 Kees Cook 2022-03-11 124 * Use fallthrough switch case to keep basic block ordering between 2e53b877dc1258 Kees Cook 2022-03-11 125 * set_return_addr*() and the label after it. 2e53b877dc1258 Kees Cook 2022-03-11 126 */ 2e53b877dc1258 Kees Cook 2022-03-11 127 switch (force_check) { 2e53b877dc1258 Kees Cook 2022-03-11 128 case 0: 2e53b877dc1258 Kees Cook 2022-03-11 129 set_return_addr_unchecked(&&normal, &&redirected); 2e53b877dc1258 Kees Cook 2022-03-11 130 fallthrough; 2e53b877dc1258 Kees Cook 2022-03-11 131 case 1: 2e53b877dc1258 Kees Cook 2022-03-11 132 normal: 2e53b877dc1258 Kees Cook 2022-03-11 133 /* Always true */ 2e53b877dc1258 Kees Cook 2022-03-11 134 if (!force_check) { 2e53b877dc1258 Kees Cook 2022-03-11 135 pr_err("FAIL: stack return address manipulation failed!\n"); 2e53b877dc1258 Kees Cook 2022-03-11 136 /* If we can't redirect "normally", we can't test mitigations. */ 2e53b877dc1258 Kees Cook 2022-03-11 137 return; 2e53b877dc1258 Kees Cook 2022-03-11 138 } 2e53b877dc1258 Kees Cook 2022-03-11 139 break; 2e53b877dc1258 Kees Cook 2022-03-11 140 default: 2e53b877dc1258 Kees Cook 2022-03-11 141 redirected: 2e53b877dc1258 Kees Cook 2022-03-11 142 pr_info("ok: redirected stack return address.\n"); 2e53b877dc1258 Kees Cook 2022-03-11 143 break; 2e53b877dc1258 Kees Cook 2022-03-11 144 } 2e53b877dc1258 Kees Cook 2022-03-11 145 2e53b877dc1258 Kees Cook 2022-03-11 146 pr_info("Attempting checked stack return address redirection ...\n"); 2e53b877dc1258 Kees Cook 2022-03-11 147 2e53b877dc1258 Kees Cook 2022-03-11 148 switch (force_check) { 2e53b877dc1258 Kees Cook 2022-03-11 149 case 0: 2e53b877dc1258 Kees Cook 2022-03-11 150 set_return_addr(&&check_normal, &&check_redirected); 2e53b877dc1258 Kees Cook 2022-03-11 151 fallthrough; 2e53b877dc1258 Kees Cook 2022-03-11 152 case 1: 2e53b877dc1258 Kees Cook 2022-03-11 153 check_normal: 2e53b877dc1258 Kees Cook 2022-03-11 154 /* Always true */ 2e53b877dc1258 Kees Cook 2022-03-11 155 if (!force_check) { 2e53b877dc1258 Kees Cook 2022-03-11 156 pr_info("ok: control flow unchanged.\n"); 2e53b877dc1258 Kees Cook 2022-03-11 157 return; 2e53b877dc1258 Kees Cook 2022-03-11 158 } 2e53b877dc1258 Kees Cook 2022-03-11 159 2e53b877dc1258 Kees Cook 2022-03-11 160 check_redirected: 2e53b877dc1258 Kees Cook 2022-03-11 161 pr_err("FAIL: stack return address was redirected!\n"); 2e53b877dc1258 Kees Cook 2022-03-11 162 break; 2e53b877dc1258 Kees Cook 2022-03-11 163 } 2e53b877dc1258 Kees Cook 2022-03-11 164 2e53b877dc1258 Kees Cook 2022-03-11 165 if (IS_ENABLED(CONFIG_ARM64_PTR_AUTH_KERNEL)) { 2e53b877dc1258 Kees Cook 2022-03-11 166 pr_expected_config(CONFIG_ARM64_PTR_AUTH_KERNEL); 2e53b877dc1258 Kees Cook 2022-03-11 167 return; 2e53b877dc1258 Kees Cook 2022-03-11 168 } 2e53b877dc1258 Kees Cook 2022-03-11 169 if (IS_ENABLED(CONFIG_SHADOW_CALL_STACK)) { 2e53b877dc1258 Kees Cook 2022-03-11 170 pr_expected_config(CONFIG_SHADOW_CALL_STACK); 2e53b877dc1258 Kees Cook 2022-03-11 171 return; 2e53b877dc1258 Kees Cook 2022-03-11 172 } 2e53b877dc1258 Kees Cook 2022-03-11 173 pr_warn("This is probably expected, since this %s was built *without* %s=y nor %s=y\n", 2e53b877dc1258 Kees Cook 2022-03-11 174 lkdtm_kernel_info, 2e53b877dc1258 Kees Cook 2022-03-11 175 "CONFIG_ARM64_PTR_AUTH_KERNEL", "CONFIG_SHADOW_CALL_STACK"); 2e53b877dc1258 Kees Cook 2022-03-11 176 } 2e53b877dc1258 Kees Cook 2022-03-11 177 -- 0-DAY CI Kernel Test Service https://01.org/lkp _______________________________________________ kbuild mailing list -- [email protected] To unsubscribe send an email to [email protected]
