Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lkdtm: Avoid objtool/ibt warning

For certain configs objtool will complain like:

vmlinux.o: warning: objtool: lkdtm_UNSET_SMEP+0x1c3: relocation to !ENDBR: native_write_cr4+0x41

What happens is that GCC optimizes the loop:

insn = (unsigned char *)native_write_cr4;
for (i = 0; i < MOV_CR4_DEPTH; i++)

to read something like:

for (insn = (unsigned char *)native_write_cr4;
insn < (unsigned char *)native_write_cr4 + MOV_CR4_DEPTH;
insn++)

Which then obviously generates the text reference
native_write_cr4+041. Since none of this is a fast path, simply
confuse GCC enough to inhibit this optimization.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/Y3JdgbXRV0MNZ+9h@hirez.programming.kicks-ass.net
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>

authored by

Peter Zijlstra and committed by
Josh Poimboeuf
4a03aa34 d49d1666

+1
+1
drivers/misc/lkdtm/bugs.c
··· 487 487 * the cr4 writing instruction. 488 488 */ 489 489 insn = (unsigned char *)native_write_cr4; 490 + OPTIMIZER_HIDE_VAR(insn); 490 491 for (i = 0; i < MOV_CR4_DEPTH; i++) { 491 492 /* mov %rdi, %cr4 */ 492 493 if (insn[i] == 0x0f && insn[i+1] == 0x22 && insn[i+2] == 0xe7)