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

objtool: Improve UACCESS coverage

A clang build reported an (obvious) double CLAC while a GCC build did not;
it turns out that objtool only re-visits instructions if the first visit
was with AC=0. If OTOH the first visit was with AC=1, it completely ignores
any subsequent visit, even when it has AC=0.

Fix this by using a visited mask instead of a boolean, and (explicitly)
mark the AC state.

$ ./objtool check -b --no-fp --retpoline --uaccess drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: .altinstr_replacement+0x22: redundant UACCESS disable
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_copy_relocations.isra.34()+0xea: (alt)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: .altinstr_replacement+0xffffffffffffffff: (branch)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_copy_relocations.isra.34()+0xd9: (alt)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_copy_relocations.isra.34()+0xb2: (branch)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_copy_relocations.isra.34()+0x39: (branch)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.o: warning: objtool: eb_copy_relocations.isra.34()+0x0: <=== (func)

Reported-by: Josh Poimboeuf <jpoimboe@redhat.com>
Reported-by: Thomas Gleixner <tglx@linutronix.de>
Reported-by: Sedat Dilek <sedat.dilek@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Nathan Chancellor <natechancellor@gmail.com>
Tested-by: Nick Desaulniers <ndesaulniers@google.com>
Tested-by: Sedat Dilek <sedat.dilek@gmail.com>
Link: https://github.com/ClangBuiltLinux/linux/issues/617
Link: https://lkml.kernel.org/r/5359166aad2d53f3145cd442d83d0e5115e0cd17.1564007838.git.jpoimboe@redhat.com

authored by

Peter Zijlstra and committed by
Thomas Gleixner
882a0db9 b68b9907

+6 -4
+4 -3
tools/objtool/check.c
··· 1946 1946 struct alternative *alt; 1947 1947 struct instruction *insn, *next_insn; 1948 1948 struct section *sec; 1949 + u8 visited; 1949 1950 int ret; 1950 1951 1951 1952 insn = first; ··· 1973 1972 return 1; 1974 1973 } 1975 1974 1975 + visited = 1 << state.uaccess; 1976 1976 if (insn->visited) { 1977 1977 if (!insn->hint && !insn_state_match(insn, &state)) 1978 1978 return 1; 1979 1979 1980 - /* If we were here with AC=0, but now have AC=1, go again */ 1981 - if (insn->state.uaccess || !state.uaccess) 1980 + if (insn->visited & visited) 1982 1981 return 0; 1983 1982 } 1984 1983 ··· 2025 2024 } else 2026 2025 insn->state = state; 2027 2026 2028 - insn->visited = true; 2027 + insn->visited |= visited; 2029 2028 2030 2029 if (!insn->ignore_alts) { 2031 2030 bool skip_orig = false;
+2 -1
tools/objtool/check.h
··· 33 33 unsigned int len; 34 34 enum insn_type type; 35 35 unsigned long immediate; 36 - bool alt_group, visited, dead_end, ignore, hint, save, restore, ignore_alts; 36 + bool alt_group, dead_end, ignore, hint, save, restore, ignore_alts; 37 37 bool retpoline_safe; 38 + u8 visited; 38 39 struct symbol *call_dest; 39 40 struct instruction *jump_dest; 40 41 struct instruction *first_jump_src;